Search in sources :

Example 1 with Source

use of org.fagu.fmv.core.exec.Source in project fmv by f-agu.

the class CutExecutable method execute.

/**
 * @see org.fagu.fmv.core.exec.Executable#execute(java.io.File, Cache)
 */
@Override
public void execute(File toFile, Cache cache) throws IOException {
    Source source = getSource();
    Executable executable = getExecutable();
    if (executable == null && source == null) {
        return;
    }
    OutputInfos outputInfos = getProject().getOutputInfos();
    FFMPEGExecutorBuilder builder = FFUtils.builder(getProject());
    InputProcessor inputProcessor = null;
    if (executable != null) {
        File childExec = getProject().getFileCache().getFile(executable, cache);
        // executable.execute(childExec, cache);
        inputProcessor = builder.addMediaInputFile(childExec);
    } else if (source != null) {
        inputProcessor = (InputProcessor) source.createAndAdd(builder);
    } else {
        throw new IllegalArgumentException("Source or executable not defined !");
    }
    inputProcessor.timeSeek(startTime);
    // SetPTS videoSetPTS = new SetPTSVideo();
    // videoSetPTS.setStartAtFirstFrame();
    // FilterComplex videoSetPTSComplex = FilterComplex.createWith(videoSetPTS);
    // videoSetPTSComplex.addInput(inputProcessor, Type.VIDEO);
    // builder.add(videoSetPTSComplex);
    // 
    // SetPTS audioSetPTS = new SetPTSAudio();
    // audioSetPTS.setStartAtFirstFrame();
    // FilterComplex audioSetPTSComplex = FilterComplex.createWith(audioSetPTS);
    // audioSetPTSComplex.addInput(inputProcessor, Type.AUDIO);
    // builder.add(audioSetPTSComplex);
    BasicStreamMuxer muxer = BasicStreamMuxer.to(toFile, outputInfos.getFormat()).avoidNegativeTs(AvoidNegativeTs.MAKE_NON_NEGATIVE);
    OutputProcessor outputProcessor = builder.mux(muxer);
    outputProcessor.duration(duration);
    outputProcessor(outputProcessor, cache);
    FFExecutor<Object> executor = builder.build();
    executor.execute();
    if (cache == Cache.MAKE) {
        MovieMetadatas movieMetadatas = MovieMetadatas.with(toFile).extract();
        MovieMetadatasUtils.getDuration(movieMetadatas).ifPresent(this::setDuration);
    }
}
Also used : BasicStreamMuxer(org.fagu.fmv.ffmpeg.format.BasicStreamMuxer) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) OutputInfos(org.fagu.fmv.core.project.OutputInfos) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Executable(org.fagu.fmv.core.exec.Executable) File(java.io.File) Source(org.fagu.fmv.core.exec.Source)

Example 2 with Source

use of org.fagu.fmv.core.exec.Source 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 3 with Source

use of org.fagu.fmv.core.exec.Source in project fmv by f-agu.

the class ConcatFadeExecutable method execute.

/**
 * @see org.fagu.fmv.core.exec.Executable#execute()
 */
@Override
public void execute(File toFile, Cache cache) throws IOException {
    if (!hasChildren()) {
        return;
    }
    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);
        }
    }
    applyConcatFade(builder, inputProcessors, toFile, cache);
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) ArrayList(java.util.ArrayList) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Executable(org.fagu.fmv.core.exec.Executable) File(java.io.File) Source(org.fagu.fmv.core.exec.Source)

Example 4 with Source

use of org.fagu.fmv.core.exec.Source in project fmv by f-agu.

the class GenericExecutable method populateWithIdentifiables.

// *******************************************************
/**
 * @param toFile
 * @param cache
 * @param builder
 */
protected List<FilterInput> populateWithIdentifiables(File toFile, Cache cache, FFMPEGExecutorBuilder builder) {
    List<FilterInput> filterInputs = new ArrayList<>();
    // executable
    for (Executable executable : executables) {
        File file = getProject().getFileCache().getFile(executable, cache);
        filterInputs.add(builder.addMediaInputFile(file));
    }
    // source
    for (Source source : sources) {
        filterInputs.add(source.createAndAdd(builder));
    }
    // filters
    for (FilterExec filterExec : getFilters()) {
        Filter filter = filterExec.makeFilter(builder, cache);
        builder.filter(filter);
        if (filter instanceof FilterComplexBase) {
            filterInputs.add((FilterComplexBase) filter);
        }
    }
    return filterInputs;
}
Also used : FilterExec(org.fagu.fmv.core.exec.FilterExec) Filter(org.fagu.fmv.ffmpeg.filter.Filter) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) ArrayList(java.util.ArrayList) FilterComplexBase(org.fagu.fmv.ffmpeg.filter.FilterComplexBase) Executable(org.fagu.fmv.core.exec.Executable) File(java.io.File) Source(org.fagu.fmv.core.exec.Source)

Aggregations

File (java.io.File)4 Executable (org.fagu.fmv.core.exec.Executable)4 Source (org.fagu.fmv.core.exec.Source)4 ArrayList (java.util.ArrayList)3 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)3 FilterInput (org.fagu.fmv.ffmpeg.filter.FilterInput)3 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)3 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)2 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)2 FilterExec (org.fagu.fmv.core.exec.FilterExec)1 OutputInfos (org.fagu.fmv.core.project.OutputInfos)1 Filter (org.fagu.fmv.ffmpeg.filter.Filter)1 FilterComplexBase (org.fagu.fmv.ffmpeg.filter.FilterComplexBase)1 AudioMix (org.fagu.fmv.ffmpeg.filter.impl.AudioMix)1 BasicStreamMuxer (org.fagu.fmv.ffmpeg.format.BasicStreamMuxer)1 Map (org.fagu.fmv.ffmpeg.operation.Map)1 On (org.fagu.fmv.ffmpeg.operation.Map.On)1