Search in sources :

Example 21 with InputProcessor

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

the class GenericFilterExec method populateWithIdentifiables.

// *************************************************************
/**
 * @param filterComplex
 * @param cache
 * @param builder
 * @return
 */
protected Set<Type> populateWithIdentifiables(FilterComplexBase filterComplex, Cache cache, FFMPEGExecutorBuilder builder) {
    Set<Type> undeclaredTypes = new HashSet<>(filterComplex.getTypes());
    for (Identifiable identifiable : getIdentifiableChildren()) {
        if (identifiable.isExecutable()) {
            File file = getProject().getFileCache().getFile((Executable) identifiable, cache);
            InputProcessor inputProcessor = builder.addMediaInputFile(file);
            addInputIntoFilter(filterComplex, inputProcessor, undeclaredTypes);
        } else if (identifiable.isSource()) {
            FilterInput filterInput = ((Source) identifiable).createAndAdd(builder);
            addInputIntoFilter(filterComplex, filterInput, undeclaredTypes);
        } else if (identifiable.isFilterExec()) {
            Filter inFilter = ((FilterExec) identifiable).makeFilter(builder, cache);
            addInputIntoFilter(filterComplex, (FilterComplexBase) inFilter, undeclaredTypes);
        }
    }
    return undeclaredTypes;
}
Also used : FilterExec(org.fagu.fmv.core.exec.FilterExec) Type(org.fagu.fmv.ffmpeg.operation.Type) Filter(org.fagu.fmv.ffmpeg.filter.Filter) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) File(java.io.File) HashSet(java.util.HashSet) Identifiable(org.fagu.fmv.core.exec.Identifiable)

Example 22 with InputProcessor

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

the class FFMPEGExecutorBuilder method addMediaInputWebCam.

/**
 * @return
 */
public InputProcessor addMediaInputWebCam() {
    String format = Devices.webCam().getName();
    InputProcessor input = addMediaInput(new IntMediaInput(0));
    input.format(format);
    input.frameRate(FrameRate.PAL);
    return input;
}
Also used : IntMediaInput(org.fagu.fmv.ffmpeg.ioe.IntMediaInput) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor)

Example 23 with InputProcessor

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

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

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

Aggregations

InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)43 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)27 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)13 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)12 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)11 MediaInput (org.fagu.fmv.ffmpeg.operation.MediaInput)11 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)9 File (java.io.File)8 FilterInput (org.fagu.fmv.ffmpeg.filter.FilterInput)6 Test (org.junit.Test)6 NullSourceVideo (org.fagu.fmv.ffmpeg.filter.impl.NullSourceVideo)5 Duration (org.fagu.fmv.utils.time.Duration)5 Time (org.fagu.fmv.utils.time.Time)5 AudioGenerator (org.fagu.fmv.ffmpeg.filter.impl.AudioGenerator)4 MixAudioDuration (org.fagu.fmv.ffmpeg.filter.impl.AudioMix.MixAudioDuration)4 Blend (org.fagu.fmv.ffmpeg.filter.impl.Blend)4 Concat (org.fagu.fmv.ffmpeg.filter.impl.Concat)4 Format (org.fagu.fmv.ffmpeg.filter.impl.Format)4 SetSAR (org.fagu.fmv.ffmpeg.filter.impl.SetSAR)4 PixelFormat (org.fagu.fmv.ffmpeg.utils.PixelFormat)4