Search in sources :

Example 1 with FilterInput

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

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

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

the class GenericFilterExec method populateWithIdentifiables.

// *************************************************************
/**
 * @param filterComplex
 * @param cache
 * @param builder
 * @return
 */
protected Set<Type> populateWithIdentifiables(FilterComplexBase filterComplex, Cache cache, FFMPEGExecutorBuilder builder) {
    Set<Type> undeclaredTypes = new HashSet<>(filterComplex.getTypes());
    for (Identifiable identifiable : getIdentifiableChildren()) {
        if (identifiable.isExecutable()) {
            File file = getProject().getFileCache().getFile((Executable) identifiable, cache);
            InputProcessor inputProcessor = builder.addMediaInputFile(file);
            addInputIntoFilter(filterComplex, inputProcessor, undeclaredTypes);
        } else if (identifiable.isSource()) {
            FilterInput filterInput = ((Source) identifiable).createAndAdd(builder);
            addInputIntoFilter(filterComplex, filterInput, undeclaredTypes);
        } else if (identifiable.isFilterExec()) {
            Filter inFilter = ((FilterExec) identifiable).makeFilter(builder, cache);
            addInputIntoFilter(filterComplex, (FilterComplexBase) inFilter, undeclaredTypes);
        }
    }
    return undeclaredTypes;
}
Also used : FilterExec(org.fagu.fmv.core.exec.FilterExec) Type(org.fagu.fmv.ffmpeg.operation.Type) Filter(org.fagu.fmv.ffmpeg.filter.Filter) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) File(java.io.File) HashSet(java.util.HashSet) Identifiable(org.fagu.fmv.core.exec.Identifiable)

Example 4 with FilterInput

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

the class AudioMixExecutable method execute.

/**
 * @see org.fagu.fmv.core.exec.Executable#execute()
 */
@Override
public void execute(File toFile, Cache cache) throws IOException {
    if (!hasChildren()) {
        return;
    }
    AudioMix audioMix = AudioMix.build();
    FFMPEGExecutorBuilder builder = FFUtils.builder(getProject());
    List<InputProcessor> inputProcessors = new ArrayList<>();
    // executable
    for (Executable executable : executables) {
        File file = getProject().getFileCache().getFile(executable, cache);
        InputProcessor inputProcessor = builder.addMediaInputFile(file);
        // audioMix.addInput(inputProcessor);
        inputProcessors.add(inputProcessor);
    }
    // source
    for (Source source : sources) {
        FilterInput filterInput = source.createAndAdd(builder);
        if (filterInput instanceof InputProcessor) {
            inputProcessors.add((InputProcessor) filterInput);
        // MovieMetadatas movieMetadatas = ((InputProcessor)filterInput).getMovieMetadatas();
        // if(movieMetadatas.contains(Type.AUDIO)) {
        // audioMix.addInput(filterInput, audioStart);
        // } else {
        // throw new RuntimeException("Source is not an audio stream: " + source);
        // }
        } else {
            throw new RuntimeException("Source is not a InputProcessor: " + source);
        }
    }
    List<InputProcessor> videoInputProcessors = new ArrayList<>();
    for (InputProcessor inputProcessor : inputProcessors) {
        MovieMetadatas movieMetadatas = inputProcessor.getMovieMetadatas();
        if (movieMetadatas.contains(Type.AUDIO) && !movieMetadatas.contains(Type.VIDEO)) {
            audioMix.addInput(inputProcessor, audioStart);
        } else {
            videoInputProcessors.add(inputProcessor);
            audioMix.addInput(inputProcessor);
        }
    }
    audioMix.duration(mixAudioDuration);
    OutputProcessor outputProcessor = outputProcessor(builder, toFile, cache);
    ObjectInvoker.invoke(outputProcessor, attributeMap);
    builder.filter(audioMix);
    Map map = outputProcessor.map();
    map.allStreams().input(audioMix);
    On videoStreams = map.types(Type.VIDEO);
    videoInputProcessors.stream().forEach(videoStreams::input);
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) AudioMix(org.fagu.fmv.ffmpeg.filter.impl.AudioMix) ArrayList(java.util.ArrayList) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Source(org.fagu.fmv.core.exec.Source) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) Executable(org.fagu.fmv.core.exec.Executable) File(java.io.File) Map(org.fagu.fmv.ffmpeg.operation.Map) On(org.fagu.fmv.ffmpeg.operation.Map.On)

Example 5 with FilterInput

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

FilterInput (org.fagu.fmv.ffmpeg.filter.FilterInput)9 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)6 File (java.io.File)5 ArrayList (java.util.ArrayList)4 Executable (org.fagu.fmv.core.exec.Executable)3 Source (org.fagu.fmv.core.exec.Source)3 Filter (org.fagu.fmv.ffmpeg.filter.Filter)3 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)3 FilterExec (org.fagu.fmv.core.exec.FilterExec)2 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)2 In (org.fagu.fmv.ffmpeg.filter.FilterComplexBase.In)2 GeneratedSource (org.fagu.fmv.ffmpeg.filter.GeneratedSource)2 IOKey (org.fagu.fmv.ffmpeg.filter.IOKey)2 OutputKey (org.fagu.fmv.ffmpeg.filter.OutputKey)2 MediaInput (org.fagu.fmv.ffmpeg.operation.MediaInput)2 Type (org.fagu.fmv.ffmpeg.operation.Type)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Identifiable (org.fagu.fmv.core.exec.Identifiable)1 FilterComplexBase (org.fagu.fmv.ffmpeg.filter.FilterComplexBase)1