Search in sources :

Example 11 with Duration

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

the class BaseIdentifiable method sumDuration.

/**
 * @param identifiables
 * @return
 */
private Optional<Duration> sumDuration(Collection<? extends Identifiable> identifiables) {
    Duration duration = Duration.valueOf(0);
    for (Identifiable identifiable : identifiables) {
        Optional<Duration> dur = identifiable.getDuration();
        if (!dur.isPresent()) {
            return Optional.empty();
        }
        duration = duration.add(dur.get());
    }
    return Optional.of(duration);
}
Also used : Duration(org.fagu.fmv.utils.time.Duration)

Example 12 with Duration

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

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

the class FFReducer method reduceAudio.

/**
 * @param metadatas
 * @param srcFile
 * @param destFile
 * @param bitRate
 * @param consolePrefixMessage
 * @param logger
 * @return
 * @throws IOException
 */
private boolean reduceAudio(MovieMetadatas metadatas, File srcFile, File destFile, String bitRate, String consolePrefixMessage, Logger logger) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.hideBanner();
    int sampleRate = Math.min(metadatas.getAudioStream().sampleRate().orElse(audioSampleRate), audioSampleRate);
    builder.addMediaInputFile(srcFile);
    FilterComplex filter = FilterComplex.create(ResampleAudio.build().frequency(sampleRate));
    builder.filter(filter);
    OutputProcessor outputProcessor = builder.addMediaOutputFile(destFile);
    outputProcessor.audioChannel(2);
    outputProcessor.audioBitRate(bitRate);
    outputProcessor.format(audioFormat);
    outputProcessor.overwrite();
    outputProcessor.map().allStreams().input(filter);
    FFExecutor<Object> executor = builder.build();
    executor.addListener(createLogFFExecListener(logger));
    Duration duration = metadatas.getAudioStream().duration().orElse(null);
    Progress progress = executor.getProgress();
    if (duration != null && progress != null) {
        textProgressBar = FFMpegProgressBar.with(progress).byDuration(duration).fileSize(srcFile.length()).build().makeBar(consolePrefixMessage);
    }
    executor.execute();
    return false;
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Progress(org.fagu.fmv.ffmpeg.operation.Progress) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) Duration(org.fagu.fmv.utils.time.Duration)

Example 14 with Duration

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

the class Template method load.

public static Template load(File propertiesFile) throws IOException {
    Properties properties = new Properties();
    try (InputStream inputStream = new FileInputStream(propertiesFile)) {
        properties.load(inputStream);
    }
    Map<Time, File> modelMap = new HashMap<>();
    for (Entry<Object, Object> entry : properties.entrySet()) {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();
        if (key.startsWith("model.")) {
            Time time = Time.parse(key.substring(6));
            File file = findModel(propertiesFile, value);
            modelMap.put(time, file);
        }
    }
    String name = properties.getProperty("name");
    Time offsetStart = parseTime(properties.getProperty("offset-time"));
    Duration endDuration = parseDuration(properties.getProperty("end-duration"));
    Logo logo = loadLogo(properties);
    return new Template(name, modelMap, offsetStart, endDuration, logo);
}
Also used : HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Time(org.fagu.fmv.utils.time.Time) Duration(org.fagu.fmv.utils.time.Duration) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) File(java.io.File)

Example 15 with Duration

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

the class Append method appendImage.

/**
 * @param sourceNum
 * @param args
 */
private void appendImage(int sourceNum, String[] args) {
    if (args.length != 3) {
        getPrinter().println("usage: append <num-source> <duration>");
        return;
    }
    Duration duration = Duration.parse(args[1]);
    ConcatExecutable concatExecutable = getConcatExecutable();
    if (concatExecutable == null) {
        return;
    }
    GenericExecutable genericExecutable = new GenericExecutable(project);
    genericExecutable.add(new SourceSource(project, sourceNum));
}
Also used : ConcatExecutable(org.fagu.fmv.core.exec.executable.ConcatExecutable) Duration(org.fagu.fmv.utils.time.Duration) SourceSource(org.fagu.fmv.core.exec.source.SourceSource) GenericExecutable(org.fagu.fmv.core.exec.executable.GenericExecutable)

Aggregations

Duration (org.fagu.fmv.utils.time.Duration)20 Time (org.fagu.fmv.utils.time.Time)7 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)5 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)5 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)5 Test (org.junit.Test)5 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)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 TreeSet (java.util.TreeSet)2 ConcatExecutable (org.fagu.fmv.core.exec.executable.ConcatExecutable)2 SourceSource (org.fagu.fmv.core.exec.source.SourceSource)2 File (java.io.File)1