use of org.fagu.fmv.utils.media.Size in project fmv by f-agu.
the class FFReducer method applyScaleIfNecessary.
/**
* @param builder
* @param movieMetadatas
* @param maxSize
* @param logger
* @param rotation
* @return
*/
public static Size applyScaleIfNecessary(FFMPEGExecutorBuilder builder, MovieMetadatas movieMetadatas, Size maxSize, Logger logger, Rotation inRotation) {
VideoStream videoStream = movieMetadatas.getVideoStream();
Size size = videoStream.size();
Rotation rotation = inRotation;
if (rotation == null) {
rotation = videoStream.rotate();
}
if (rotation != null) {
size = rotation.resize(size);
}
if (size.getWidth() <= maxSize.getWidth() && size.getHeight() <= maxSize.getHeight()) {
return size;
}
StringBuilder log = new StringBuilder();
log.append("Need to resize ").append(size);
if (rotation != null) {
log.append(" (rotation of ").append(rotation.getValue()).append(')');
}
size = size.fitAndKeepRatioTo(maxSize);
if (rotation != null && !AutoRotate.isAutoRotateObsolete()) {
size = rotation.resize(size);
}
// fix [libx264 @ 037f8b00] height not divisible by 2 (1078x607)
size = Libx264NotDisibleBy2FFExecFallback.resize(size);
log.append(" to under ").append(maxSize).append(": ").append(size);
logger.log(log.toString());
// .forceOriginalAspectRatio(ForceOriginalAspectRatio.DECREASE)
builder.filter(Scale.to(size, ScaleMode.fitToBoxKeepAspectRatio()));
return size;
}
use of org.fagu.fmv.utils.media.Size 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());
}
Aggregations