Search in sources :

Example 1 with Type

use of org.fagu.fmv.ffmpeg.operation.Type 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 Type

use of org.fagu.fmv.ffmpeg.operation.Type in project fmv by f-agu.

the class Reduce method doIt.

/**
 * @param sourceFile
 * @throws IOException
 */
private static void doIt(File sourceFile) throws IOException {
    String extension = FilenameUtils.getExtension(sourceFile.getName()).toLowerCase();
    if (!"mkv".equals(extension)) {
        extension = "mp4";
    }
    File destinationFile = new File(sourceFile.getParentFile(), FilenameUtils.getBaseName(sourceFile.getName()) + "-new." + extension);
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.hideBanner();
    InputProcessor inputProcessor = builder.addMediaInputFile(sourceFile);
    MovieMetadatas videoMetadatas = inputProcessor.getMovieMetadatas();
    boolean doVideo = !videoMetadatas.getVideoStream().isTreatedByFMV();
    boolean doAudio = doVideo;
    Collection<AudioStream> audioStreams = StreamOrder.sort(videoMetadatas.getAudioStreams());
    for (AudioStream audioStream : audioStreams) {
        if ("vorbis".equals(audioStream.codecName().get())) {
            doAudio |= true;
            break;
        }
        if ("aac".equals(audioStream.codecName().get())) {
            doAudio = false;
            break;
        }
    }
    if (!doVideo && !doAudio) {
        return;
    }
    OutputProcessor outputProcessor = builder.addMediaOutputFile(destinationFile);
    outputProcessor.qualityScale(0);
    // video
    for (Stream stream : videoMetadatas.getVideoStreams()) {
        outputProcessor.map().streams(stream).input(inputProcessor);
    }
    // audio
    for (Stream stream : audioStreams) {
        outputProcessor.map().streams(stream).input(inputProcessor);
    }
    // subtitle
    Collection<SubtitleStream> subtitleStreams = StreamOrder.sort(videoMetadatas.getSubtitleStreams());
    for (Stream stream : subtitleStreams) {
        outputProcessor.map().streams(stream).input(inputProcessor);
    }
    // other stream
    for (Stream stream : videoMetadatas.getStreams()) {
        Type type = stream.type();
        if (type != Type.AUDIO && type != Type.VIDEO && type != Type.SUBTITLE) {
            outputProcessor.map().streams(stream).input(inputProcessor);
        }
    }
    // ------------------------ disposition default ------------------------
    // 
    int count = 0;
    for (Stream stream : audioStreams) {
        boolean beDefault = count == 1;
        if (stream.isDefaultStream() != beDefault) {
            outputProcessor.metadataStream(Type.AUDIO, count, "disposition:default", beDefault ? "1" : "0");
        }
        ++count;
    }
    count = 0;
    for (Stream stream : subtitleStreams) {
        boolean beDefault = count == 1;
        if (stream.isDefaultStream() != beDefault) {
            outputProcessor.metadataStream(Type.SUBTITLE, count, "disposition:default", beDefault ? "1" : "0");
        }
        ++count;
    }
    // video
    if (doVideo) {
        outputProcessor.codec(H264.findRecommanded().strict(Strict.EXPERIMENTAL).quality(23));
    } else {
        outputProcessor.codecCopy(Type.VIDEO);
    }
    // audio
    if (doAudio) {
        outputProcessor.codecAutoSelectAAC();
    } else {
        outputProcessor.codecCopy(Type.AUDIO);
    }
    // subtitle
    if (videoMetadatas.contains(Type.SUBTITLE)) {
        outputProcessor.codecCopy(Type.SUBTITLE);
    }
    // outputProcessor.overwrite();
    FFExecutor<Object> executor = builder.build();
    System.out.println(executor.getCommandLine());
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) SubtitleStream(org.fagu.fmv.ffmpeg.metadatas.SubtitleStream) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) AudioStream(org.fagu.fmv.ffmpeg.metadatas.AudioStream) Type(org.fagu.fmv.ffmpeg.operation.Type) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) SubtitleStream(org.fagu.fmv.ffmpeg.metadatas.SubtitleStream) Stream(org.fagu.fmv.ffmpeg.metadatas.Stream) AudioStream(org.fagu.fmv.ffmpeg.metadatas.AudioStream) File(java.io.File)

Example 3 with Type

use of org.fagu.fmv.ffmpeg.operation.Type in project fmv by f-agu.

the class Bootstrap method populateDefaultColumns.

// ****************************************************
/**
 */
private void populateDefaultColumns() {
    columns.add(new NameColumn());
    columns.add(new VideoHDColumn());
    columns.add(new VideoSizeColumn());
    columns.add(new VideoSizeNameColumn());
    columns.add(new VideoSizeWidthColumn());
    columns.add(new VideoSizeHeightColumn());
    columns.add(new VideoRatioColumn());
    columns.add(new VideoRatioFloatColumn());
    columns.add(new VideoPixelsColumn());
    columns.add(new VideoDurationColumn());
    columns.add(new VideoCodecNameColumn());
    columns.add(new VideoCodecLongNameColumn());
    columns.add(new CategoryColumn(0));
    columns.add(new CategoryColumn(1));
    columns.add(new CategoryColumn(2));
    columns.add(new SizeBytesColumn());
    columns.add(new LastModifiedDateColumn());
    columns.add(new AudioColumn());
    columns.add(new AudioCodecNameColumn());
    columns.add(new AudioCodecLongNameColumn());
    columns.add(new VideoSubtitleColumn());
    for (Type type : Type.values()) {
        columns.add(new StreamTypeCountColumn(type));
    }
    columns.add(new FMVTreatedColumn());
    columns.add(new PathColumn());
}
Also used : VideoRatioColumn(org.fagu.fmv.mymedia.movie.list.column.VideoRatioColumn) VideoRatioFloatColumn(org.fagu.fmv.mymedia.movie.list.column.VideoRatioFloatColumn) AudioCodecLongNameColumn(org.fagu.fmv.mymedia.movie.list.column.AudioCodecLongNameColumn) AudioCodecNameColumn(org.fagu.fmv.mymedia.movie.list.column.AudioCodecNameColumn) VideoCodecNameColumn(org.fagu.fmv.mymedia.movie.list.column.VideoCodecNameColumn) AudioCodecLongNameColumn(org.fagu.fmv.mymedia.movie.list.column.AudioCodecLongNameColumn) NameColumn(org.fagu.fmv.mymedia.movie.list.column.NameColumn) VideoSizeNameColumn(org.fagu.fmv.mymedia.movie.list.column.VideoSizeNameColumn) VideoCodecLongNameColumn(org.fagu.fmv.mymedia.movie.list.column.VideoCodecLongNameColumn) VideoSizeHeightColumn(org.fagu.fmv.mymedia.movie.list.column.VideoSizeHeightColumn) LastModifiedDateColumn(org.fagu.fmv.mymedia.movie.list.column.LastModifiedDateColumn) VideoPixelsColumn(org.fagu.fmv.mymedia.movie.list.column.VideoPixelsColumn) VideoCodecNameColumn(org.fagu.fmv.mymedia.movie.list.column.VideoCodecNameColumn) VideoSizeWidthColumn(org.fagu.fmv.mymedia.movie.list.column.VideoSizeWidthColumn) VideoSubtitleColumn(org.fagu.fmv.mymedia.movie.list.column.VideoSubtitleColumn) CategoryColumn(org.fagu.fmv.mymedia.movie.list.column.CategoryColumn) StreamTypeCountColumn(org.fagu.fmv.mymedia.movie.list.column.StreamTypeCountColumn) PathColumn(org.fagu.fmv.mymedia.movie.list.column.PathColumn) VideoHDColumn(org.fagu.fmv.mymedia.movie.list.column.VideoHDColumn) Type(org.fagu.fmv.ffmpeg.operation.Type) VideoSizeNameColumn(org.fagu.fmv.mymedia.movie.list.column.VideoSizeNameColumn) AudioCodecNameColumn(org.fagu.fmv.mymedia.movie.list.column.AudioCodecNameColumn) VideoSizeColumn(org.fagu.fmv.mymedia.movie.list.column.VideoSizeColumn) FMVTreatedColumn(org.fagu.fmv.mymedia.movie.list.column.FMVTreatedColumn) SizeBytesColumn(org.fagu.fmv.mymedia.movie.list.column.SizeBytesColumn) VideoCodecLongNameColumn(org.fagu.fmv.mymedia.movie.list.column.VideoCodecLongNameColumn) AudioColumn(org.fagu.fmv.mymedia.movie.list.column.AudioColumn) VideoDurationColumn(org.fagu.fmv.mymedia.movie.list.column.VideoDurationColumn)

Example 4 with Type

use of org.fagu.fmv.ffmpeg.operation.Type in project fmv by f-agu.

the class StreamsTypeCountColumn method value.

/**
 * @see org.fagu.fmv.mymedia.movie.list.Column#value(Path, java.io.File, Supplier)
 */
@Override
public Optional<String> value(Path rootPath, File file, Supplier<Optional<MovieMetadatas>> movieMetadatasOptSupplier) {
    MovieMetadatas movieMetadatas = movieMetadatasOptSupplier.get().orElse(null);
    if (movieMetadatas == null) {
        return Optional.empty();
    }
    MapList<Type, Stream> typeMap = movieMetadatas.toTypeMap();
    if (typeMap.isEmpty()) {
        return Optional.empty();
    }
    StringJoiner joiner = new StringJoiner(", ");
    Type[] values = { Type.VIDEO, Type.AUDIO, Type.SUBTITLE, Type.DATA, Type.ATTACHEMENTS, Type.UNKNOWN };
    for (Type type : values) {
        List<Stream> list = typeMap.get(type);
        if (list != null) {
            joiner.add(type.name().toLowerCase() + "(" + list.size() + ")");
        }
    }
    return Optional.of(joiner.toString());
}
Also used : Type(org.fagu.fmv.ffmpeg.operation.Type) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) Stream(org.fagu.fmv.ffmpeg.metadatas.Stream) StringJoiner(java.util.StringJoiner)

Example 5 with Type

use of org.fagu.fmv.ffmpeg.operation.Type in project fmv by f-agu.

the class FilterGraphUI method getEdgeKey.

/**
 * @param label
 * @return
 */
private String getEdgeKey(Label label, FilterComplex filterComplex) {
    StringBuilder buf = new StringBuilder();
    buf.append(filterNaming.generate(label)).append('-');
    for (Type type : filterComplex.getTypes()) {
        buf.append(Character.toUpperCase(type.code()));
    }
    return buf.toString();
}
Also used : Type(org.fagu.fmv.ffmpeg.operation.Type)

Aggregations

Type (org.fagu.fmv.ffmpeg.operation.Type)9 File (java.io.File)3 Filter (org.fagu.fmv.ffmpeg.filter.Filter)3 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)3 FilterInput (org.fagu.fmv.ffmpeg.filter.FilterInput)2 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)2 Stream (org.fagu.fmv.ffmpeg.metadatas.Stream)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 StringJoiner (java.util.StringJoiner)1 FilterExec (org.fagu.fmv.core.exec.FilterExec)1 Identifiable (org.fagu.fmv.core.exec.Identifiable)1 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)1 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)1 FilterComplexBase (org.fagu.fmv.ffmpeg.filter.FilterComplexBase)1 GeneratedSource (org.fagu.fmv.ffmpeg.filter.GeneratedSource)1 AudioStream (org.fagu.fmv.ffmpeg.metadatas.AudioStream)1 SubtitleStream (org.fagu.fmv.ffmpeg.metadatas.SubtitleStream)1 MediaInput (org.fagu.fmv.ffmpeg.operation.MediaInput)1 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)1