use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas in project fmv by f-agu.
the class OutputProcessor method mapStreams.
/**
* @param predicate
* @param forInputProcessor
* @return
* @throws IOException
*/
public OutputProcessor mapStreams(Predicate<Stream> predicate, InputProcessor forInputProcessor) throws IOException {
Map myMap = map();
MovieMetadatas movieMetadatas = forInputProcessor.getMovieMetadatas();
for (Stream stream : movieMetadatas.getStreams()) {
if (predicate.test(stream)) {
myMap.streams(stream).input(forInputProcessor);
}
}
return this;
}
use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas in project fmv by f-agu.
the class AutoRotateTestCase method test.
@Test
public void test() {
MovieMetadatas movieMetadatas = mock(MovieMetadatas.class);
VideoStream videoStream = mock(VideoStream.class);
doReturn(videoStream).when(movieMetadatas).getVideoStream();
doReturn(Optional.of("90")).when(videoStream).tag("rotate");
AutoRotate.create(movieMetadatas);
}
use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas in project fmv by f-agu.
the class Reduce method doIt.
/**
* @param sourceFile
* @throws IOException
*/
private static void doIt(File sourceFile) throws IOException {
String extension = FilenameUtils.getExtension(sourceFile.getName()).toLowerCase();
if (!"mkv".equals(extension)) {
extension = "mp4";
}
File destinationFile = new File(sourceFile.getParentFile(), FilenameUtils.getBaseName(sourceFile.getName()) + "-new." + extension);
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
InputProcessor inputProcessor = builder.addMediaInputFile(sourceFile);
MovieMetadatas videoMetadatas = inputProcessor.getMovieMetadatas();
boolean doVideo = !videoMetadatas.getVideoStream().isTreatedByFMV();
boolean doAudio = doVideo;
Collection<AudioStream> audioStreams = StreamOrder.sort(videoMetadatas.getAudioStreams());
for (AudioStream audioStream : audioStreams) {
if ("vorbis".equals(audioStream.codecName().get())) {
doAudio |= true;
break;
}
if ("aac".equals(audioStream.codecName().get())) {
doAudio = false;
break;
}
}
if (!doVideo && !doAudio) {
return;
}
OutputProcessor outputProcessor = builder.addMediaOutputFile(destinationFile);
outputProcessor.qualityScale(0);
// video
for (Stream stream : videoMetadatas.getVideoStreams()) {
outputProcessor.map().streams(stream).input(inputProcessor);
}
// audio
for (Stream stream : audioStreams) {
outputProcessor.map().streams(stream).input(inputProcessor);
}
// subtitle
Collection<SubtitleStream> subtitleStreams = StreamOrder.sort(videoMetadatas.getSubtitleStreams());
for (Stream stream : subtitleStreams) {
outputProcessor.map().streams(stream).input(inputProcessor);
}
// other stream
for (Stream stream : videoMetadatas.getStreams()) {
Type type = stream.type();
if (type != Type.AUDIO && type != Type.VIDEO && type != Type.SUBTITLE) {
outputProcessor.map().streams(stream).input(inputProcessor);
}
}
// ------------------------ disposition default ------------------------
//
int count = 0;
for (Stream stream : audioStreams) {
boolean beDefault = count == 1;
if (stream.isDefaultStream() != beDefault) {
outputProcessor.metadataStream(Type.AUDIO, count, "disposition:default", beDefault ? "1" : "0");
}
++count;
}
count = 0;
for (Stream stream : subtitleStreams) {
boolean beDefault = count == 1;
if (stream.isDefaultStream() != beDefault) {
outputProcessor.metadataStream(Type.SUBTITLE, count, "disposition:default", beDefault ? "1" : "0");
}
++count;
}
// video
if (doVideo) {
outputProcessor.codec(H264.findRecommanded().strict(Strict.EXPERIMENTAL).quality(23));
} else {
outputProcessor.codecCopy(Type.VIDEO);
}
// audio
if (doAudio) {
outputProcessor.codecAutoSelectAAC();
} else {
outputProcessor.codecCopy(Type.AUDIO);
}
// subtitle
if (videoMetadatas.contains(Type.SUBTITLE)) {
outputProcessor.codecCopy(Type.SUBTITLE);
}
// outputProcessor.overwrite();
FFExecutor<Object> executor = builder.build();
System.out.println(executor.getCommandLine());
}
use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas in project fmv by f-agu.
the class MovieScriptConverter method convert.
/**
* @see org.fagu.fmv.mymedia.classify.Converter#convert(org.fagu.fmv.media.Media,
* org.fagu.fmv.utils.file.FileFinder.InfosFile, java.io.File, org.fagu.fmv.mymedia.classify.ConverterListener)
*/
@Override
public void convert(Movie srcMedia, FileFinder<Movie>.InfosFile infosFile, File destFile, ConverterListener<Movie> listener) throws IOException {
openScript();
File srcFile = srcMedia.getFile();
MovieMetadatas infos = srcMedia.getMetadatas();
int audioFrequency = FFMpegUtils.minAudioSampleRate(infos, DEFAULT_AUDIO_SAMPLE_RATE);
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
builder.addMediaInputFile(srcFile).setMovieMetadatas(infos);
Rotation rotation = rotateMap.get(srcFile.getName());
if (rotation != null) {
if (rotation != Rotation.R_0) {
builder.filter(Rotate.create(rotation));
}
} else {
builder.filter(AutoRotate.create(infos));
}
Size newSize = FFReducer.applyScaleIfNecessary(builder, infos, getMaxSize(), getScaleLogger(), rotation);
writeLabel();
script.println("rem " + (newSize.isLandscape() ? "landscape" : newSize.isPortrait() ? "portrait" : "square"));
builder.filter(ResampleAudio.build().frequency(audioFrequency));
Optional<VolumeDetected> findFirst = infosFile.getInfos().stream().filter(o -> o instanceof VolumeDetected).map(o -> (VolumeDetected) o).findFirst();
if (findFirst.isPresent()) {
VolumeDetected volumeDetected = findFirst.get();
builder.filter(Volume.build().increaseToMax(volumeDetected));
}
File dest = new File(destFile.getParentFile(), FilenameUtils.getBaseName(destFile.getName()) + ".mp4");
OutputProcessor outputProcessor = builder.addMediaOutputFile(dest);
outputProcessor.qualityScale(0);
Transpose.addMetadataRotate(outputProcessor, Rotation.R_0);
outputProcessor.format("mp4");
// outputProcessor.overwrite();
FFExecutor<Object> executor = builder.build();
try {
script.println("if exist \"" + dest.getPath() + "\" goto :movie_" + currentVideo);
script.println("echo.");
script.println("echo Frame: " + infos.getVideoStream().countEstimateFrames().getAsInt());
script.println(executor.getCommandLine());
script.println();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas in project fmv by f-agu.
the class MovieFinder method flushToMap.
// *****************************************
/**
* @see org.fagu.fmv.utils.file.FileFinder#flushToMap(java.util.List, java.util.function.Consumer)
*/
@Override
protected Future<Map<FileFound, InfosFile>> flushToMap(List<FileFound> buffer, Consumer<List<FileFound>> consumer) {
Map<FileFound, InfosFile> outMap = new LinkedHashMap<>(buffer.size());
for (FileFound fileFound : buffer) {
File file = fileFound.getFileFound();
try {
MovieMetadatas movieMetadatas = FFHelper.videoMetadatas(file);
Map<FileFound, InfosFile> flushMap = Collections.singletonMap(fileFound, new InfosFile(new Movie(file, movieMetadatas)));
outMap.putAll(flushMap);
if (consumer != null) {
consumer.accept(Collections.singletonList(fileFound));
}
afterFlush(flushMap);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return new DoneFuture<>(outMap);
}
Aggregations