Search in sources :

Example 6 with AudioStream

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

the class AudioColumn 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) {
    List<AudioStream> audioStreams = movieMetadatasOptSupplier.get().map(MovieMetadatas::getAudioStreams).orElse(null);
    if (CollectionUtils.isEmpty(audioStreams)) {
        return Optional.empty();
    }
    StringJoiner joiner = new StringJoiner(", ");
    for (AudioStream audioStream : audioStreams) {
        String name = audioStream.title().orElse(audioStream.language().orElse(null));
        if (name == null || "und".equals(name)) {
            name = "?";
        }
        joiner.add(name);
    }
    String list = joiner.toString();
    return Optional.of(audioStreams.size() + (list.isEmpty() ? "" : ": " + list));
}
Also used : AudioStream(org.fagu.fmv.ffmpeg.metadatas.AudioStream) StringJoiner(java.util.StringJoiner)

Example 7 with AudioStream

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

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

the class ConsoleOutput method forOutput.

/**
 * @param fileSource
 * @param fromFile
 * @return
 */
public static String forOutput(FileSource fileSource, File fromFile) {
    StringBuilder buf = new StringBuilder(100);
    buf.append(StringUtils.rightPad(Integer.toString(fileSource.getNumber()), 3)).append(' ').append(' ');
    FileType fileType = fileSource.getFileType();
    if (fileType != null) {
        buf.append(fileType.name().charAt(0)).append(' ');
    }
    String meta = null;
    if (fileSource.isImage()) {
        ImageMetadatas imageMetadatas = fileSource.getImageMetadatas();
        if (imageMetadatas != null) {
            meta = imageMetadatas.getDimension().toString();
        }
    }
    if (fileSource.isAudioOrVideo()) {
        MovieMetadatas videoMetadatas = fileSource.getVideoMetadatas();
        if (videoMetadatas != null) {
            AudioStream audioStream = videoMetadatas.getAudioStream();
            VideoStream videoStream = videoMetadatas.getVideoStream();
            if (videoStream != null) {
                Optional<Duration> duration = videoStream.duration();
                String sd = duration.isPresent() ? duration.get().toString() : "";
                meta = videoStream.size().toString() + " " + sd;
            } else if (audioStream != null) {
                Optional<Duration> duration = audioStream.duration();
                meta = duration.isPresent() ? duration.get().toString() : "";
            }
        }
    }
    String subPath = null;
    if (fromFile != null) {
        subPath = StringUtils.substringAfter(fileSource.getFile().getPath(), fromFile.getPath() + File.separator);
    } else {
        subPath = fileSource.getFile().getName();
    }
    buf.append(StringUtils.rightPad(meta, 25)).append(' ').append(' ').append(subPath);
    return buf.toString();
}
Also used : ImageMetadatas(org.fagu.fmv.im.ImageMetadatas) AudioStream(org.fagu.fmv.ffmpeg.metadatas.AudioStream) Optional(java.util.Optional) FileType(org.fagu.fmv.media.FileType) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) Duration(org.fagu.fmv.utils.time.Duration)

Example 9 with AudioStream

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

AudioStream (org.fagu.fmv.ffmpeg.metadatas.AudioStream)9 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)5 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)5 Stream (org.fagu.fmv.ffmpeg.metadatas.Stream)4 OptionalInt (java.util.OptionalInt)3 StringJoiner (java.util.StringJoiner)3 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)3 SubtitleStream (org.fagu.fmv.ffmpeg.metadatas.SubtitleStream)3 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)3 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)3 File (java.io.File)2 Progress (org.fagu.fmv.ffmpeg.operation.Progress)2 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 CropDetect (org.fagu.fmv.ffmpeg.filter.impl.CropDetect)1 VolumeDetect (org.fagu.fmv.ffmpeg.filter.impl.VolumeDetect)1 Type (org.fagu.fmv.ffmpeg.operation.Type)1 ImageMetadatas (org.fagu.fmv.im.ImageMetadatas)1 FileType (org.fagu.fmv.media.FileType)1 Size (org.fagu.fmv.utils.media.Size)1