Search in sources :

Example 16 with InputProcessor

use of org.fagu.fmv.ffmpeg.operation.InputProcessor 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 17 with InputProcessor

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

Example 18 with InputProcessor

use of org.fagu.fmv.ffmpeg.operation.InputProcessor 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();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Stream(org.fagu.fmv.ffmpeg.metadatas.Stream) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream)

Example 19 with InputProcessor

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

the class FFHelper method speed.

/**
 * @param inFile
 * @param outFile
 * @param multiplyBy
 * @throws IOException
 */
public static void speed(File inFile, File outFile, float multiplyBy) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
    Speed speed = Speed.multiply(multiplyBy);
    speed.addInput(inputProcessor);
    builder.filter(speed);
    builder.addMediaOutputFile(outFile).overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : Speed(org.fagu.fmv.ffmpeg.filter.impl.Speed) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor)

Example 20 with InputProcessor

use of org.fagu.fmv.ffmpeg.operation.InputProcessor 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);
    }
}
Also used : BasicStreamMuxer(org.fagu.fmv.ffmpeg.format.BasicStreamMuxer) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) OutputInfos(org.fagu.fmv.core.project.OutputInfos) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Executable(org.fagu.fmv.core.exec.Executable) File(java.io.File) Source(org.fagu.fmv.core.exec.Source)

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