Search in sources :

Example 6 with Time

use of org.fagu.fmv.utils.time.Time in project fmv by f-agu.

the class TimeTestCase method testParse.

/**
 */
@Test
public void testParse() {
    assertEquals(Time.valueOf(0), Time.parse("0"));
    assertEquals(Time.valueOf(0), Time.parse("0.0"));
    assertEquals(Time.valueOf(1.00001), Time.parse("1.00001"));
    assertEquals(Time.valueOf(27.767000), Time.parse("27.767000"));
    assertEquals(new Time(0, 58, 59.988), Time.parse("58:59.988"));
    assertEquals(new Time(81, 58, 59.988), Time.parse("81:58:59.988"));
}
Also used : Time(org.fagu.fmv.utils.time.Time) Test(org.junit.Test)

Example 7 with Time

use of org.fagu.fmv.utils.time.Time in project fmv by f-agu.

the class Test method concatFade1.

public static void concatFade1(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();
    Time startTime_T1 = Time.valueOf(videoStream1.duration().get().toSeconds() - fadeDuration.toSeconds());
    Duration duration_0_T1 = Duration.valueOf(startTime_T1.toSeconds());
    Time startTime_T2 = Time.valueOf(videoStream2.duration().get().toSeconds() - fadeDuration.toSeconds());
    Duration duration_T2_END = Duration.valueOf(startTime_T2.toSeconds());
    // source 1
    NullSourceVideo nullSourceVideo1 = NullSourceVideo.build().size(videoStream1.size()).duration(duration_T2_END);
    AudioGenerator audioGenerator1 = AudioGenerator.build().silence().duration(duration_T2_END);
    Concat concat1 = Concat.create(builder, video1InputProcessor, FilterComplex.create(nullSourceVideo1), FilterComplex.create(audioGenerator1));
    FilterComplex fadeAudio1 = FilterComplex.create(FadeAudio.out().startTime(startTime_T1).duration(fadeDuration)).addInput(concat1);
    // source 2
    NullSourceVideo nullSourceVideo2 = NullSourceVideo.build().size(videoStream2.size()).duration(duration_0_T1);
    AudioGenerator audioGenerator2 = AudioGenerator.build().silence().duration(duration_0_T1);
    Concat concat2 = Concat.create(builder, FilterComplex.create(nullSourceVideo2), FilterComplex.create(audioGenerator2), video2InputProcessor);
    FilterComplex fadeAudio2 = FilterComplex.create(FadeAudio.in().startTime(startTime_T1).duration(fadeDuration)).addInput(concat2);
    // blend for fade / merge
    // video
    SetSAR setSAR = SetSAR.toRatio("1");
    Format formatRGBA = Format.with(PixelFormat.RGBA);
    FilterComplex vfc1 = FilterComplex.create(setSAR, formatRGBA).addInput(concat1);
    FilterComplex vfc2 = FilterComplex.create(setSAR, formatRGBA).addInput(concat2);
    Blend blend = Blend.build().mode(Mode.ADDITION).repeatLast(true).opacity(1).exprFade(startTime_T1, fadeDuration);
    Format formatYUV = Format.with(PixelFormat.YUVA422P10LE);
    FilterComplex vfcBlend = FilterComplex.create(blend, formatYUV).addInput(vfc1).addInput(vfc2);
    builder.filter(vfcBlend);
    // audio
    FilterComplex audioMix = AudioMix.build().duration(MixAudioDuration.SHORTEST).addInput(fadeAudio1).addInput(fadeAudio2);
    builder.filter(audioMix);
    // out
    OutputProcessor outputProcessor = builder.addMediaOutputFile(outFile);
    outputProcessor.overwrite();
    FFExecutor<Object> executor = builder.build();
    System.out.println(executor.getCommandLine());
    FilterGraphUI.show(builder.getFFMPEGOperation());
// 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) Time(org.fagu.fmv.utils.time.Time) MixAudioDuration(org.fagu.fmv.ffmpeg.filter.impl.AudioMix.MixAudioDuration) Duration(org.fagu.fmv.utils.time.Duration) 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) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor)

Example 8 with Time

use of org.fagu.fmv.utils.time.Time in project fmv by f-agu.

the class Test method concatFade2.

public static void concatFade2(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();
    Time startTime_T1 = Time.valueOf(videoStream1.duration().get().toSeconds() - fadeDuration.toSeconds());
    Duration duration_0_T1 = Duration.valueOf(startTime_T1.toSeconds());
    Time startTime_T2 = Time.valueOf(videoStream2.duration().get().toSeconds() - fadeDuration.toSeconds());
    Duration duration_T2_END = Duration.valueOf(startTime_T2.toSeconds());
    // source 1: video
    NullSourceVideo nullSourceVideo1 = NullSourceVideo.build().size(videoStream1.size()).duration(duration_T2_END);
    Concat concat1V = Concat.create(builder, video1InputProcessor, FilterComplex.create(nullSourceVideo1)).countVideo(1).countAudio(0).countInputs(2);
    // source 1: audio
    AudioGenerator audioGenerator1 = AudioGenerator.build().silence().duration(duration_T2_END);
    Concat concat1A = Concat.create(builder, video1InputProcessor, FilterComplex.create(audioGenerator1)).countVideo(0).countAudio(1).countInputs(2);
    FilterComplex fadeAudio1 = FilterComplex.create(FadeAudio.out().startTime(startTime_T1).duration(fadeDuration)).addInput(concat1A);
    // source 2: video
    NullSourceVideo nullSourceVideo2 = NullSourceVideo.build().size(videoStream2.size()).duration(duration_0_T1);
    Concat concat2V = Concat.create(builder, FilterComplex.create(nullSourceVideo2), video2InputProcessor).countVideo(1).countAudio(0).countInputs(2);
    // source 2: audio
    AudioGenerator audioGenerator2 = AudioGenerator.build().silence().duration(duration_0_T1);
    Concat concat2A = Concat.create(builder, FilterComplex.create(audioGenerator2), video2InputProcessor).countVideo(0).countAudio(1).countInputs(2);
    FilterComplex fadeAudio2 = FilterComplex.create(FadeAudio.in().startTime(startTime_T1).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(startTime_T1, 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
    OutputProcessor outputProcessor = builder.addMediaOutputFile(outFile);
    outputProcessor.overwrite();
    FFExecutor<Object> executor = builder.build();
    System.out.println(executor.getCommandLine());
    FilterGraphUI.show(builder.getFFMPEGOperation());
// 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) Time(org.fagu.fmv.utils.time.Time) MixAudioDuration(org.fagu.fmv.ffmpeg.filter.impl.AudioMix.MixAudioDuration) Duration(org.fagu.fmv.utils.time.Duration) 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) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor)

Example 9 with Time

use of org.fagu.fmv.utils.time.Time 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 10 with Time

use of org.fagu.fmv.utils.time.Time in project fmv by f-agu.

the class Blend method exprFade.

/**
 * @param startTime
 * @param fadeDuration
 * @return
 */
public Blend exprFade(Time startTime, Duration fadeDuration) {
    // 1.1 : startTime
    // 2.5 : endTime
    // 1.3 : fadeDuration
    Time endTime = startTime.add(fadeDuration);
    StringBuilder subExpr = new StringBuilder(100);
    // (if(gte(T,2.5),1,if(lte(T,1.1),0,min(max((T-1.1)/1.3,0),1))))
    subExpr.append("(if(gte(T,").append(endTime.toSeconds()).append("),1,if(lte(T,").append(startTime.toSeconds()).append("),0,min(max((T-");
    subExpr.append(startTime.toSeconds()).append(")/").append(fadeDuration.toSeconds()).append(",0),1))))");
    StringBuilder expr = new StringBuilder(200);
    // A*(1-(if(gte(T,2.5),1,if(lte(T,1.1),0,min(max((T-1.1)/1.3,0),1)))))+B*(if(gte(T,2.5),1,if(lte(T,1.1),0,min(max((T-1.1)/1.3,0),1))))
    expr.append("A*(1-").append(subExpr).append(")+B*").append(subExpr);
    return expr(expr.toString());
}
Also used : Time(org.fagu.fmv.utils.time.Time)

Aggregations

Time (org.fagu.fmv.utils.time.Time)16 Duration (org.fagu.fmv.utils.time.Duration)7 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)5 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 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)4 PixelFormat (org.fagu.fmv.ffmpeg.utils.PixelFormat)4 File (java.io.File)3 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)3 Test (org.junit.Test)3 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1