Search in sources :

Example 1 with OutputKey

use of org.fagu.fmv.ffmpeg.filter.OutputKey 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 2 with OutputKey

use of org.fagu.fmv.ffmpeg.filter.OutputKey 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 3 with OutputKey

use of org.fagu.fmv.ffmpeg.filter.OutputKey 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 4 with OutputKey

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

the class FilterGraphUI method addRoot.

// **************************************************
/**
 */
private void addRoot() {
    Map<InputProcessor, Node> inputProcessorNodeMap = new HashMap<>();
    operation.getInputProcessorStream().forEach(ip -> {
        for (OutputKey outputKey : ip.getOutputKeys()) {
            Node node = createRootNode(ip, outputKey);
            inputProcessorNodeMap.put(ip, node);
        }
    });
    for (FilterComplex rootFC : filterGraph.getRoots()) {
        Map<IOKey, In> inputMap = rootFC.getInputMap();
        if (!inputMap.isEmpty()) {
            for (Entry<IOKey, In> entry : inputMap.entrySet()) {
                FilterInput filterInput = entry.getValue().getFilterInput();
                if (filterInput instanceof InputProcessor) {
                    Node node = inputProcessorNodeMap.get(filterInput);
                    Edge edge = graph.addEdge(node.getId() + "-" + rootFC.toString(), createOrGetNode(rootFC), node);
                // edge.addAttribute("ui.label", values);
                }
            }
        }
    }
}
Also used : IOKey(org.fagu.fmv.ffmpeg.filter.IOKey) FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) HashMap(java.util.HashMap) In(org.fagu.fmv.ffmpeg.filter.FilterComplexBase.In) Node(org.graphstream.graph.Node) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Edge(org.graphstream.graph.Edge) OutputKey(org.fagu.fmv.ffmpeg.filter.OutputKey)

Aggregations

OutputKey (org.fagu.fmv.ffmpeg.filter.OutputKey)4 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)3 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)3 In (org.fagu.fmv.ffmpeg.filter.FilterComplexBase.In)2 FilterInput (org.fagu.fmv.ffmpeg.filter.FilterInput)2 IOKey (org.fagu.fmv.ffmpeg.filter.IOKey)2 HashMap (java.util.HashMap)1 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)1 GeneratedSource (org.fagu.fmv.ffmpeg.filter.GeneratedSource)1 Label (org.fagu.fmv.ffmpeg.filter.Label)1 Fade (org.fagu.fmv.ffmpeg.filter.impl.Fade)1 SplitAudio (org.fagu.fmv.ffmpeg.filter.impl.SplitAudio)1 SplitVideo (org.fagu.fmv.ffmpeg.filter.impl.SplitVideo)1 MediaInput (org.fagu.fmv.ffmpeg.operation.MediaInput)1 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)1 Edge (org.graphstream.graph.Edge)1 Node (org.graphstream.graph.Node)1