Search in sources :

Example 16 with VideoStream

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

the class ConcatFadeExecutable method applyConcatFade.

/**
 * @param builder
 * @param inputProcessors
 * @param toFile
 * @param cache
 * @throws IOException
 */
protected void applyConcatFade(FFMPEGExecutorBuilder builder, List<InputProcessor> inputProcessors, File toFile, Cache cache) throws IOException {
    if (inputProcessors.size() != 2) {
        throw new RuntimeException("Need 2 inputs ! : " + inputProcessors);
    }
    InputProcessor video1InputProcessor = inputProcessors.get(0);
    InputProcessor video2InputProcessor = inputProcessors.get(1);
    VideoStream videoStream1 = video1InputProcessor.getMovieMetadatas().getVideoStream();
    VideoStream videoStream2 = video2InputProcessor.getMovieMetadatas().getVideoStream();
    Time startTimeT1 = Time.valueOf(videoStream1.duration().get().toSeconds() - duration.toSeconds());
    Duration duration0T1 = Duration.valueOf(startTimeT1.toSeconds());
    Time startTimeT2 = Time.valueOf(videoStream2.duration().get().toSeconds() - duration.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(duration)).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(duration)).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, duration);
    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);
    outputProcessor(builder, toFile, cache);
}
Also used : Concat(org.fagu.fmv.ffmpeg.filter.impl.Concat) FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) 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) 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) Time(org.fagu.fmv.utils.time.Time) Duration(org.fagu.fmv.utils.time.Duration) MixAudioDuration(org.fagu.fmv.ffmpeg.filter.impl.AudioMix.MixAudioDuration)

Example 17 with VideoStream

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

the class ConsoleOutput method forOutput.

/**
 * @param fileSource
 * @param fromFile
 * @return
 */
public static String forOutput(FileSource fileSource, File fromFile) {
    StringBuilder buf = new StringBuilder(100);
    buf.append(StringUtils.rightPad(Integer.toString(fileSource.getNumber()), 3)).append(' ').append(' ');
    FileType fileType = fileSource.getFileType();
    if (fileType != null) {
        buf.append(fileType.name().charAt(0)).append(' ');
    }
    String meta = null;
    if (fileSource.isImage()) {
        ImageMetadatas imageMetadatas = fileSource.getImageMetadatas();
        if (imageMetadatas != null) {
            meta = imageMetadatas.getDimension().toString();
        }
    }
    if (fileSource.isAudioOrVideo()) {
        MovieMetadatas videoMetadatas = fileSource.getVideoMetadatas();
        if (videoMetadatas != null) {
            AudioStream audioStream = videoMetadatas.getAudioStream();
            VideoStream videoStream = videoMetadatas.getVideoStream();
            if (videoStream != null) {
                Optional<Duration> duration = videoStream.duration();
                String sd = duration.isPresent() ? duration.get().toString() : "";
                meta = videoStream.size().toString() + " " + sd;
            } else if (audioStream != null) {
                Optional<Duration> duration = audioStream.duration();
                meta = duration.isPresent() ? duration.get().toString() : "";
            }
        }
    }
    String subPath = null;
    if (fromFile != null) {
        subPath = StringUtils.substringAfter(fileSource.getFile().getPath(), fromFile.getPath() + File.separator);
    } else {
        subPath = fileSource.getFile().getName();
    }
    buf.append(StringUtils.rightPad(meta, 25)).append(' ').append(' ').append(subPath);
    return buf.toString();
}
Also used : ImageMetadatas(org.fagu.fmv.im.ImageMetadatas) AudioStream(org.fagu.fmv.ffmpeg.metadatas.AudioStream) Optional(java.util.Optional) FileType(org.fagu.fmv.media.FileType) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) Duration(org.fagu.fmv.utils.time.Duration)

Example 18 with VideoStream

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

the class FFHelperTestCase method testOo_Rotate270.

/**
 * @throws Exception
 */
@Test
public void testOo_Rotate270() throws Exception {
    final MovieMetadatas movieMetadatas = mock(MovieMetadatas.class);
    VideoStream videoStream = mock(VideoStream.class);
    doReturn(videoStream).when(movieMetadatas).getVideoStream();
    doReturn(Rotation.R_270).when(videoStream).rotate();
    movieMetadatasSupplier = fileName -> movieMetadatas;
    File inFile = new File("in.mp4");
    File outFile = new File("out.mp4");
    FFHelper.oo(inFile, outFile);
    if (AutoRotate.isAutoRotateObsolete()) {
        assertCmd("-hide_banner -i in.mp4 -filter:a \"aresample=sample_rate=44100\" -filter:v \"scale=w='if(gt(dar,930/500),930,trunc(oh*dar/2)*2)':h='if(gt(dar,930/500),trunc(ow/dar/2)*2,500)',format=yuv420p\" -movflags +faststart -f mp4 -codec:v libx264 -preset medium -profile:v baseline -level 3.0 -crf 22 -pix_fmt yuv420p -codec:a aac -ac 2 -b:a 128000 -y -metadata:s:v:0 \"rotate=0\" out.mp4");
    } else {
        assertCmd("-hide_banner -i in.mp4 -filter:a \"aresample=sample_rate=44100\" -filter:v \"transpose=dir=cclock,scale=w='if(gt(dar,930/500),930,trunc(oh*dar/2)*2)':h='if(gt(dar,930/500),trunc(ow/dar/2)*2,500)',format=yuv420p\" -movflags +faststart -f mp4 -codec:v libx264 -preset medium -profile:v baseline -level 3.0 -crf 22 -pix_fmt yuv420p -codec:a aac -ac 2 -b:a 128000 -y -metadata:s:v:0 \"rotate=0\" out.mp4");
    }
}
Also used : MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) MockVideoStream(org.fagu.fmv.ffmpeg.MockMovieMetadatas.MockVideoStream) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) File(java.io.File) Test(org.junit.Test)

Example 19 with VideoStream

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

the class MockMovieMetadatas method video.

/**
 * @return
 */
public MockVideoStream video() {
    VideoStream videoStream = mock(VideoStream.class);
    doReturn(videoStream).when(movieMetadatas).getVideoStream();
    addStream(videoStream, Type.VIDEO, videoStreams);
    return new MockVideoStream(videoStream);
}
Also used : VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream)

Example 20 with VideoStream

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

the class TSTest method test.

@Test
@Ignore
public void test() throws IOException {
    MovieMetadatas metadatas = MovieMetadatas.with(new File("d:\\tmp\\dvdout.ts")).extract();
    List<Stream> streams = metadatas.getStreams();
    System.out.println("count: " + streams.size());
    for (Stream stream : streams) {
        System.out.println(stream);
        if (stream.is(Type.VIDEO)) {
            VideoStream videoStream = (VideoStream) stream;
            System.out.println("   " + videoStream);
        } else if (stream.is(Type.AUDIO)) {
            AudioStream audioStream = (AudioStream) stream;
            System.out.println("   " + audioStream);
        }
    }
}
Also used : AudioStream(org.fagu.fmv.ffmpeg.metadatas.AudioStream) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) AudioStream(org.fagu.fmv.ffmpeg.metadatas.AudioStream) Stream(org.fagu.fmv.ffmpeg.metadatas.Stream) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)21 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)11 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)8 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)8 File (java.io.File)6 AudioStream (org.fagu.fmv.ffmpeg.metadatas.AudioStream)5 Duration (org.fagu.fmv.utils.time.Duration)5 OptionalInt (java.util.OptionalInt)4 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)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 NullSourceVideo (org.fagu.fmv.ffmpeg.filter.impl.NullSourceVideo)4 SetSAR (org.fagu.fmv.ffmpeg.filter.impl.SetSAR)4 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)4 PixelFormat (org.fagu.fmv.ffmpeg.utils.PixelFormat)4 Size (org.fagu.fmv.utils.media.Size)4 Time (org.fagu.fmv.utils.time.Time)4