Search in sources :

Example 11 with OutputProcessor

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

use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.

the class FFHelper method addFrenchAudioStream.

/**
 * @param videoFile
 * @param frenchAudioToAddFile
 * @param outFile
 * @throws Exception
 */
public static void addFrenchAudioStream(File videoFile, File frenchAudioToAddFile, File outFile) throws Exception {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    InputProcessor videoInput = builder.addMediaInputFile(videoFile);
    int countAudioStreams = videoInput.getMovieMetadatas().getAudioStreams().size();
    InputProcessor audioInput = builder.addMediaInputFile(frenchAudioToAddFile);
    OutputProcessor outputProcessor = builder.addMediaOutputFile(outFile);
    outputProcessor.map().allStreams().input(videoInput).input(audioInput);
    outputProcessor.codecCopy(Type.VIDEO).shortest().overwrite().metadataStream(Type.AUDIO, countAudioStreams, "language", "fra");
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor)

Example 13 with OutputProcessor

use of org.fagu.fmv.ffmpeg.operation.OutputProcessor 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 14 with OutputProcessor

use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.

the class FFMPEGExecutorBuilder method addMediaOutput.

/**
 * @param output
 * @return
 */
public OutputProcessor addMediaOutput(MediaOutput output) {
    if (output instanceof Muxer) {
        return mux((Muxer<?>) output);
    }
    Processor<?> processor = defaultFFMPEGOperation.getProcessor(output);
    if (processor != null && !(processor instanceof OutputProcessor)) {
        throw new IllegalArgumentException("Already defined: " + output);
    }
    OutputParameters outputParameters = defaultFFMPEGOperation.getOutputParameters();
    return outputParameters.addOutput(output);
}
Also used : OutputParameters(org.fagu.fmv.ffmpeg.operation.OutputParameters) Muxer(org.fagu.fmv.ffmpeg.format.Muxer) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor)

Example 15 with OutputProcessor

use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.

the class FFMPEGExecutorBuilder method mux.

/**
 * @param muxer
 * @return
 */
public OutputProcessor mux(Muxer<?> muxer) {
    MediaOutput mediaOutput = muxer.getMediaOutput();
    OutputProcessor outputProcessor = addMediaOutput(mediaOutput);
    muxer.eventAdded(outputProcessor, mediaOutput);
    outputProcessor.format(muxer.name());
    return outputProcessor;
}
Also used : MediaOutput(org.fagu.fmv.ffmpeg.operation.MediaOutput) FileMediaOutput(org.fagu.fmv.ffmpeg.ioe.FileMediaOutput) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor)

Aggregations

OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)23 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)19 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)13 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)11 File (java.io.File)7 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)5 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)5 Stream (org.fagu.fmv.ffmpeg.metadatas.Stream)4 Duration (org.fagu.fmv.utils.time.Duration)4 OptionalInt (java.util.OptionalInt)3 AudioStream (org.fagu.fmv.ffmpeg.metadatas.AudioStream)3 SubtitleStream (org.fagu.fmv.ffmpeg.metadatas.SubtitleStream)3 MediaOutput (org.fagu.fmv.ffmpeg.operation.MediaOutput)3 Progress (org.fagu.fmv.ffmpeg.operation.Progress)3 IOException (java.io.IOException)2 StringJoiner (java.util.StringJoiner)2 Executable (org.fagu.fmv.core.exec.Executable)2 Source (org.fagu.fmv.core.exec.Source)2 AudioGenerator (org.fagu.fmv.ffmpeg.filter.impl.AudioGenerator)2 MixAudioDuration (org.fagu.fmv.ffmpeg.filter.impl.AudioMix.MixAudioDuration)2