use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.
the class Test method concatFade1.
public static void concatFade1(File in1VideoFile, File in2VideoFile, Duration fadeDuration, File outFile) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
InputProcessor video1InputProcessor = builder.addMediaInputFile(in1VideoFile);
InputProcessor video2InputProcessor = builder.addMediaInputFile(in2VideoFile);
VideoStream videoStream1 = video1InputProcessor.getMovieMetadatas().getVideoStream();
VideoStream videoStream2 = video2InputProcessor.getMovieMetadatas().getVideoStream();
Time startTime_T1 = Time.valueOf(videoStream1.duration().get().toSeconds() - fadeDuration.toSeconds());
Duration duration_0_T1 = Duration.valueOf(startTime_T1.toSeconds());
Time startTime_T2 = Time.valueOf(videoStream2.duration().get().toSeconds() - fadeDuration.toSeconds());
Duration duration_T2_END = Duration.valueOf(startTime_T2.toSeconds());
// source 1
NullSourceVideo nullSourceVideo1 = NullSourceVideo.build().size(videoStream1.size()).duration(duration_T2_END);
AudioGenerator audioGenerator1 = AudioGenerator.build().silence().duration(duration_T2_END);
Concat concat1 = Concat.create(builder, video1InputProcessor, FilterComplex.create(nullSourceVideo1), FilterComplex.create(audioGenerator1));
FilterComplex fadeAudio1 = FilterComplex.create(FadeAudio.out().startTime(startTime_T1).duration(fadeDuration)).addInput(concat1);
// source 2
NullSourceVideo nullSourceVideo2 = NullSourceVideo.build().size(videoStream2.size()).duration(duration_0_T1);
AudioGenerator audioGenerator2 = AudioGenerator.build().silence().duration(duration_0_T1);
Concat concat2 = Concat.create(builder, FilterComplex.create(nullSourceVideo2), FilterComplex.create(audioGenerator2), video2InputProcessor);
FilterComplex fadeAudio2 = FilterComplex.create(FadeAudio.in().startTime(startTime_T1).duration(fadeDuration)).addInput(concat2);
// blend for fade / merge
// video
SetSAR setSAR = SetSAR.toRatio("1");
Format formatRGBA = Format.with(PixelFormat.RGBA);
FilterComplex vfc1 = FilterComplex.create(setSAR, formatRGBA).addInput(concat1);
FilterComplex vfc2 = FilterComplex.create(setSAR, formatRGBA).addInput(concat2);
Blend blend = Blend.build().mode(Mode.ADDITION).repeatLast(true).opacity(1).exprFade(startTime_T1, fadeDuration);
Format formatYUV = Format.with(PixelFormat.YUVA422P10LE);
FilterComplex vfcBlend = FilterComplex.create(blend, formatYUV).addInput(vfc1).addInput(vfc2);
builder.filter(vfcBlend);
// audio
FilterComplex audioMix = AudioMix.build().duration(MixAudioDuration.SHORTEST).addInput(fadeAudio1).addInput(fadeAudio2);
builder.filter(audioMix);
// out
OutputProcessor outputProcessor = builder.addMediaOutputFile(outFile);
outputProcessor.overwrite();
FFExecutor<Object> executor = builder.build();
System.out.println(executor.getCommandLine());
FilterGraphUI.show(builder.getFFMPEGOperation());
// executor.execute();
}
use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.
the class Test method concatFade2.
public static void concatFade2(File in1VideoFile, File in2VideoFile, Duration fadeDuration, File outFile) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
InputProcessor video1InputProcessor = builder.addMediaInputFile(in1VideoFile);
InputProcessor video2InputProcessor = builder.addMediaInputFile(in2VideoFile);
VideoStream videoStream1 = video1InputProcessor.getMovieMetadatas().getVideoStream();
VideoStream videoStream2 = video2InputProcessor.getMovieMetadatas().getVideoStream();
Time startTime_T1 = Time.valueOf(videoStream1.duration().get().toSeconds() - fadeDuration.toSeconds());
Duration duration_0_T1 = Duration.valueOf(startTime_T1.toSeconds());
Time startTime_T2 = Time.valueOf(videoStream2.duration().get().toSeconds() - fadeDuration.toSeconds());
Duration duration_T2_END = Duration.valueOf(startTime_T2.toSeconds());
// source 1: video
NullSourceVideo nullSourceVideo1 = NullSourceVideo.build().size(videoStream1.size()).duration(duration_T2_END);
Concat concat1V = Concat.create(builder, video1InputProcessor, FilterComplex.create(nullSourceVideo1)).countVideo(1).countAudio(0).countInputs(2);
// source 1: audio
AudioGenerator audioGenerator1 = AudioGenerator.build().silence().duration(duration_T2_END);
Concat concat1A = Concat.create(builder, video1InputProcessor, FilterComplex.create(audioGenerator1)).countVideo(0).countAudio(1).countInputs(2);
FilterComplex fadeAudio1 = FilterComplex.create(FadeAudio.out().startTime(startTime_T1).duration(fadeDuration)).addInput(concat1A);
// source 2: video
NullSourceVideo nullSourceVideo2 = NullSourceVideo.build().size(videoStream2.size()).duration(duration_0_T1);
Concat concat2V = Concat.create(builder, FilterComplex.create(nullSourceVideo2), video2InputProcessor).countVideo(1).countAudio(0).countInputs(2);
// source 2: audio
AudioGenerator audioGenerator2 = AudioGenerator.build().silence().duration(duration_0_T1);
Concat concat2A = Concat.create(builder, FilterComplex.create(audioGenerator2), video2InputProcessor).countVideo(0).countAudio(1).countInputs(2);
FilterComplex fadeAudio2 = FilterComplex.create(FadeAudio.in().startTime(startTime_T1).duration(fadeDuration)).addInput(concat2A);
// blend / merge video
SetSAR setSAR = SetSAR.toRatio("1");
Format formatRGBA = Format.with(PixelFormat.RGBA);
FilterComplex vfc1 = FilterComplex.create(setSAR, formatRGBA).addInput(concat1V);
FilterComplex vfc2 = FilterComplex.create(setSAR, formatRGBA).addInput(concat2V);
Blend blend = Blend.build().mode(Mode.ADDITION).repeatLast(true).opacity(1).exprFade(startTime_T1, fadeDuration);
Format formatYUV = Format.with(PixelFormat.YUVA422P10LE);
FilterComplex vfcBlend = FilterComplex.create(blend, formatYUV).addInput(vfc1).addInput(vfc2);
builder.filter(vfcBlend);
// merge audio
FilterComplex audioMix = AudioMix.build().duration(MixAudioDuration.SHORTEST).addInput(fadeAudio1).addInput(fadeAudio2);
builder.filter(audioMix);
// out
OutputProcessor outputProcessor = builder.addMediaOutputFile(outFile);
outputProcessor.overwrite();
FFExecutor<Object> executor = builder.build();
System.out.println(executor.getCommandLine());
FilterGraphUI.show(builder.getFFMPEGOperation());
// executor.execute();
}
use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.
the class FFHelper method splitTo3.
/**
* @param inFile
* @param outFile1
* @param outFile2
* @throws IOException
*/
public static void splitTo3(File inFile, File outFile1, File outFile2, File outFile3) throws IOException {
// outFile1 : no fade
// outFile2 : fade in
// outFile3 : fade out
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
SplitVideo splitVideo = SplitVideo.build();
splitVideo.addInput(inputProcessor);
OutputKey outv1 = splitVideo.addOutput();
OutputKey outv2 = splitVideo.addOutput();
OutputKey outv3 = splitVideo.addOutput();
SplitAudio splitAudio = SplitAudio.build();
splitAudio.addInput(inputProcessor);
OutputKey outa1 = splitAudio.addOutput();
OutputKey outa2 = splitAudio.addOutput();
OutputKey outa3 = splitAudio.addOutput();
Fade fade2 = Fade.create(FadeType.IN, Time.valueOf(0), Duration.valueOf(1));
Fade fade3 = Fade.create(FadeType.OUT, Time.valueOf(0), Duration.valueOf(1));
fade2.addInput(outv2).addInput(outa2);
fade3.addInput(outv3).addInput(outa3);
builder.filter(splitVideo);
builder.filter(splitAudio);
builder.filter(fade2);
builder.filter(fade3);
OutputProcessor outputProcessor1 = builder.addMediaOutputFile(outFile1);
outputProcessor1.map().allStreams().label(outv1.getLabel()).label(outa1.getLabel());
outputProcessor1.overwrite();
OutputProcessor outputProcessor2 = builder.addMediaOutputFile(outFile2);
outputProcessor2.map().allStreams().input(fade2);
outputProcessor2.overwrite();
OutputProcessor outputProcessor3 = builder.addMediaOutputFile(outFile3);
outputProcessor3.map().allStreams().input(fade3);
outputProcessor3.overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.
the class FFHelper method encodeTox264_KeepChaptersAndSubtitles.
/**
* @param inMkvFile
* @param outMp4File
* @param locales
* @throws IOException
*/
public static void encodeTox264_KeepChaptersAndSubtitles(File inFile, File outFile, Collection<Locale> locales) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
MovieMetadatas videoMetadatas = inputProcessor.getMovieMetadatas();
OutputProcessor outputProcessor = builder.addMediaOutputFile(outFile);
for (Stream stream : videoMetadatas.getStreams()) {
// exclude some subtitles
// if(stream.is(Type.SUBTITLE) && ! locales.contains(stream.locale())) {
// continue;
// }
// if(stream.is(Type.AUDIO) && ! locales.contains(stream.locale())) {
// continue;
// }
outputProcessor.map().streams(stream).input(inputProcessor);
}
outputProcessor.codec(H264.findRecommanded().strict(Strict.EXPERIMENTAL).quality(23)).codecAutoSelectAAC().codecCopy(Type.SUBTITLE).overwrite();
FFExecutor<Object> executor = builder.build();
// System.out.println(executor.getCommandLine());
executor.execute();
}
use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.
the class CutExecutable method execute.
/**
* @see org.fagu.fmv.core.exec.Executable#execute(java.io.File, Cache)
*/
@Override
public void execute(File toFile, Cache cache) throws IOException {
Source source = getSource();
Executable executable = getExecutable();
if (executable == null && source == null) {
return;
}
OutputInfos outputInfos = getProject().getOutputInfos();
FFMPEGExecutorBuilder builder = FFUtils.builder(getProject());
InputProcessor inputProcessor = null;
if (executable != null) {
File childExec = getProject().getFileCache().getFile(executable, cache);
// executable.execute(childExec, cache);
inputProcessor = builder.addMediaInputFile(childExec);
} else if (source != null) {
inputProcessor = (InputProcessor) source.createAndAdd(builder);
} else {
throw new IllegalArgumentException("Source or executable not defined !");
}
inputProcessor.timeSeek(startTime);
// SetPTS videoSetPTS = new SetPTSVideo();
// videoSetPTS.setStartAtFirstFrame();
// FilterComplex videoSetPTSComplex = FilterComplex.createWith(videoSetPTS);
// videoSetPTSComplex.addInput(inputProcessor, Type.VIDEO);
// builder.add(videoSetPTSComplex);
//
// SetPTS audioSetPTS = new SetPTSAudio();
// audioSetPTS.setStartAtFirstFrame();
// FilterComplex audioSetPTSComplex = FilterComplex.createWith(audioSetPTS);
// audioSetPTSComplex.addInput(inputProcessor, Type.AUDIO);
// builder.add(audioSetPTSComplex);
BasicStreamMuxer muxer = BasicStreamMuxer.to(toFile, outputInfos.getFormat()).avoidNegativeTs(AvoidNegativeTs.MAKE_NON_NEGATIVE);
OutputProcessor outputProcessor = builder.mux(muxer);
outputProcessor.duration(duration);
outputProcessor(outputProcessor, cache);
FFExecutor<Object> executor = builder.build();
executor.execute();
if (cache == Cache.MAKE) {
MovieMetadatas movieMetadatas = MovieMetadatas.with(toFile).extract();
MovieMetadatasUtils.getDuration(movieMetadatas).ifPresent(this::setDuration);
}
}
Aggregations