Search in sources :

Example 11 with Size

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;
}
Also used : Size(org.fagu.fmv.utils.media.Size) CropSize(org.fagu.fmv.ffmpeg.filter.impl.CropDetection.CropSize) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) Rotation(org.fagu.fmv.utils.media.Rotation)

Example 12 with 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());
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) Size(org.fagu.fmv.utils.media.Size) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) Logger(org.fagu.fmv.mymedia.logger.Logger) File(java.io.File) Rotation(org.fagu.fmv.utils.media.Rotation)

Aggregations

Size (org.fagu.fmv.utils.media.Size)12 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)7 File (java.io.File)5 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)5 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)5 IOException (java.io.IOException)4 Rotation (org.fagu.fmv.utils.media.Rotation)4 OutputInfos (org.fagu.fmv.core.project.OutputInfos)3 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)3 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)3 Logger (org.fagu.fmv.mymedia.logger.Logger)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Optional (java.util.Optional)2 OptionalInt (java.util.OptionalInt)2 FilenameUtils (org.apache.commons.io.FilenameUtils)2 FFExecutor (org.fagu.fmv.ffmpeg.executor.FFExecutor)2 AutoRotate (org.fagu.fmv.ffmpeg.filter.impl.AutoRotate)2 ResampleAudio (org.fagu.fmv.ffmpeg.filter.impl.ResampleAudio)2 Scale (org.fagu.fmv.ffmpeg.filter.impl.Scale)2