Search in sources :

Example 16 with MovieMetadatas

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

Example 17 with MovieMetadatas

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

the class AudioMixExecutable method execute.

/**
 * @see org.fagu.fmv.core.exec.Executable#execute()
 */
@Override
public void execute(File toFile, Cache cache) throws IOException {
    if (!hasChildren()) {
        return;
    }
    AudioMix audioMix = AudioMix.build();
    FFMPEGExecutorBuilder builder = FFUtils.builder(getProject());
    List<InputProcessor> inputProcessors = new ArrayList<>();
    // executable
    for (Executable executable : executables) {
        File file = getProject().getFileCache().getFile(executable, cache);
        InputProcessor inputProcessor = builder.addMediaInputFile(file);
        // audioMix.addInput(inputProcessor);
        inputProcessors.add(inputProcessor);
    }
    // source
    for (Source source : sources) {
        FilterInput filterInput = source.createAndAdd(builder);
        if (filterInput instanceof InputProcessor) {
            inputProcessors.add((InputProcessor) filterInput);
        // MovieMetadatas movieMetadatas = ((InputProcessor)filterInput).getMovieMetadatas();
        // if(movieMetadatas.contains(Type.AUDIO)) {
        // audioMix.addInput(filterInput, audioStart);
        // } else {
        // throw new RuntimeException("Source is not an audio stream: " + source);
        // }
        } else {
            throw new RuntimeException("Source is not a InputProcessor: " + source);
        }
    }
    List<InputProcessor> videoInputProcessors = new ArrayList<>();
    for (InputProcessor inputProcessor : inputProcessors) {
        MovieMetadatas movieMetadatas = inputProcessor.getMovieMetadatas();
        if (movieMetadatas.contains(Type.AUDIO) && !movieMetadatas.contains(Type.VIDEO)) {
            audioMix.addInput(inputProcessor, audioStart);
        } else {
            videoInputProcessors.add(inputProcessor);
            audioMix.addInput(inputProcessor);
        }
    }
    audioMix.duration(mixAudioDuration);
    OutputProcessor outputProcessor = outputProcessor(builder, toFile, cache);
    ObjectInvoker.invoke(outputProcessor, attributeMap);
    builder.filter(audioMix);
    Map map = outputProcessor.map();
    map.allStreams().input(audioMix);
    On videoStreams = map.types(Type.VIDEO);
    videoInputProcessors.stream().forEach(videoStreams::input);
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) AudioMix(org.fagu.fmv.ffmpeg.filter.impl.AudioMix) ArrayList(java.util.ArrayList) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Source(org.fagu.fmv.core.exec.Source) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) Executable(org.fagu.fmv.core.exec.Executable) File(java.io.File) Map(org.fagu.fmv.ffmpeg.operation.Map) On(org.fagu.fmv.ffmpeg.operation.Map.On)

Example 18 with MovieMetadatas

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

the class FFHelper method m4aToMp3.

/**
 * @param inFile
 * @param outFile
 * @throws IOException
 */
public static void m4aToMp3(File inFile, File outFile) throws IOException {
    final int SAMPLE_RATE = 44100;
    final String bitRate = "128k";
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.hideBanner();
    InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
    MovieMetadatas movieMetadatas = inputProcessor.getMovieMetadatas();
    int sampleRate = Math.min(movieMetadatas.getAudioStream().sampleRate().orElse(SAMPLE_RATE), SAMPLE_RATE);
    FilterComplex filter = FilterComplex.create(ResampleAudio.build().frequency(sampleRate));
    builder.filter(filter);
    OutputProcessor outputProcessor = builder.addMediaOutputFile(outFile).audioChannel(2).audioBitRate(bitRate).format("mp3").overwrite();
    outputProcessor.map().allStreams().input(filter);
    FFExecutor<Object> executor = builder.build();
    System.out.println(executor.getCommandLine());
// Integer numberOfFrames =
// movieMetadatas.getAudioStream().countEstimateFrames();
// prepareProgressBar(numberOfFrames, executor, consolePrefixMessage);
// executor.execute();
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) 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)

Example 19 with MovieMetadatas

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

the class FFHelper method extractThumbnails2JPEGS.

/**
 * @param inFile
 * @param outFolder
 * @param countFrame
 * @return
 * @throws IOException
 */
public static ExtractThumbnail extractThumbnails2JPEGS(File inFile, File outFolder, int countFrame) throws IOException {
    // extract images
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    // global
    builder.hideBanner();
    builder.logLevel(LogLevel.INFO);
    // input
    InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
    MovieMetadatas videoMetadatas = inputProcessor.getMovieMetadatas();
    VideoStream videoStream = videoMetadatas.getVideoStreams().get(0);
    if (!outFolder.exists()) {
        outFolder.mkdirs();
    }
    // filter
    SelectVideo selectVideo = SelectVideo.build().countFrame(videoStream, countFrame);
    builder.filter(selectVideo);
    // output
    builder.mux(Image2Muxer.to(new File(outFolder, "out%05d.jpg"))).videoSync(VSync.PASSTHROUGH).overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.execute();
    return ExtractThumbnail.find(outFolder, "out\\d+\\.jpg");
}
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) File(java.io.File)

Example 20 with MovieMetadatas

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

the class FFHelper method videoMetadatas.

/**
 * @param inFile
 * @return
 * @throws IOException
 */
public static MovieMetadatas videoMetadatas(File inFile) throws IOException {
    MediaInput input = new FileMediaInput(inFile);
    InfoOperation infoOperation = new InfoOperation(input);
    FFExecutor<MovieMetadatas> executor = new FFExecutor<>(infoOperation);
    Executed<MovieMetadatas> execute = executor.execute();
    return execute.getResult();
}
Also used : MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) FFExecutor(org.fagu.fmv.ffmpeg.executor.FFExecutor) FileMediaInput(org.fagu.fmv.ffmpeg.ioe.FileMediaInput) FileMediaInput(org.fagu.fmv.ffmpeg.ioe.FileMediaInput) MediaInput(org.fagu.fmv.ffmpeg.operation.MediaInput) InfoOperation(org.fagu.fmv.ffmpeg.operation.InfoOperation)

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