Search in sources :

Example 21 with FFMPEGExecutorBuilder

use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder in project fmv by f-agu.

the class FFHelper method videoToGraph.

/**
 * @param inFile
 * @param outFile
 * @throws IOException
 */
public static void videoToGraph(File inAudio, File outImage) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.hideBanner();
    builder.getFFMPEGOperation().setAutoMap(AutoMaps.disable());
    builder.addMediaInputFile(inAudio);
    FilterComplex filter = FilterComplex.create(AudioToPictureShowWaves.build().size(Size.valueOf(1024, 200)));
    builder.filter(filter);
    builder.addMediaOutputFile(outImage).numberOfVideoFrameToRecord(1);
    FFExecutor<Object> executor = builder.build();
    System.out.println(executor.getCommandLine());
    executor.execute();
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)

Example 22 with FFMPEGExecutorBuilder

use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder in project fmv by f-agu.

the class FFHelper method concat.

/**
 * @param inFiles
 * @param outFile
 * @throws IOException
 */
public static void concat(List<File> inFiles, File outFile) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    Concat concat = Concat.create(builder, inFiles);
    builder.filter(concat);
    builder.mux(MP4Muxer.to(outFile).movflags(Movflags.FASTSTART)).qualityScale(0).codec(H264.findRecommanded().mostCompatible()).overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : Concat(org.fagu.fmv.ffmpeg.filter.impl.Concat) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)

Example 23 with FFMPEGExecutorBuilder

use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder 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 24 with FFMPEGExecutorBuilder

use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder 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 25 with FFMPEGExecutorBuilder

use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder in project fmv by f-agu.

the class CutExecutable method execute.

/**
 * @see org.fagu.fmv.core.exec.Executable#execute(java.io.File, Cache)
 */
@Override
public void execute(File toFile, Cache cache) throws IOException {
    Source source = getSource();
    Executable executable = getExecutable();
    if (executable == null && source == null) {
        return;
    }
    OutputInfos outputInfos = getProject().getOutputInfos();
    FFMPEGExecutorBuilder builder = FFUtils.builder(getProject());
    InputProcessor inputProcessor = null;
    if (executable != null) {
        File childExec = getProject().getFileCache().getFile(executable, cache);
        // executable.execute(childExec, cache);
        inputProcessor = builder.addMediaInputFile(childExec);
    } else if (source != null) {
        inputProcessor = (InputProcessor) source.createAndAdd(builder);
    } else {
        throw new IllegalArgumentException("Source or executable not defined !");
    }
    inputProcessor.timeSeek(startTime);
    // SetPTS videoSetPTS = new SetPTSVideo();
    // videoSetPTS.setStartAtFirstFrame();
    // FilterComplex videoSetPTSComplex = FilterComplex.createWith(videoSetPTS);
    // videoSetPTSComplex.addInput(inputProcessor, Type.VIDEO);
    // builder.add(videoSetPTSComplex);
    // 
    // SetPTS audioSetPTS = new SetPTSAudio();
    // audioSetPTS.setStartAtFirstFrame();
    // FilterComplex audioSetPTSComplex = FilterComplex.createWith(audioSetPTS);
    // audioSetPTSComplex.addInput(inputProcessor, Type.AUDIO);
    // builder.add(audioSetPTSComplex);
    BasicStreamMuxer muxer = BasicStreamMuxer.to(toFile, outputInfos.getFormat()).avoidNegativeTs(AvoidNegativeTs.MAKE_NON_NEGATIVE);
    OutputProcessor outputProcessor = builder.mux(muxer);
    outputProcessor.duration(duration);
    outputProcessor(outputProcessor, cache);
    FFExecutor<Object> executor = builder.build();
    executor.execute();
    if (cache == Cache.MAKE) {
        MovieMetadatas movieMetadatas = MovieMetadatas.with(toFile).extract();
        MovieMetadatasUtils.getDuration(movieMetadatas).ifPresent(this::setDuration);
    }
}
Also used : BasicStreamMuxer(org.fagu.fmv.ffmpeg.format.BasicStreamMuxer) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) OutputInfos(org.fagu.fmv.core.project.OutputInfos) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Executable(org.fagu.fmv.core.exec.Executable) File(java.io.File) Source(org.fagu.fmv.core.exec.Source)

Aggregations

FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)55 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)27 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)19 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)16 File (java.io.File)12 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)11 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)9 Size (org.fagu.fmv.utils.media.Size)6 Concat (org.fagu.fmv.ffmpeg.filter.impl.Concat)5 IOException (java.io.IOException)4 OptionalInt (java.util.OptionalInt)4 AudioGenerator (org.fagu.fmv.ffmpeg.filter.impl.AudioGenerator)4 NullSourceVideo (org.fagu.fmv.ffmpeg.filter.impl.NullSourceVideo)4 Progress (org.fagu.fmv.ffmpeg.operation.Progress)4 Duration (org.fagu.fmv.utils.time.Duration)4 Executable (org.fagu.fmv.core.exec.Executable)3 Source (org.fagu.fmv.core.exec.Source)3 OutputInfos (org.fagu.fmv.core.project.OutputInfos)3 MixAudioDuration (org.fagu.fmv.ffmpeg.filter.impl.AudioMix.MixAudioDuration)3 Blend (org.fagu.fmv.ffmpeg.filter.impl.Blend)3