use of org.fagu.fmv.ffmpeg.filter.impl.AudioMix in project fmv by f-agu.
the class AudioMixFilterExec method addInputIntoFilter.
/**
* @see org.fagu.fmv.core.exec.filter.GenericFilterExec#addInputIntoFilter(org.fagu.fmv.ffmpeg.filter.FilterComplexBase,
* org.fagu.fmv.ffmpeg.filter.FilterInput, java.util.Set)
*/
@Override
protected void addInputIntoFilter(FilterComplexBase filterComplexBase, FilterInput filterInput, Set<Type> undeclaredTypes) {
if (filterInput.contains(Type.AUDIO) && !filterInput.contains(Type.VIDEO)) {
// only audio
AudioMix audioMix = (AudioMix) filterComplexBase;
audioMix.addInput(filterInput, audioStart);
removeUndeclaredTypes(undeclaredTypes, filterInput);
} else {
super.addInputIntoFilter(filterComplexBase, filterInput, undeclaredTypes);
}
}
use of org.fagu.fmv.ffmpeg.filter.impl.AudioMix 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();
}
use of org.fagu.fmv.ffmpeg.filter.impl.AudioMix in project fmv by f-agu.
the class FFHelper method mixAudio.
/**
* @param inVideoFile
* @param inAudioFile
* @param outFile
* @throws IOException
*/
public static void mixAudio(File inVideoFile, File inAudioFile, File outFile, Time audioStart) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
InputProcessor videoInputProcessor = builder.addMediaInputFile(inVideoFile);
InputProcessor audioInputProcessor = builder.addMediaInputFile(inAudioFile);
// audioInputProcessor.timeSeek(audioStart);
AudioMix audioMix = AudioMix.build();
audioMix.addInput(audioInputProcessor, audioStart);
audioMix.addInput(videoInputProcessor);
audioMix.duration(MixAudioDuration.SHORTEST);
builder.filter(audioMix);
builder.addMediaOutputFile(outFile).videoCodecCopy().overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
Aggregations