use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.
the class PreparedImages method makeVideo.
/**
* @param imageFrameRate
* @param destVideo
* @param videoFrameRate
* @throws IOException
*/
public void makeVideo(FrameRate imageFrameRate, File destVideo, FPS videoFrameRate) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
// input
File srcFiles = new File(parentFolder, "img_%0" + countLengthNumber() + "d." + extension);
builder.addMediaInput(Image2Demuxer.from(srcFiles).frameRate(imageFrameRate));
FilterComplex filter = FilterComplex.create(org.fagu.fmv.ffmpeg.filter.impl.FrameRate.to(videoFrameRate), Format.with(PixelFormat.YUV420P));
builder.filter(filter);
OutputProcessor outputProcessor = builder.addMediaOutputFile(destVideo);
outputProcessor.codec(H264.findRecommanded());
outputProcessor.overwrite();
outputProcessor.map().allStreams().input(filter);
FFExecutor<Object> executor = builder.build();
System.out.println(executor.getCommandLine());
int countEstimateFrames = (int) (files.size() * videoFrameRate.countFrameBySeconds() * imageFrameRate.invert().doubleValue());
Progress progress = executor.getProgress();
if (progress != null) {
textProgressBar = FFMpegProgressBar.with(progress).byFrame(countEstimateFrames).build().makeBar("");
}
executor.execute();
}
use of org.fagu.fmv.ffmpeg.operation.OutputProcessor 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;
}
use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.
the class Rotate method main.
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
File srcFile = new File("D:\\tmp\\Auvergne\\phone-vv\\VID_20170813_183349.mp4");
Rotation rotation = Rotation.R_90;
File dest = new File(srcFile.getParentFile(), FilenameUtils.getBaseName(srcFile.getName()) + "-rotate-" + rotation + ".mp4");
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
MovieMetadatas infos = builder.addMediaInputFile(srcFile).getMovieMetadatas();
int audioFrequency = FFMpegUtils.minAudioSampleRate(infos, DEFAULT_AUDIO_SAMPLE_RATE);
if (rotation != null && rotation != Rotation.R_0) {
builder.filter(org.fagu.fmv.ffmpeg.filter.impl.Rotate.create(rotation));
}
Logger logger = Loggers.systemOut();
Size newSize = FFReducer.applyScaleIfNecessary(builder, infos, MAX_SIZE, logger, rotation);
logger.log((newSize.isLandscape() ? "landscape" : newSize.isPortrait() ? "portrait" : "square"));
builder.filter(ResampleAudio.build().frequency(audioFrequency));
OutputProcessor outputProcessor = builder.addMediaOutputFile(dest);
outputProcessor.qualityScale(0);
Transpose.addMetadataRotate(outputProcessor, Rotation.R_0);
outputProcessor.format("mp4");
FFExecutor<Object> executor = builder.build();
logger.log(executor.getCommandLine());
}
use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.
the class FFReducer method reduceVideo.
/**
* @param metadatas
* @param srcFile
* @param movieMetadatas
* @param destFile
* @param consolePrefixMessage
* @param logger
* @throws IOException
*/
public void reduceVideo(MovieMetadatas metadatas, File srcFile, MovieMetadatas movieMetadatas, File destFile, String consolePrefixMessage, Logger logger) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
InputProcessor inputProcessor = builder.addMediaInputFile(srcFile);
builder.filter(AutoRotate.create(movieMetadatas));
org.fagu.fmv.mymedia.reduce.FFReducer.applyScaleIfNecessary(builder, movieMetadatas, Size.HD720, logger);
MovieMetadatas videoMetadatas = inputProcessor.getMovieMetadatas();
Collection<AudioStream> audioStreams = StreamOrder.sort(videoMetadatas.getAudioStreams());
OutputProcessor outputProcessor = builder.addMediaOutputFile(destFile);
outputProcessor.qualityScale(0);
// video
for (Stream stream : videoMetadatas.getVideoStreams()) {
logger.log("map[" + stream.index() + "] video: " + stream);
outputProcessor.map().streams(stream).input(inputProcessor);
}
// audio
for (Stream stream : audioStreams) {
logger.log("map[" + stream.index() + "] audio: " + stream);
outputProcessor.map().streams(stream).input(inputProcessor);
}
// subtitle
Collection<SubtitleStream> subtitleStreams = StreamOrder.sort(videoMetadatas.getSubtitleStreams());
for (Stream stream : subtitleStreams) {
logger.log("map[" + stream.index() + "] subtitle: " + stream);
outputProcessor.map().streams(stream).input(inputProcessor);
}
// -------------------------- codec -------------------------
outputProcessor.codec(H264.findRecommanded().strict(Strict.EXPERIMENTAL).quality(23));
// subtitle
if (videoMetadatas.contains(Type.AUDIO)) {
outputProcessor.codecCopy(Type.AUDIO);
}
// subtitle
if (videoMetadatas.contains(Type.SUBTITLE)) {
outputProcessor.codecCopy(Type.SUBTITLE);
}
outputProcessor.overwrite();
FFExecutor<Object> executor = builder.build();
executor.addListener(org.fagu.fmv.mymedia.reduce.FFReducer.createLogFFExecListener(logger));
OptionalInt countEstimateFrames = metadatas.getVideoStream().countEstimateFrames();
Progress progress = executor.getProgress();
if (countEstimateFrames.isPresent() && progress != null) {
textProgressBar = FFMpegProgressBar.with(progress).byFrame(countEstimateFrames.getAsInt()).fileSize(srcFile.length()).build().makeBar(consolePrefixMessage);
} else {
StringJoiner joiner = new StringJoiner(", ");
if (progress == null) {
joiner.add("progress not found");
}
if (!countEstimateFrames.isPresent()) {
joiner.add("nb frames nout found");
}
logger.log("No progress bar: " + joiner.toString());
}
executor.execute();
}
use of org.fagu.fmv.ffmpeg.operation.OutputProcessor in project fmv by f-agu.
the class GenericExecutable 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());
populateWithIdentifiables(toFile, cache, builder);
OutputProcessor outputProcessor = outputProcessor(builder, toFile, cache);
ObjectInvoker.invoke(outputProcessor, attributeMap);
fixOutput(outputProcessor);
FFExecutor<Object> executor = builder.build();
executor.execute();
}
Aggregations