Search in sources :

Example 11 with FilterComplex

use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.

the class FFHelper method audioToGraph.

/**
 * @param inFile
 * @param outFile
 * @throws IOException
 */
public static void audioToGraph(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 12 with FilterComplex

use of org.fagu.fmv.ffmpeg.filter.FilterComplex 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 13 with FilterComplex

use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.

the class FFHelper method concatFade.

/**
 * @param in1VideoFile
 * @param in2VideoFile
 * @param fadeDuration
 * @param outFile
 * @throws IOException
 */
public static void concatFade(File in1VideoFile, File in2VideoFile, Duration fadeDuration, File outFile) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    InputProcessor video1InputProcessor = builder.addMediaInputFile(in1VideoFile);
    InputProcessor video2InputProcessor = builder.addMediaInputFile(in2VideoFile);
    VideoStream videoStream1 = video1InputProcessor.getMovieMetadatas().getVideoStream();
    VideoStream videoStream2 = video2InputProcessor.getMovieMetadatas().getVideoStream();
    Optional<Duration> duration1 = videoStream1.duration();
    Time startTimeT1 = Time.valueOf(duration1.get().toSeconds() - fadeDuration.toSeconds());
    Duration duration0T1 = Duration.valueOf(startTimeT1.toSeconds());
    Optional<Duration> duration2 = videoStream2.duration();
    Time startTimeT2 = Time.valueOf(duration2.get().toSeconds() - fadeDuration.toSeconds());
    Duration durationT2END = Duration.valueOf(startTimeT2.toSeconds());
    // source 1: video
    NullSourceVideo nullSourceVideo1 = NullSourceVideo.build().size(videoStream1.size()).duration(durationT2END);
    Concat concat1V = Concat.create(builder, video1InputProcessor, FilterComplex.create(nullSourceVideo1)).countVideo(1).countAudio(0).countInputs(2);
    // source 1: audio
    AudioGenerator audioGenerator1 = AudioGenerator.build().silence().duration(durationT2END);
    Concat concat1A = Concat.create(builder, video1InputProcessor, FilterComplex.create(audioGenerator1)).countVideo(0).countAudio(1).countInputs(2);
    FilterComplex fadeAudio1 = FilterComplex.create(FadeAudio.out().startTime(startTimeT1).duration(fadeDuration)).addInput(concat1A);
    // source 2: video
    NullSourceVideo nullSourceVideo2 = NullSourceVideo.build().size(videoStream2.size()).duration(duration0T1);
    Concat concat2V = Concat.create(builder, FilterComplex.create(nullSourceVideo2), video2InputProcessor).countVideo(1).countAudio(0).countInputs(2);
    // source 2: audio
    AudioGenerator audioGenerator2 = AudioGenerator.build().silence().duration(duration0T1);
    Concat concat2A = Concat.create(builder, FilterComplex.create(audioGenerator2), video2InputProcessor).countVideo(0).countAudio(1).countInputs(2);
    FilterComplex fadeAudio2 = FilterComplex.create(FadeAudio.in().startTime(startTimeT1).duration(fadeDuration)).addInput(concat2A);
    // blend / merge video
    SetSAR setSAR = SetSAR.toRatio("1");
    Format formatRGBA = Format.with(PixelFormat.RGBA);
    FilterComplex vfc1 = FilterComplex.create(setSAR, formatRGBA).addInput(concat1V);
    FilterComplex vfc2 = FilterComplex.create(setSAR, formatRGBA).addInput(concat2V);
    Blend blend = Blend.build().mode(Mode.ADDITION).repeatLast(true).opacity(1).exprFade(startTimeT1, fadeDuration);
    Format formatYUV = Format.with(PixelFormat.YUVA422P10LE);
    FilterComplex vfcBlend = FilterComplex.create(blend, formatYUV).addInput(vfc1).addInput(vfc2);
    builder.filter(vfcBlend);
    // merge audio
    FilterComplex audioMix = AudioMix.build().duration(MixAudioDuration.SHORTEST).addInput(fadeAudio1).addInput(fadeAudio2);
    builder.filter(audioMix);
    // out
    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) SetSAR(org.fagu.fmv.ffmpeg.filter.impl.SetSAR) Blend(org.fagu.fmv.ffmpeg.filter.impl.Blend) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Duration(org.fagu.fmv.utils.time.Duration) MixAudioDuration(org.fagu.fmv.ffmpeg.filter.impl.AudioMix.MixAudioDuration) Time(org.fagu.fmv.utils.time.Time) Concat(org.fagu.fmv.ffmpeg.filter.impl.Concat) NullSourceVideo(org.fagu.fmv.ffmpeg.filter.impl.NullSourceVideo) PixelFormat(org.fagu.fmv.ffmpeg.utils.PixelFormat) Format(org.fagu.fmv.ffmpeg.filter.impl.Format) AudioGenerator(org.fagu.fmv.ffmpeg.filter.impl.AudioGenerator)

Example 14 with FilterComplex

use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.

the class FilterGraphUI method addTail.

/**
 */
private void addTail() {
    // TODO autoMap by outputProcessor
    AutoMap autoMap = operation.getAutoMap();
    Set<Label> labels = autoMap.find(operation);
    Node node = graph.addNode("output");
    node.addAttribute("ui.label", "output");
    node.addAttribute("ui.class", "root");
    for (Label label : labels) {
        // System.out.println(filterNaming.generate(label));
        Set<FilterComplex> fcs = filterGraph.getByOut(label);
        for (FilterComplex outFC : fcs) {
            Node inNode = createOrGetNode(outFC);
            graph.addEdge("output" + label, inNode, node);
        }
    }
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) Node(org.graphstream.graph.Node) Label(org.fagu.fmv.ffmpeg.filter.Label) AutoMap(org.fagu.fmv.ffmpeg.operation.AutoMap)

Example 15 with FilterComplex

use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.

the class FilterGraphUI method addRoot.

// **************************************************
/**
 */
private void addRoot() {
    Map<InputProcessor, Node> inputProcessorNodeMap = new HashMap<>();
    operation.getInputProcessorStream().forEach(ip -> {
        for (OutputKey outputKey : ip.getOutputKeys()) {
            Node node = createRootNode(ip, outputKey);
            inputProcessorNodeMap.put(ip, node);
        }
    });
    for (FilterComplex rootFC : filterGraph.getRoots()) {
        Map<IOKey, In> inputMap = rootFC.getInputMap();
        if (!inputMap.isEmpty()) {
            for (Entry<IOKey, In> entry : inputMap.entrySet()) {
                FilterInput filterInput = entry.getValue().getFilterInput();
                if (filterInput instanceof InputProcessor) {
                    Node node = inputProcessorNodeMap.get(filterInput);
                    Edge edge = graph.addEdge(node.getId() + "-" + rootFC.toString(), createOrGetNode(rootFC), node);
                // edge.addAttribute("ui.label", values);
                }
            }
        }
    }
}
Also used : IOKey(org.fagu.fmv.ffmpeg.filter.IOKey) FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) HashMap(java.util.HashMap) In(org.fagu.fmv.ffmpeg.filter.FilterComplexBase.In) Node(org.graphstream.graph.Node) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Edge(org.graphstream.graph.Edge) OutputKey(org.fagu.fmv.ffmpeg.filter.OutputKey)

Aggregations

FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)21 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)11 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)11 NullSourceVideo (org.fagu.fmv.ffmpeg.filter.impl.NullSourceVideo)5 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)5 Duration (org.fagu.fmv.utils.time.Duration)5 Filter (org.fagu.fmv.ffmpeg.filter.Filter)4 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 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)4 PixelFormat (org.fagu.fmv.ffmpeg.utils.PixelFormat)4 Time (org.fagu.fmv.utils.time.Time)4 ArrayList (java.util.ArrayList)3 FilterInput (org.fagu.fmv.ffmpeg.filter.FilterInput)3 Label (org.fagu.fmv.ffmpeg.filter.Label)3 OutputKey (org.fagu.fmv.ffmpeg.filter.OutputKey)3