Search in sources :

Example 11 with InputProcessor

use of org.fagu.fmv.ffmpeg.operation.InputProcessor 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();
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) SetSAR(org.fagu.fmv.ffmpeg.filter.impl.SetSAR) Blend(org.fagu.fmv.ffmpeg.filter.impl.Blend) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Time(org.fagu.fmv.utils.time.Time) MixAudioDuration(org.fagu.fmv.ffmpeg.filter.impl.AudioMix.MixAudioDuration) Duration(org.fagu.fmv.utils.time.Duration) Concat(org.fagu.fmv.ffmpeg.filter.impl.Concat) NullSourceVideo(org.fagu.fmv.ffmpeg.filter.impl.NullSourceVideo) PixelFormat(org.fagu.fmv.ffmpeg.utils.PixelFormat) Format(org.fagu.fmv.ffmpeg.filter.impl.Format) AudioGenerator(org.fagu.fmv.ffmpeg.filter.impl.AudioGenerator) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor)

Example 12 with InputProcessor

use of org.fagu.fmv.ffmpeg.operation.InputProcessor in project fmv by f-agu.

the class FFHelper method oo.

/**
 * @param inFile
 * @param outFile
 * @throws IOException
 */
public static void oo(File srcFile, File outFile) throws IOException {
    final int DEFAULT_AUDIO_SAMPLE_RATE = 44100;
    final int DEFAULT_AUDIO_BIT_RATE = 128000;
    final int DEFAULT_AUDIO_CHANNEL = 2;
    Size size = Size.valueOf(930, 500);
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.hideBanner();
    // input
    InputProcessor inputProcessor = builder.addMediaInputFile(srcFile);
    // infos
    MovieMetadatas movieMetadatas = inputProcessor.getMovieMetadatas();
    int audioFrequency = FFMpegUtils.minAudioSampleRate(movieMetadatas, DEFAULT_AUDIO_SAMPLE_RATE);
    int audioBitRate = FFMpegUtils.minAudioBitRate(movieMetadatas, DEFAULT_AUDIO_BIT_RATE);
    int audioChannel = FFMpegUtils.minAudioChannel(movieMetadatas, DEFAULT_AUDIO_CHANNEL);
    // filters (garder l'ordre des filters)
    builder.filter(AutoRotate.create(movieMetadatas));
    builder.filter(Scale.to(size, ScaleMode.fitToBoxKeepAspectRatio()));
    builder.filter(Format.with(PixelFormat.YUV420P));
    builder.filter(ResampleAudio.build().frequency(audioFrequency));
    // output
    builder.mux(// 
    MP4Muxer.to(outFile).movflags(// , Movflags.FRAG_KEYFRAME, Movflags.EMPTY_MOOV
    Movflags.FASTSTART)).codec(// 
    H264.findRecommanded().mostCompatible()).pixelFormat(// pour quicktime/safari
    PixelFormat.YUV420P).codecAutoSelectAAC().audioChannel(// 
    audioChannel).audioBitRate(// 
    audioBitRate).overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Size(org.fagu.fmv.utils.media.Size) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor)

Example 13 with InputProcessor

use of org.fagu.fmv.ffmpeg.operation.InputProcessor 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();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) SplitAudio(org.fagu.fmv.ffmpeg.filter.impl.SplitAudio) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) SplitVideo(org.fagu.fmv.ffmpeg.filter.impl.SplitVideo) Fade(org.fagu.fmv.ffmpeg.filter.impl.Fade) OutputKey(org.fagu.fmv.ffmpeg.filter.OutputKey)

Example 14 with InputProcessor

use of org.fagu.fmv.ffmpeg.operation.InputProcessor in project fmv by f-agu.

the class FFHelper method resize.

/**
 * @param inFile
 * @param size
 * @param outFile
 * @throws IOException
 */
public static void resize(File inFile, Size size, File outFile) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
    builder.filter(Scale.to(size, ScaleMode.fitToBoxKeepAspectRatio()));
    builder.mux(MP4Muxer.to(outFile)).qualityScaleVideo(0).codecCopy(Type.AUDIO).codecCopy(Type.SUBTITLE).mapAllStreams(inputProcessor).overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.addListener(new FFExecListener() {

        @Override
        public void eventExecFailed(IOException e, CommandLine command) {
            System.out.println("FAILED: " + CommandLineUtils.toLine(command));
        }

        @Override
        public void eventPreExecFallbacks(CommandLine command, Collection<FFExecFallback> fallbacks) {
            System.out.println("With fallback: " + fallbacks);
            System.out.println(" -->: " + CommandLineUtils.toLine(command));
        }
    });
    executor.execute();
}
Also used : FFExecListener(org.fagu.fmv.ffmpeg.executor.FFExecListener) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) CommandLine(org.apache.commons.exec.CommandLine) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) IOException(java.io.IOException) FFExecFallback(org.fagu.fmv.ffmpeg.executor.FFExecFallback)

Example 15 with InputProcessor

use of org.fagu.fmv.ffmpeg.operation.InputProcessor in project fmv by f-agu.

the class FFHelper method extractThumbnails2GIF.

/**
 * similar extractThumbnails2JPEGS(..) without 'format("image2")'
 *
 * @param inFile
 * @param outFolder
 * @param countFrame
 * @return
 * @throws IOException
 */
public static void extractThumbnails2GIF(File inFile, File outFile, int countFrame) throws IOException {
    if (!"gif".equalsIgnoreCase(FilenameUtils.getExtension(outFile.getName()))) {
        throw new IllegalArgumentException("Not a gif: " + outFile.getPath());
    }
    // extract images
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    // global
    builder.hideBanner();
    builder.logLevel(LogLevel.INFO);
    // input
    InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
    // infos
    MovieMetadatas movieMetadatas = inputProcessor.getMovieMetadatas();
    VideoStream videoStream = movieMetadatas.getVideoStream();
    // filter
    SelectVideo selectVideo = SelectVideo.build().countFrame(videoStream, countFrame);
    builder.filter(selectVideo);
    // necessary ?
    builder.filter(Format.with(PixelFormat.RGB8));
    builder.filter(Format.with(PixelFormat.RGB24));
    // output
    builder.addMediaOutputFile(outFile).videoSync(VSync.PASSTHROUGH).overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) SelectVideo(org.fagu.fmv.ffmpeg.filter.impl.SelectVideo) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor)

Aggregations

InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)43 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)27 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)13 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)12 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)11 MediaInput (org.fagu.fmv.ffmpeg.operation.MediaInput)11 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)9 File (java.io.File)8 FilterInput (org.fagu.fmv.ffmpeg.filter.FilterInput)6 Test (org.junit.Test)6 NullSourceVideo (org.fagu.fmv.ffmpeg.filter.impl.NullSourceVideo)5 Duration (org.fagu.fmv.utils.time.Duration)5 Time (org.fagu.fmv.utils.time.Time)5 AudioGenerator (org.fagu.fmv.ffmpeg.filter.impl.AudioGenerator)4 MixAudioDuration (org.fagu.fmv.ffmpeg.filter.impl.AudioMix.MixAudioDuration)4 Blend (org.fagu.fmv.ffmpeg.filter.impl.Blend)4 Concat (org.fagu.fmv.ffmpeg.filter.impl.Concat)4 Format (org.fagu.fmv.ffmpeg.filter.impl.Format)4 SetSAR (org.fagu.fmv.ffmpeg.filter.impl.SetSAR)4 PixelFormat (org.fagu.fmv.ffmpeg.utils.PixelFormat)4