Search in sources :

Example 6 with Stream

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

use of org.fagu.fmv.ffmpeg.metadatas.Stream in project fmv by f-agu.

the class FFHelper method encodeTox264_KeepChaptersAndSubtitles.

/**
 * @param inMkvFile
 * @param outMp4File
 * @param locales
 * @throws IOException
 */
public static void encodeTox264_KeepChaptersAndSubtitles(File inFile, File outFile, Collection<Locale> locales) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.hideBanner();
    InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
    MovieMetadatas videoMetadatas = inputProcessor.getMovieMetadatas();
    OutputProcessor outputProcessor = builder.addMediaOutputFile(outFile);
    for (Stream stream : videoMetadatas.getStreams()) {
        // exclude some subtitles
        // if(stream.is(Type.SUBTITLE) && ! locales.contains(stream.locale())) {
        // continue;
        // }
        // if(stream.is(Type.AUDIO) && ! locales.contains(stream.locale())) {
        // continue;
        // }
        outputProcessor.map().streams(stream).input(inputProcessor);
    }
    outputProcessor.codec(H264.findRecommanded().strict(Strict.EXPERIMENTAL).quality(23)).codecAutoSelectAAC().codecCopy(Type.SUBTITLE).overwrite();
    FFExecutor<Object> executor = builder.build();
    // System.out.println(executor.getCommandLine());
    executor.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Stream(org.fagu.fmv.ffmpeg.metadatas.Stream) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream)

Example 8 with Stream

use of org.fagu.fmv.ffmpeg.metadatas.Stream in project fmv by f-agu.

the class FFReducer method reduceVideo.

/**
 * @param metadatas
 * @param srcFile
 * @param movieMetadatas
 * @param destFile
 * @param consolePrefixMessage
 * @param logger
 * @throws IOException
 */
public void reduceVideo(MovieMetadatas metadatas, File srcFile, MovieMetadatas movieMetadatas, File destFile, String consolePrefixMessage, Logger logger) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.hideBanner();
    InputProcessor inputProcessor = builder.addMediaInputFile(srcFile);
    builder.filter(AutoRotate.create(movieMetadatas));
    org.fagu.fmv.mymedia.reduce.FFReducer.applyScaleIfNecessary(builder, movieMetadatas, Size.HD720, logger);
    MovieMetadatas videoMetadatas = inputProcessor.getMovieMetadatas();
    Collection<AudioStream> audioStreams = StreamOrder.sort(videoMetadatas.getAudioStreams());
    OutputProcessor outputProcessor = builder.addMediaOutputFile(destFile);
    outputProcessor.qualityScale(0);
    // video
    for (Stream stream : videoMetadatas.getVideoStreams()) {
        logger.log("map[" + stream.index() + "] video: " + stream);
        outputProcessor.map().streams(stream).input(inputProcessor);
    }
    // audio
    for (Stream stream : audioStreams) {
        logger.log("map[" + stream.index() + "] audio: " + stream);
        outputProcessor.map().streams(stream).input(inputProcessor);
    }
    // subtitle
    Collection<SubtitleStream> subtitleStreams = StreamOrder.sort(videoMetadatas.getSubtitleStreams());
    for (Stream stream : subtitleStreams) {
        logger.log("map[" + stream.index() + "] subtitle: " + stream);
        outputProcessor.map().streams(stream).input(inputProcessor);
    }
    // -------------------------- codec -------------------------
    outputProcessor.codec(H264.findRecommanded().strict(Strict.EXPERIMENTAL).quality(23));
    // subtitle
    if (videoMetadatas.contains(Type.AUDIO)) {
        outputProcessor.codecCopy(Type.AUDIO);
    }
    // subtitle
    if (videoMetadatas.contains(Type.SUBTITLE)) {
        outputProcessor.codecCopy(Type.SUBTITLE);
    }
    outputProcessor.overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.addListener(org.fagu.fmv.mymedia.reduce.FFReducer.createLogFFExecListener(logger));
    OptionalInt countEstimateFrames = metadatas.getVideoStream().countEstimateFrames();
    Progress progress = executor.getProgress();
    if (countEstimateFrames.isPresent() && progress != null) {
        textProgressBar = FFMpegProgressBar.with(progress).byFrame(countEstimateFrames.getAsInt()).fileSize(srcFile.length()).build().makeBar(consolePrefixMessage);
    } else {
        StringJoiner joiner = new StringJoiner(", ");
        if (progress == null) {
            joiner.add("progress not found");
        }
        if (!countEstimateFrames.isPresent()) {
            joiner.add("nb frames nout found");
        }
        logger.log("No progress bar: " + joiner.toString());
    }
    executor.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Progress(org.fagu.fmv.ffmpeg.operation.Progress) SubtitleStream(org.fagu.fmv.ffmpeg.metadatas.SubtitleStream) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) OptionalInt(java.util.OptionalInt) AudioStream(org.fagu.fmv.ffmpeg.metadatas.AudioStream) 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) StringJoiner(java.util.StringJoiner)

Example 9 with Stream

use of org.fagu.fmv.ffmpeg.metadatas.Stream in project fmv by f-agu.

the class TSTest method test.

@Test
@Ignore
public void test() throws IOException {
    MovieMetadatas metadatas = MovieMetadatas.with(new File("d:\\tmp\\dvdout.ts")).extract();
    List<Stream> streams = metadatas.getStreams();
    System.out.println("count: " + streams.size());
    for (Stream stream : streams) {
        System.out.println(stream);
        if (stream.is(Type.VIDEO)) {
            VideoStream videoStream = (VideoStream) stream;
            System.out.println("   " + videoStream);
        } else if (stream.is(Type.AUDIO)) {
            AudioStream audioStream = (AudioStream) stream;
            System.out.println("   " + audioStream);
        }
    }
}
Also used : AudioStream(org.fagu.fmv.ffmpeg.metadatas.AudioStream) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) AudioStream(org.fagu.fmv.ffmpeg.metadatas.AudioStream) Stream(org.fagu.fmv.ffmpeg.metadatas.Stream) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Stream (org.fagu.fmv.ffmpeg.metadatas.Stream)9 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)8 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)5 AudioStream (org.fagu.fmv.ffmpeg.metadatas.AudioStream)5 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)5 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)5 StringJoiner (java.util.StringJoiner)4 SubtitleStream (org.fagu.fmv.ffmpeg.metadatas.SubtitleStream)4 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)4 File (java.io.File)3 OptionalInt (java.util.OptionalInt)3 Progress (org.fagu.fmv.ffmpeg.operation.Progress)3 Type (org.fagu.fmv.ffmpeg.operation.Type)3 CropDetect (org.fagu.fmv.ffmpeg.filter.impl.CropDetect)2 VolumeDetect (org.fagu.fmv.ffmpeg.filter.impl.VolumeDetect)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1