Search in sources :

Example 11 with FFMPEGExecutorBuilder

use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder 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 12 with FFMPEGExecutorBuilder

use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder 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)

Example 13 with FFMPEGExecutorBuilder

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

Example 14 with FFMPEGExecutorBuilder

use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder in project fmv by f-agu.

the class FFHelper method cutConcat.

/**
 * @param inFiles
 * @param outFile
 * @throws IOException
 */
public static void cutConcat(List<File> inFiles, File outFile) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    Concat concat = Concat.create(builder, inFiles);
    // for(File inFile : inFiles) {
    // InputProcessor inputProcessor = builder.inputFile(inFile);
    // 
    // // les 2 SetPTS permettent de commencer la video au debut car une video ne
    // commence pas toujours a 0 !
    // 
    // SetPTS setPTS = new SetPTSVideo();
    // setPTS.setStartAtFirstFrame();
    // FilterComplex setPTSComplex = FilterComplex.createWith(setPTS);
    // setPTSComplex.addInput(inputProcessor, Type.VIDEO);
    // builder.add(setPTSComplex);
    // concat.addInput(setPTSComplex);
    // 
    // setPTS = new SetPTSAudio();
    // setPTS.setStartAtFirstFrame();
    // setPTSComplex = FilterComplex.createWith(setPTS);
    // setPTSComplex.addInput(inputProcessor, Type.AUDIO);
    // builder.add(setPTSComplex);
    // concat.addInput(setPTSComplex);
    // }
    builder.filter(concat);
    builder.addMediaOutputFile(outFile).qualityScaleAudio(0).qualityScaleVideo(0).codec(H264.findRecommanded().mostCompatible()).format("mp4").overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : Concat(org.fagu.fmv.ffmpeg.filter.impl.Concat) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)

Example 15 with FFMPEGExecutorBuilder

use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder 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();
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Hue(org.fagu.fmv.ffmpeg.filter.impl.Hue) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Boxblur(org.fagu.fmv.ffmpeg.filter.impl.Boxblur) Overlay(org.fagu.fmv.ffmpeg.filter.impl.Overlay)

Aggregations

FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)55 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)27 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)19 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)16 File (java.io.File)12 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)11 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)9 Size (org.fagu.fmv.utils.media.Size)6 Concat (org.fagu.fmv.ffmpeg.filter.impl.Concat)5 IOException (java.io.IOException)4 OptionalInt (java.util.OptionalInt)4 AudioGenerator (org.fagu.fmv.ffmpeg.filter.impl.AudioGenerator)4 NullSourceVideo (org.fagu.fmv.ffmpeg.filter.impl.NullSourceVideo)4 Progress (org.fagu.fmv.ffmpeg.operation.Progress)4 Duration (org.fagu.fmv.utils.time.Duration)4 Executable (org.fagu.fmv.core.exec.Executable)3 Source (org.fagu.fmv.core.exec.Source)3 OutputInfos (org.fagu.fmv.core.project.OutputInfos)3 MixAudioDuration (org.fagu.fmv.ffmpeg.filter.impl.AudioMix.MixAudioDuration)3 Blend (org.fagu.fmv.ffmpeg.filter.impl.Blend)3