use of org.fagu.fmv.ffmpeg.operation.OutputProcessor 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.operation.OutputProcessor in project fmv by f-agu.
the class FFHelper method addFrenchAudioStream.
/**
* @param videoFile
* @param frenchAudioToAddFile
* @param outFile
* @throws Exception
*/
public static void addFrenchAudioStream(File videoFile, File frenchAudioToAddFile, File outFile) throws Exception {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
InputProcessor videoInput = builder.addMediaInputFile(videoFile);
int countAudioStreams = videoInput.getMovieMetadatas().getAudioStreams().size();
InputProcessor audioInput = builder.addMediaInputFile(frenchAudioToAddFile);
OutputProcessor outputProcessor = builder.addMediaOutputFile(outFile);
outputProcessor.map().allStreams().input(videoInput).input(audioInput);
outputProcessor.codecCopy(Type.VIDEO).shortest().overwrite().metadataStream(Type.AUDIO, countAudioStreams, "language", "fra");
FFExecutor<Object> executor = builder.build();
executor.execute();
}
use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.
the class FFHelper method m4aToMp3.
/**
* @param inFile
* @param outFile
* @throws IOException
*/
public static void m4aToMp3(File inFile, File outFile) throws IOException {
final int SAMPLE_RATE = 44100;
final String bitRate = "128k";
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
MovieMetadatas movieMetadatas = inputProcessor.getMovieMetadatas();
int sampleRate = Math.min(movieMetadatas.getAudioStream().sampleRate().orElse(SAMPLE_RATE), SAMPLE_RATE);
FilterComplex filter = FilterComplex.create(ResampleAudio.build().frequency(sampleRate));
builder.filter(filter);
OutputProcessor outputProcessor = builder.addMediaOutputFile(outFile).audioChannel(2).audioBitRate(bitRate).format("mp3").overwrite();
outputProcessor.map().allStreams().input(filter);
FFExecutor<Object> executor = builder.build();
System.out.println(executor.getCommandLine());
// Integer numberOfFrames =
// movieMetadatas.getAudioStream().countEstimateFrames();
// prepareProgressBar(numberOfFrames, executor, consolePrefixMessage);
// executor.execute();
}
use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.
the class FFMPEGExecutorBuilder method addMediaOutput.
/**
* @param output
* @return
*/
public OutputProcessor addMediaOutput(MediaOutput output) {
if (output instanceof Muxer) {
return mux((Muxer<?>) output);
}
Processor<?> processor = defaultFFMPEGOperation.getProcessor(output);
if (processor != null && !(processor instanceof OutputProcessor)) {
throw new IllegalArgumentException("Already defined: " + output);
}
OutputParameters outputParameters = defaultFFMPEGOperation.getOutputParameters();
return outputParameters.addOutput(output);
}
use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.
the class FFMPEGExecutorBuilder method mux.
/**
* @param muxer
* @return
*/
public OutputProcessor mux(Muxer<?> muxer) {
MediaOutput mediaOutput = muxer.getMediaOutput();
OutputProcessor outputProcessor = addMediaOutput(mediaOutput);
muxer.eventAdded(outputProcessor, mediaOutput);
outputProcessor.format(muxer.name());
return outputProcessor;
}
Aggregations