use of org.fagu.fmv.ffmpeg.filter.FilterComplex 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.filter.FilterComplex in project fmv by f-agu.
the class FFHelper method audioHalfVolume.
/**
* @param inFile
* @param outFile
* @throws IOException
*/
public static void audioHalfVolume(File inFile, File outFile) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
AudioModifier audioModifier = AudioModifier.build().halfVolume().channelLayout(ChannelLayout.SAME);
FilterComplex filtercomplex = FilterComplex.create(audioModifier);
filtercomplex.addInput(inputProcessor);
builder.filter(filtercomplex);
builder.addMediaOutputFile(outFile).overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.
the class FFHelper method backgroundBlurOverlayScale.
/**
* @param inFile
* @param outFile
* @throws IOException
*/
public static void backgroundBlurOverlayScale(File inFile, File outFile) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
// inFile is in HD720
InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
// builder.filter(FilterComplex.create(AudioGenerator.build().silence()));
Boxblur boxblur = Boxblur.build().lumaRadius("8").lumaPower(8);
Hue hue = Hue.build().blackAndWhite();
FilterComplex blurAndBW = FilterComplex.create(boxblur, hue).addInput(inputProcessor);
FilterComplex scale = FilterComplex.create(Scale.build().size(Size.HD480)).addInput(inputProcessor);
Overlay overlay = Overlay.with(blurAndBW, scale).shortest(true).positionMiddle();
FilterComplex scale2 = FilterComplex.create(Scale.build().size(Size.HD480)).addInput(overlay);
builder.filter(scale2);
builder.addMediaOutputFile(outFile).overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.
the class FFHelper method videoToGraph.
/**
* @param inFile
* @param outFile
* @throws IOException
*/
public static void videoToGraph(File inAudio, File outImage) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
builder.getFFMPEGOperation().setAutoMap(AutoMaps.disable());
builder.addMediaInputFile(inAudio);
FilterComplex filter = FilterComplex.create(AudioToPictureShowWaves.build().size(Size.valueOf(1024, 200)));
builder.filter(filter);
builder.addMediaOutputFile(outImage).numberOfVideoFrameToRecord(1);
FFExecutor<Object> executor = builder.build();
System.out.println(executor.getCommandLine());
executor.execute();
}
use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.
the class FFHelper method overlay4.
/**
* @param in1VideoFile
* @param in2VideoFile
* @param in3VideoFile
* @param in4VideoFile
* @param outFile
* @param size
* @throws IOException
*/
public static void overlay4(File in1VideoFile, File in2VideoFile, File in3VideoFile, File in4VideoFile, File outFile, Size size) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
InputProcessor video1InputProcessor = builder.addMediaInputFile(in1VideoFile);
InputProcessor video2InputProcessor = builder.addMediaInputFile(in2VideoFile);
InputProcessor video3InputProcessor = builder.addMediaInputFile(in3VideoFile);
InputProcessor video4InputProcessor = builder.addMediaInputFile(in4VideoFile);
Size quartSize = size.getRatio().getSizeByWidth(size.getWidth() / 2);
NullSourceVideo nullSource = NullSourceVideo.build().size(size);
FilterComplex nullSourceFC = FilterComplex.create(nullSource);
SetPTSVideo setPTS = SetPTSVideo.createStartAtFirstFrame();
Scale scale = Scale.to(quartSize, ScaleMode.fitToBox());
FilterComplex vfc1 = FilterComplex.create(setPTS, scale).addInput(video1InputProcessor);
FilterComplex vfc2 = FilterComplex.create(setPTS, scale).addInput(video2InputProcessor);
FilterComplex vfc3 = FilterComplex.create(setPTS, scale).addInput(video3InputProcessor);
FilterComplex vfc4 = FilterComplex.create(setPTS, scale).addInput(video4InputProcessor);
builder.filter(nullSourceFC);
builder.filter(vfc1);
builder.filter(vfc2);
builder.filter(vfc3);
builder.filter(vfc4);
Overlay overlay1 = Overlay.with(nullSourceFC, vfc1).shortest(true);
Overlay overlay2 = Overlay.with(overlay1, vfc2).shortest(true).x(quartSize.getWidth());
Overlay overlay3 = Overlay.with(overlay2, vfc3).shortest(true).y(quartSize.getHeight());
Overlay.with(overlay3, vfc4).shortest(true).x(quartSize.getWidth()).y(quartSize.getHeight());
builder.addMediaOutputFile(outFile).overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
Aggregations