Search in sources :

Example 16 with FilterComplex

use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.

the class Concat method addPTS.

// ****************************************************
/**
 * @param builder
 * @param setPTS
 * @param input
 */
private void addPTS(FFMPEGExecutorBuilder builder, SetPTS<?> setPTS, Object input) {
    setPTS.startAtFirstFrame();
    FilterComplex setPTSComplex = FilterComplex.create(setPTS);
    setPTSComplex.addInput((FilterInput) input, setPTS.getTypes().iterator().next());
    if (input instanceof Filter) {
        builder.filter((Filter) input);
    }
    builder.filter(setPTSComplex);
    super.addInput(setPTSComplex);
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) Filter(org.fagu.fmv.ffmpeg.filter.Filter)

Example 17 with FilterComplex

use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.

the class PreparedImages method makeVideo.

/**
 * @param imageFrameRate
 * @param destVideo
 * @param videoFrameRate
 * @throws IOException
 */
public void makeVideo(FrameRate imageFrameRate, File destVideo, FPS videoFrameRate) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    // input
    File srcFiles = new File(parentFolder, "img_%0" + countLengthNumber() + "d." + extension);
    builder.addMediaInput(Image2Demuxer.from(srcFiles).frameRate(imageFrameRate));
    FilterComplex filter = FilterComplex.create(org.fagu.fmv.ffmpeg.filter.impl.FrameRate.to(videoFrameRate), Format.with(PixelFormat.YUV420P));
    builder.filter(filter);
    OutputProcessor outputProcessor = builder.addMediaOutputFile(destVideo);
    outputProcessor.codec(H264.findRecommanded());
    outputProcessor.overwrite();
    outputProcessor.map().allStreams().input(filter);
    FFExecutor<Object> executor = builder.build();
    System.out.println(executor.getCommandLine());
    int countEstimateFrames = (int) (files.size() * videoFrameRate.countFrameBySeconds() * imageFrameRate.invert().doubleValue());
    Progress progress = executor.getProgress();
    if (progress != null) {
        textProgressBar = FFMpegProgressBar.with(progress).byFrame(countEstimateFrames).build().makeBar("");
    }
    executor.execute();
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Progress(org.fagu.fmv.ffmpeg.operation.Progress) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) File(java.io.File)

Example 18 with FilterComplex

use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.

the class FFReducer method reduceAudio.

/**
 * @param metadatas
 * @param srcFile
 * @param destFile
 * @param bitRate
 * @param consolePrefixMessage
 * @param logger
 * @return
 * @throws IOException
 */
private boolean reduceAudio(MovieMetadatas metadatas, File srcFile, File destFile, String bitRate, String consolePrefixMessage, Logger logger) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.hideBanner();
    int sampleRate = Math.min(metadatas.getAudioStream().sampleRate().orElse(audioSampleRate), audioSampleRate);
    builder.addMediaInputFile(srcFile);
    FilterComplex filter = FilterComplex.create(ResampleAudio.build().frequency(sampleRate));
    builder.filter(filter);
    OutputProcessor outputProcessor = builder.addMediaOutputFile(destFile);
    outputProcessor.audioChannel(2);
    outputProcessor.audioBitRate(bitRate);
    outputProcessor.format(audioFormat);
    outputProcessor.overwrite();
    outputProcessor.map().allStreams().input(filter);
    FFExecutor<Object> executor = builder.build();
    executor.addListener(createLogFFExecListener(logger));
    Duration duration = metadatas.getAudioStream().duration().orElse(null);
    Progress progress = executor.getProgress();
    if (duration != null && progress != null) {
        textProgressBar = FFMpegProgressBar.with(progress).byDuration(duration).fileSize(srcFile.length()).build().makeBar(consolePrefixMessage);
    }
    executor.execute();
    return false;
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Progress(org.fagu.fmv.ffmpeg.operation.Progress) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) Duration(org.fagu.fmv.utils.time.Duration)

Example 19 with FilterComplex

use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.

the class ConcatFadeExecutable method applyConcatFade.

/**
 * @param builder
 * @param inputProcessors
 * @param toFile
 * @param cache
 * @throws IOException
 */
protected void applyConcatFade(FFMPEGExecutorBuilder builder, List<InputProcessor> inputProcessors, File toFile, Cache cache) throws IOException {
    if (inputProcessors.size() != 2) {
        throw new RuntimeException("Need 2 inputs ! : " + inputProcessors);
    }
    InputProcessor video1InputProcessor = inputProcessors.get(0);
    InputProcessor video2InputProcessor = inputProcessors.get(1);
    VideoStream videoStream1 = video1InputProcessor.getMovieMetadatas().getVideoStream();
    VideoStream videoStream2 = video2InputProcessor.getMovieMetadatas().getVideoStream();
    Time startTimeT1 = Time.valueOf(videoStream1.duration().get().toSeconds() - duration.toSeconds());
    Duration duration0T1 = Duration.valueOf(startTimeT1.toSeconds());
    Time startTimeT2 = Time.valueOf(videoStream2.duration().get().toSeconds() - duration.toSeconds());
    Duration durationT2END = Duration.valueOf(startTimeT2.toSeconds());
    // source 1: video
    NullSourceVideo nullSourceVideo1 = NullSourceVideo.build().size(videoStream1.size()).duration(durationT2END);
    Concat concat1V = Concat.create(builder, video1InputProcessor, FilterComplex.create(nullSourceVideo1)).countVideo(1).countAudio(0).countInputs(2);
    // source 1: audio
    AudioGenerator audioGenerator1 = AudioGenerator.build().silence().duration(durationT2END);
    Concat concat1A = Concat.create(builder, video1InputProcessor, FilterComplex.create(audioGenerator1)).countVideo(0).countAudio(1).countInputs(2);
    FilterComplex fadeAudio1 = FilterComplex.create(FadeAudio.out().startTime(startTimeT1).duration(duration)).addInput(concat1A);
    // source 2: video
    NullSourceVideo nullSourceVideo2 = NullSourceVideo.build().size(videoStream2.size()).duration(duration0T1);
    Concat concat2V = Concat.create(builder, FilterComplex.create(nullSourceVideo2), video2InputProcessor).countVideo(1).countAudio(0).countInputs(2);
    // source 2: audio
    AudioGenerator audioGenerator2 = AudioGenerator.build().silence().duration(duration0T1);
    Concat concat2A = Concat.create(builder, FilterComplex.create(audioGenerator2), video2InputProcessor).countVideo(0).countAudio(1).countInputs(2);
    FilterComplex fadeAudio2 = FilterComplex.create(FadeAudio.in().startTime(startTimeT1).duration(duration)).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(startTimeT1, duration);
    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);
    outputProcessor(builder, toFile, cache);
}
Also used : Concat(org.fagu.fmv.ffmpeg.filter.impl.Concat) FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) 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) 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) Duration(org.fagu.fmv.utils.time.Duration) MixAudioDuration(org.fagu.fmv.ffmpeg.filter.impl.AudioMix.MixAudioDuration)

Example 20 with FilterComplex

use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.

the class AbstractOperation method add.

/**
 * @see org.fagu.fmv.ffmpeg.operation.Operation#add(Filter)
 */
@Override
public boolean add(Filter filter) {
    if (rawFilters.contains(filter)) {
        return false;
    }
    OperationListener operationListener = operationListener();
    operationListener.eventPreAddFilter(this, filter);
    addRawFilter(filter);
    if (filter instanceof FilterComplexBase) {
        if (!containsFilterComplex) {
            containsFilterComplex = true;
            List<Filter> newFilters = new ArrayList<>();
            for (Filter f : filters) {
                FilterComplex fc = FilterComplex.create(f);
                newFilters.add(fc);
                addRawFilter(fc);
            }
            filters = newFilters;
        }
        filters.add(filter);
    } else {
        if (containsFilterComplex) {
            FilterComplex fc = FilterComplex.create(filter);
            filters.add(fc);
            addRawFilter(fc);
        } else {
            filters.add(filter);
        }
    }
    if (filter instanceof LibLog) {
        libLogs.add((LibLog) filter);
    }
    operationListener.eventPostAddFilter(this, filter);
    return true;
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) Filter(org.fagu.fmv.ffmpeg.filter.Filter) ArrayList(java.util.ArrayList) FilterComplexBase(org.fagu.fmv.ffmpeg.filter.FilterComplexBase)

Aggregations

FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)21 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)11 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)11 NullSourceVideo (org.fagu.fmv.ffmpeg.filter.impl.NullSourceVideo)5 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)5 Duration (org.fagu.fmv.utils.time.Duration)5 Filter (org.fagu.fmv.ffmpeg.filter.Filter)4 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 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)4 PixelFormat (org.fagu.fmv.ffmpeg.utils.PixelFormat)4 Time (org.fagu.fmv.utils.time.Time)4 ArrayList (java.util.ArrayList)3 FilterInput (org.fagu.fmv.ffmpeg.filter.FilterInput)3 Label (org.fagu.fmv.ffmpeg.filter.Label)3 OutputKey (org.fagu.fmv.ffmpeg.filter.OutputKey)3