Search in sources :

Example 6 with Size

use of org.fagu.fmv.utils.media.Size 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 7 with Size

use of org.fagu.fmv.utils.media.Size in project fmv by f-agu.

the class FileCache method scaleForPreview.

/**
 * @param inFile
 * @param toFile
 * @param id
 * @throws IOException
 */
private void scaleForPreview(File inFile, File toFile, Identifiable identifiable) throws IOException {
    OutputInfos outputInfos = project.getOutputInfos();
    Size previewSize = outputInfos.getSize().fitAndKeepRatioTo(PREVIEW_SIZE);
    FFMPEGExecutorBuilder builder = FFUtils.builder(project);
    builder.addMediaInputFile(inFile);
    builder.filter(Scale.to(previewSize, ScaleMode.fitToBox()));
    Drawtext drawtext = Drawtext.build().x(0);
    drawtext.y(16 * identifiable.getDepth(i -> i instanceof Executable));
    drawtext.text(identifiable.getId() + " - %{pts} / %{n}").fontColor(Color.WHITE).fontSize(15);
    builder.filter(drawtext);
    builder.addMediaOutputFile(toFile).format(outputInfos.getFormat()).overwrite();
    FFExecutor<Object> build = builder.build();
    build.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Size(org.fagu.fmv.utils.media.Size) OutputInfos(org.fagu.fmv.core.project.OutputInfos) Drawtext(org.fagu.fmv.ffmpeg.filter.impl.Drawtext)

Example 8 with Size

use of org.fagu.fmv.utils.media.Size 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)

Example 9 with Size

use of org.fagu.fmv.utils.media.Size in project fmv by f-agu.

the class FFHelper method overlay4.

/**
 * @param in1VideoFile
 * @param in2VideoFile
 * @param in3VideoFile
 * @param in4VideoFile
 * @param outFile
 * @param size
 * @throws IOException
 */
public static void overlay4(File in1VideoFile, File in2VideoFile, File in3VideoFile, File in4VideoFile, File outFile, Size size) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    InputProcessor video1InputProcessor = builder.addMediaInputFile(in1VideoFile);
    InputProcessor video2InputProcessor = builder.addMediaInputFile(in2VideoFile);
    InputProcessor video3InputProcessor = builder.addMediaInputFile(in3VideoFile);
    InputProcessor video4InputProcessor = builder.addMediaInputFile(in4VideoFile);
    Size quartSize = size.getRatio().getSizeByWidth(size.getWidth() / 2);
    NullSourceVideo nullSource = NullSourceVideo.build().size(size);
    FilterComplex nullSourceFC = FilterComplex.create(nullSource);
    SetPTSVideo setPTS = SetPTSVideo.createStartAtFirstFrame();
    Scale scale = Scale.to(quartSize, ScaleMode.fitToBox());
    FilterComplex vfc1 = FilterComplex.create(setPTS, scale).addInput(video1InputProcessor);
    FilterComplex vfc2 = FilterComplex.create(setPTS, scale).addInput(video2InputProcessor);
    FilterComplex vfc3 = FilterComplex.create(setPTS, scale).addInput(video3InputProcessor);
    FilterComplex vfc4 = FilterComplex.create(setPTS, scale).addInput(video4InputProcessor);
    builder.filter(nullSourceFC);
    builder.filter(vfc1);
    builder.filter(vfc2);
    builder.filter(vfc3);
    builder.filter(vfc4);
    Overlay overlay1 = Overlay.with(nullSourceFC, vfc1).shortest(true);
    Overlay overlay2 = Overlay.with(overlay1, vfc2).shortest(true).x(quartSize.getWidth());
    Overlay overlay3 = Overlay.with(overlay2, vfc3).shortest(true).y(quartSize.getHeight());
    Overlay.with(overlay3, vfc4).shortest(true).x(quartSize.getWidth()).y(quartSize.getHeight());
    builder.addMediaOutputFile(outFile).overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) NullSourceVideo(org.fagu.fmv.ffmpeg.filter.impl.NullSourceVideo) SetPTSVideo(org.fagu.fmv.ffmpeg.filter.impl.SetPTSVideo) Size(org.fagu.fmv.utils.media.Size) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Scale(org.fagu.fmv.ffmpeg.filter.impl.Scale) Overlay(org.fagu.fmv.ffmpeg.filter.impl.Overlay)

Example 10 with Size

use of org.fagu.fmv.utils.media.Size in project fmv by f-agu.

the class Libx264NotDisibleBy2FFExecFallback method prepare.

/**
 * @see org.fagu.fmv.ffmpeg.executor.FFExecFallback#prepare(org.fagu.fmv.ffmpeg.executor.FFEnv, java.io.IOException)
 */
@Override
public boolean prepare(FFEnv ffEnv, IOException ioException) throws IOException {
    FFExecutor<Object> executor = ffEnv.getExecutor();
    AbstractOperation<?, ?> operation = (AbstractOperation<?, ?>) ffEnv.getOperation();
    for (String line : executor.getOutputReadLine().getLines()) {
        if (line.startsWith("[libx264 @") && line.contains(" not divisible by 2")) {
            for (Filter filter : operation.getFilters()) {
                if (filter instanceof Scale) {
                    Scale scale = (Scale) filter;
                    Size size = scale.getSize();
                    ScaleMode scaleMode = scale.getScaleMode();
                    if (size != null && scaleMode != null) {
                        Size newSize = resize(size);
                        if (newSize == null) {
                            return false;
                        }
                        scale.set(size, scaleMode);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : AbstractOperation(org.fagu.fmv.ffmpeg.operation.AbstractOperation) Filter(org.fagu.fmv.ffmpeg.filter.Filter) Size(org.fagu.fmv.utils.media.Size) Scale(org.fagu.fmv.ffmpeg.filter.impl.Scale) ScaleMode(org.fagu.fmv.ffmpeg.filter.impl.ScaleMode)

Aggregations

Size (org.fagu.fmv.utils.media.Size)12 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)7 File (java.io.File)5 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)5 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)5 IOException (java.io.IOException)4 Rotation (org.fagu.fmv.utils.media.Rotation)4 OutputInfos (org.fagu.fmv.core.project.OutputInfos)3 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)3 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)3 Logger (org.fagu.fmv.mymedia.logger.Logger)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Optional (java.util.Optional)2 OptionalInt (java.util.OptionalInt)2 FilenameUtils (org.apache.commons.io.FilenameUtils)2 FFExecutor (org.fagu.fmv.ffmpeg.executor.FFExecutor)2 AutoRotate (org.fagu.fmv.ffmpeg.filter.impl.AutoRotate)2 ResampleAudio (org.fagu.fmv.ffmpeg.filter.impl.ResampleAudio)2 Scale (org.fagu.fmv.ffmpeg.filter.impl.Scale)2