Search in sources :

Example 31 with MovieMetadatas

use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas 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

MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)31 File (java.io.File)17 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)17 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)14 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)13 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)12 Stream (org.fagu.fmv.ffmpeg.metadatas.Stream)8 IOException (java.io.IOException)6 AudioStream (org.fagu.fmv.ffmpeg.metadatas.AudioStream)6 OptionalInt (java.util.OptionalInt)5 Size (org.fagu.fmv.utils.media.Size)5 StringJoiner (java.util.StringJoiner)4 SubtitleStream (org.fagu.fmv.ffmpeg.metadatas.SubtitleStream)4 Progress (org.fagu.fmv.ffmpeg.operation.Progress)4 Type (org.fagu.fmv.ffmpeg.operation.Type)4 Logger (org.fagu.fmv.mymedia.logger.Logger)4 Rotation (org.fagu.fmv.utils.media.Rotation)4 Optional (java.util.Optional)3 FilenameUtils (org.apache.commons.io.FilenameUtils)3 FFExecutor (org.fagu.fmv.ffmpeg.executor.FFExecutor)3