Search in sources :

Example 11 with MovieMetadatas

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

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

the class FFHelper method oo.

/**
 * @param inFile
 * @param outFile
 * @throws IOException
 */
public static void oo(File srcFile, File outFile) throws IOException {
    final int DEFAULT_AUDIO_SAMPLE_RATE = 44100;
    final int DEFAULT_AUDIO_BIT_RATE = 128000;
    final int DEFAULT_AUDIO_CHANNEL = 2;
    Size size = Size.valueOf(930, 500);
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.hideBanner();
    // input
    InputProcessor inputProcessor = builder.addMediaInputFile(srcFile);
    // infos
    MovieMetadatas movieMetadatas = inputProcessor.getMovieMetadatas();
    int audioFrequency = FFMpegUtils.minAudioSampleRate(movieMetadatas, DEFAULT_AUDIO_SAMPLE_RATE);
    int audioBitRate = FFMpegUtils.minAudioBitRate(movieMetadatas, DEFAULT_AUDIO_BIT_RATE);
    int audioChannel = FFMpegUtils.minAudioChannel(movieMetadatas, DEFAULT_AUDIO_CHANNEL);
    // filters (garder l'ordre des filters)
    builder.filter(AutoRotate.create(movieMetadatas));
    builder.filter(Scale.to(size, ScaleMode.fitToBoxKeepAspectRatio()));
    builder.filter(Format.with(PixelFormat.YUV420P));
    builder.filter(ResampleAudio.build().frequency(audioFrequency));
    // output
    builder.mux(// 
    MP4Muxer.to(outFile).movflags(// , Movflags.FRAG_KEYFRAME, Movflags.EMPTY_MOOV
    Movflags.FASTSTART)).codec(// 
    H264.findRecommanded().mostCompatible()).pixelFormat(// pour quicktime/safari
    PixelFormat.YUV420P).codecAutoSelectAAC().audioChannel(// 
    audioChannel).audioBitRate(// 
    audioBitRate).overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Size(org.fagu.fmv.utils.media.Size) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor)

Example 13 with MovieMetadatas

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

the class FFHelper method extractThumbnails2GIF.

/**
 * similar extractThumbnails2JPEGS(..) without 'format("image2")'
 *
 * @param inFile
 * @param outFolder
 * @param countFrame
 * @return
 * @throws IOException
 */
public static void extractThumbnails2GIF(File inFile, File outFile, int countFrame) throws IOException {
    if (!"gif".equalsIgnoreCase(FilenameUtils.getExtension(outFile.getName()))) {
        throw new IllegalArgumentException("Not a gif: " + outFile.getPath());
    }
    // extract images
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    // global
    builder.hideBanner();
    builder.logLevel(LogLevel.INFO);
    // input
    InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
    // infos
    MovieMetadatas movieMetadatas = inputProcessor.getMovieMetadatas();
    VideoStream videoStream = movieMetadatas.getVideoStream();
    // filter
    SelectVideo selectVideo = SelectVideo.build().countFrame(videoStream, countFrame);
    builder.filter(selectVideo);
    // necessary ?
    builder.filter(Format.with(PixelFormat.RGB8));
    builder.filter(Format.with(PixelFormat.RGB24));
    // output
    builder.addMediaOutputFile(outFile).videoSync(VSync.PASSTHROUGH).overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) SelectVideo(org.fagu.fmv.ffmpeg.filter.impl.SelectVideo) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor)

Example 14 with MovieMetadatas

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

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

the class FileCache method scaleForMake.

/**
 * @param inFile
 * @throws IOException
 */
private void scaleForMake(File inFile) throws IOException {
    OutputInfos outputInfos = project.getOutputInfos();
    Size makeSize = outputInfos.getSize();
    MovieMetadatas metadatas = MovieMetadatas.with(inFile).extract();
    VideoStream videoStream = metadatas.getVideoStream();
    if (videoStream == null) {
        return;
    }
    Size videoSize = videoStream.size();
    if (videoSize.equals(makeSize)) {
        return;
    }
    File makeTmpFile = File.createTempFile(inFile.getName() + "-", "." + FilenameUtils.getExtension(inFile.getName()), inFile.getParentFile());
    try {
        makeTmpFile.delete();
        if (!inFile.renameTo(makeTmpFile)) {
            throw new IOException("Unable to rename " + inFile + " to " + makeTmpFile);
        }
        File toFile = inFile;
        FFMPEGExecutorBuilder builder = FFUtils.builder(project);
        // input
        builder.addMediaInputFile(makeTmpFile);
        // filter
        builder.filter(Scale.to(makeSize, ScaleMode.fitToBox()));
        // output
        builder.addMediaOutputFile(toFile).format(outputInfos.getFormat()).overwrite();
        FFExecutor<Object> build = builder.build();
        build.execute();
    } finally {
        makeTmpFile.delete();
    }
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Size(org.fagu.fmv.utils.media.Size) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) OutputInfos(org.fagu.fmv.core.project.OutputInfos) IOException(java.io.IOException) File(java.io.File)

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