Search in sources :

Example 1 with Label

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

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

the class FilterGraphUI method addTail.

/**
 */
private void addTail() {
    // TODO autoMap by outputProcessor
    AutoMap autoMap = operation.getAutoMap();
    Set<Label> labels = autoMap.find(operation);
    Node node = graph.addNode("output");
    node.addAttribute("ui.label", "output");
    node.addAttribute("ui.class", "root");
    for (Label label : labels) {
        // System.out.println(filterNaming.generate(label));
        Set<FilterComplex> fcs = filterGraph.getByOut(label);
        for (FilterComplex outFC : fcs) {
            Node inNode = createOrGetNode(outFC);
            graph.addEdge("output" + label, inNode, node);
        }
    }
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) Node(org.graphstream.graph.Node) Label(org.fagu.fmv.ffmpeg.filter.Label) AutoMap(org.fagu.fmv.ffmpeg.operation.AutoMap)

Example 3 with Label

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

the class AbstractOperation method toArguments.

/**
 * @see org.fagu.fmv.ffmpeg.operation.Operation#toArguments()
 */
@Override
public List<String> toArguments() {
    OperationListener operationListener = operationListener();
    operationListener.eventPreToArguments(this);
    List<String> arguments = new ArrayList<>();
    // global
    getGlobalParameters().toArguments(arguments);
    // input
    getInputParameters().toArguments(arguments);
    // filter_complex
    if (containsFilterComplexs()) {
        List<FilterComplex> filterComplexs = getFilterComplexs();
        arguments.add("-filter_complex");
        StringBuilder fbuf = new StringBuilder();
        Iterator<FilterComplex> it = filterComplexs.iterator();
        boolean useLabels = autoMap.useLabels();
        for (; ; ) {
            FilterComplex f = it.next();
            if (!useLabels) {
                f.clearInput();
                f.clearOutput();
            }
            fbuf.append(f.toString());
            if (!it.hasNext()) {
                break;
            }
            fbuf.append(';');
        }
        arguments.add(fbuf.toString());
        if (!containsMap()) {
            // auto-map
            try {
                for (Label label : autoMap.find(this)) {
                    arguments.add("-map");
                    arguments.add(filterNaming.generateBrackets(label));
                }
            } catch (RuntimeException e) {
                throw new RuntimeException(arguments.toString(), e);
            }
        }
    } else {
        // filter
        for (Type type : Type.values()) {
            StringBuilder fbuf = new StringBuilder();
            List<Filter> filterSimples = getFilterSimples(type);
            if (!filterSimples.isEmpty()) {
                Iterator<Filter> it = filterSimples.iterator();
                for (; ; ) {
                    Filter f = it.next();
                    fbuf.append(f.toString());
                    if (!it.hasNext()) {
                        break;
                    }
                    fbuf.append(',');
                }
                String fstr = fbuf.toString();
                if (StringUtils.isNotBlank(fstr)) {
                    arguments.add("-filter:" + type.code());
                    arguments.add(fstr);
                }
            }
        }
    }
    // output
    getOutputParameters().toArguments(arguments);
    operationListener.eventPostToArguments(this);
    return arguments;
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) ArrayList(java.util.ArrayList) Label(org.fagu.fmv.ffmpeg.filter.Label) Filter(org.fagu.fmv.ffmpeg.filter.Filter)

Example 4 with Label

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

the class AutoMaps method oneStreamByType.

/**
 * @param types
 * @return
 */
public static AutoMap oneStreamByType(Set<Type> types, FilterNaming filterNaming) {
    return new AutoMap() {

        @Override
        public boolean useLabels() {
            return true;
        }

        @Override
        public Set<Label> find(Operation<?, ?> operation) {
            FilterGraph filterGraph = FilterGraph.of(operation);
            // filterGraph.discover(() -> Visitors.checkSameTypes());
            MapSet<Label, Type> mapSet = MultiValueMaps.hashMapHashSet();
            filterGraph.discover(() -> Visitors.lastLabelWithType(mapSet));
            Map<Type, Label> chdirMap = new HashMap<>(4);
            for (Entry<Label, Set<Type>> entry : mapSet.entrySet()) {
                for (Type type : entry.getValue()) {
                    if (chdirMap.putIfAbsent(type, entry.getKey()) != null) {
                        throw new RuntimeException("Type " + type + " already defined in an other output filter: " + mapSet);
                    }
                }
            }
            for (Type type : types) {
                // missing some types ?
                if (!chdirMap.containsKey(type)) {
                    InputParameters inputParameters = operation.getInputParameters();
                    for (IOEntity ioEntity : inputParameters.getIOEntities()) {
                        Processor<?> processor = inputParameters.getProcessor(ioEntity);
                        if (processor instanceof InputProcessor) {
                            try {
                                MovieMetadatas movieMetadatas = ((InputProcessor) processor).getMovieMetadatas();
                                if (movieMetadatas.contains(type)) {
                                    chdirMap.put(type, Label.input(processor.getIndex(), type));
                                    break;
                                }
                            } catch (Exception e) {
                                throw new RuntimeException(e);
                            }
                        }
                    }
                }
            }
            return new HashSet<>(chdirMap.values());
        }
    };
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) MapSet(org.fagu.fmv.utils.collection.MapSet) HashMap(java.util.HashMap) Label(org.fagu.fmv.ffmpeg.filter.Label) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) FilterGraph(org.fagu.fmv.ffmpeg.filter.graph.FilterGraph) HashSet(java.util.HashSet)

Aggregations

Label (org.fagu.fmv.ffmpeg.filter.Label)4 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Filter (org.fagu.fmv.ffmpeg.filter.Filter)1 OutputKey (org.fagu.fmv.ffmpeg.filter.OutputKey)1 FilterGraph (org.fagu.fmv.ffmpeg.filter.graph.FilterGraph)1 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)1 AutoMap (org.fagu.fmv.ffmpeg.operation.AutoMap)1 MapSet (org.fagu.fmv.utils.collection.MapSet)1 Node (org.graphstream.graph.Node)1