Search in sources :

Example 1 with FilterComplex

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

the class Concat method beforeAddAround.

// ****************************************************
/**
 * @param operation
 * @param filterNaming
 */
@Override
protected void beforeAddAround(Operation<?, ?> operation, FilterNaming filterNaming) {
    // copy pour acces concurrent
    ArrayList<Object> arrayList = new ArrayList<>(inputs);
    for (Object input : arrayList) {
        Object inputObj = null;
        Set<Type> types = Collections.emptySet();
        if (input instanceof File) {
            InputProcessor inputProcessor = builder.addMediaInputFile((File) input);
            inputObj = inputProcessor;
            types = getTypes(inputProcessor);
        } else if (input instanceof InputProcessor) {
            types = getTypes((InputProcessor) input);
            inputObj = input;
        } else if (input instanceof FilterComplex) {
            inputObj = input;
            types = ((FilterComplex) input).getTypes();
        } else if (input instanceof Filter) {
            throw new IllegalArgumentException("Filter forbidden: " + input.getClass().getName() + ". Wrap it with FilterComplex.create(...).");
        }
        if (startAtStartTime && inputObj != null) {
            boolean startAt = true;
            FilterInput filterInput = (FilterInput) inputObj;
            for (MediaInput mediaInput : filterInput.getInputs()) {
                if (mediaInput instanceof GeneratedSource) {
                    startAt = false;
                    break;
                }
            }
            if (startAt) {
                if (types.contains(Type.VIDEO) && (countVideo == null || countVideo != 0)) {
                    addPTS(builder, SetPTSVideo.build(), inputObj);
                }
                if (types.contains(Type.AUDIO) && (countAudio == null || countAudio != 0)) {
                    addPTS(builder, SetPTSAudio.build(), inputObj);
                }
            } else {
                builder.filter((Filter) inputObj);
                super.addInput((FilterInput) inputObj);
            }
        } else if (input instanceof FilterInput) {
            builder.filter((Filter) inputObj);
            super.addInput((FilterInput) input);
        } else {
            throw new IllegalArgumentException(input.getClass().getName());
        }
    }
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) ArrayList(java.util.ArrayList) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) GeneratedSource(org.fagu.fmv.ffmpeg.filter.GeneratedSource) Type(org.fagu.fmv.ffmpeg.operation.Type) Filter(org.fagu.fmv.ffmpeg.filter.Filter) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) File(java.io.File) MediaInput(org.fagu.fmv.ffmpeg.operation.MediaInput)

Example 2 with FilterComplex

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

the class FilterGraph method of.

/**
 * @param operation
 * @param filterNaming
 * @return
 */
public static FilterGraph of(Operation<?, ?> operation) {
    FilterGraph filterGraph = new FilterGraph(operation.getFilterNaming());
    List<FilterComplex> filterComplexs = operation.getFilterComplexs();
    for (FilterComplex filterComplex : filterComplexs) {
        // System.out.println(filterComplex);
        Map<IOKey, In> inputMap = filterComplex.getInputMap();
        if (inputMap.isEmpty()) {
            for (MediaInput mediaInput : filterComplex.getInputs()) {
                if (mediaInput instanceof GeneratedSource) {
                    filterGraph.roots.add(filterComplex);
                    for (OutputKey outputKey : filterComplex.getOutputKeys()) {
                        filterGraph.byOutMap.add(outputKey.getLabel(), filterComplex);
                    }
                }
            }
        } else {
            for (Entry<IOKey, In> entry : inputMap.entrySet()) {
                FilterInput filterInput = entry.getValue().getFilterInput();
                for (OutputKey inputKey : filterInput.getOutputKeys()) {
                    filterGraph.byInMap.add(inputKey.getLabel(), filterComplex);
                }
                if (filterInput instanceof InputProcessor) {
                    filterGraph.roots.add(filterComplex);
                }
                for (OutputKey outputKey : filterComplex.getOutputKeys()) {
                    filterGraph.byOutMap.add(outputKey.getLabel(), filterComplex);
                }
            }
        }
    }
    return filterGraph;
}
Also used : IOKey(org.fagu.fmv.ffmpeg.filter.IOKey) FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) In(org.fagu.fmv.ffmpeg.filter.FilterComplexBase.In) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) GeneratedSource(org.fagu.fmv.ffmpeg.filter.GeneratedSource) OutputKey(org.fagu.fmv.ffmpeg.filter.OutputKey) MediaInput(org.fagu.fmv.ffmpeg.operation.MediaInput)

Example 3 with FilterComplex

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

the class FilterGraph method discover.

// ***************************************************
/**
 * @param inLabel
 * @param filterComplex
 * @param outLabel
 * @param visitor
 * @param depth
 */
private <T> void discover(Label inLabel, FilterComplex filterComplex, Visitor<T> visitor, int depth) {
    for (OutputKey outputKey : filterComplex.getOutputKeys()) {
        Label outLabel = outputKey.getLabel();
        Set<FilterComplex> inFilters = null;
        if (inLabel != null) {
            inFilters = byOutMap.get(inLabel);
        }
        Set<FilterComplex> outFilters = byInMap.get(outLabel);
        visitor.visit(inLabel, inFilters, filterComplex, outFilters, outLabel, depth);
        if (outFilters != null) {
            for (FilterComplex childFC : outFilters) {
                discover(outLabel, childFC, visitor, depth + 1);
            }
        }
    }
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) Label(org.fagu.fmv.ffmpeg.filter.Label) OutputKey(org.fagu.fmv.ffmpeg.filter.OutputKey)

Example 4 with FilterComplex

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

the class FilterGraph method discover.

/**
 * @param visitorSupplier
 */
public <T> void discover(Supplier<Visitor<T>> visitorSupplier) {
    for (FilterComplex fcRoot : roots) {
        Visitor<T> visitor = visitorSupplier.get();
        discover(null, fcRoot, visitor, 0);
        visitor.close();
    }
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex)

Example 5 with FilterComplex

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

the class Test method concatFade1.

public static void concatFade1(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
    NullSourceVideo nullSourceVideo1 = NullSourceVideo.build().size(videoStream1.size()).duration(duration_T2_END);
    AudioGenerator audioGenerator1 = AudioGenerator.build().silence().duration(duration_T2_END);
    Concat concat1 = Concat.create(builder, video1InputProcessor, FilterComplex.create(nullSourceVideo1), FilterComplex.create(audioGenerator1));
    FilterComplex fadeAudio1 = FilterComplex.create(FadeAudio.out().startTime(startTime_T1).duration(fadeDuration)).addInput(concat1);
    // source 2
    NullSourceVideo nullSourceVideo2 = NullSourceVideo.build().size(videoStream2.size()).duration(duration_0_T1);
    AudioGenerator audioGenerator2 = AudioGenerator.build().silence().duration(duration_0_T1);
    Concat concat2 = Concat.create(builder, FilterComplex.create(nullSourceVideo2), FilterComplex.create(audioGenerator2), video2InputProcessor);
    FilterComplex fadeAudio2 = FilterComplex.create(FadeAudio.in().startTime(startTime_T1).duration(fadeDuration)).addInput(concat2);
    // blend for fade / merge
    // video
    SetSAR setSAR = SetSAR.toRatio("1");
    Format formatRGBA = Format.with(PixelFormat.RGBA);
    FilterComplex vfc1 = FilterComplex.create(setSAR, formatRGBA).addInput(concat1);
    FilterComplex vfc2 = FilterComplex.create(setSAR, formatRGBA).addInput(concat2);
    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);
    // 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)

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