Search in sources :

Example 1 with VolumeDetected

use of org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected in project fmv by f-agu.

the class MovieScriptConverter method convert.

/**
 * @see org.fagu.fmv.mymedia.classify.Converter#convert(org.fagu.fmv.media.Media,
 *      org.fagu.fmv.utils.file.FileFinder.InfosFile, java.io.File, org.fagu.fmv.mymedia.classify.ConverterListener)
 */
@Override
public void convert(Movie srcMedia, FileFinder<Movie>.InfosFile infosFile, File destFile, ConverterListener<Movie> listener) throws IOException {
    openScript();
    File srcFile = srcMedia.getFile();
    MovieMetadatas infos = srcMedia.getMetadatas();
    int audioFrequency = FFMpegUtils.minAudioSampleRate(infos, DEFAULT_AUDIO_SAMPLE_RATE);
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.hideBanner();
    builder.addMediaInputFile(srcFile).setMovieMetadatas(infos);
    Rotation rotation = rotateMap.get(srcFile.getName());
    if (rotation != null) {
        if (rotation != Rotation.R_0) {
            builder.filter(Rotate.create(rotation));
        }
    } else {
        builder.filter(AutoRotate.create(infos));
    }
    Size newSize = FFReducer.applyScaleIfNecessary(builder, infos, getMaxSize(), getScaleLogger(), rotation);
    writeLabel();
    script.println("rem " + (newSize.isLandscape() ? "landscape" : newSize.isPortrait() ? "portrait" : "square"));
    builder.filter(ResampleAudio.build().frequency(audioFrequency));
    Optional<VolumeDetected> findFirst = infosFile.getInfos().stream().filter(o -> o instanceof VolumeDetected).map(o -> (VolumeDetected) o).findFirst();
    if (findFirst.isPresent()) {
        VolumeDetected volumeDetected = findFirst.get();
        builder.filter(Volume.build().increaseToMax(volumeDetected));
    }
    File dest = new File(destFile.getParentFile(), FilenameUtils.getBaseName(destFile.getName()) + ".mp4");
    OutputProcessor outputProcessor = builder.addMediaOutputFile(dest);
    outputProcessor.qualityScale(0);
    Transpose.addMetadataRotate(outputProcessor, Rotation.R_0);
    outputProcessor.format("mp4");
    // outputProcessor.overwrite();
    FFExecutor<Object> executor = builder.build();
    try {
        script.println("if exist \"" + dest.getPath() + "\" goto :movie_" + currentVideo);
        script.println("echo.");
        script.println("echo Frame: " + infos.getVideoStream().countEstimateFrames().getAsInt());
        script.println(executor.getCommandLine());
        script.println();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : FFReducer(org.fagu.fmv.mymedia.reduce.FFReducer) HashMap(java.util.HashMap) Size(org.fagu.fmv.utils.media.Size) AutoRotate(org.fagu.fmv.ffmpeg.filter.impl.AutoRotate) ConverterListener(org.fagu.fmv.mymedia.classify.ConverterListener) Map(java.util.Map) VolumeDetected(org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) PrintStream(java.io.PrintStream) Rotation(org.fagu.fmv.utils.media.Rotation) Rotate(org.fagu.fmv.ffmpeg.filter.impl.Rotate) FileFinder(org.fagu.fmv.utils.file.FileFinder) FFMpegUtils(org.fagu.fmv.ffmpeg.FFMpegUtils) FFExecutor(org.fagu.fmv.ffmpeg.executor.FFExecutor) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) IOException(java.io.IOException) File(java.io.File) Volume(org.fagu.fmv.ffmpeg.filter.impl.Volume) Transpose(org.fagu.fmv.ffmpeg.filter.impl.Transpose) Logger(org.fagu.fmv.mymedia.logger.Logger) Optional(java.util.Optional) ResampleAudio(org.fagu.fmv.ffmpeg.filter.impl.ResampleAudio) Converter(org.fagu.fmv.mymedia.classify.Converter) FilenameUtils(org.apache.commons.io.FilenameUtils) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Size(org.fagu.fmv.utils.media.Size) IOException(java.io.IOException) Rotation(org.fagu.fmv.utils.media.Rotation) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) File(java.io.File) VolumeDetected(org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected)

Example 2 with VolumeDetected

use of org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected in project fmv by f-agu.

the class FFReducer method createVolumeDetectFFExecListener.

/**
 * @param logger
 * @param volumeDetect
 * @return
 */
private FFExecListener createVolumeDetectFFExecListener(Logger logger, VolumeDetect volumeDetect) {
    return new FFExecListener() {

        /**
         * @see org.fagu.fmv.soft.exec.FMVExecListener#eventPostExecute(org.fagu.fmv.soft.exec.FMVExecutor,
         *      org.apache.commons.exec.CommandLine, java.util.Map, org.apache.commons.exec.ExecuteResultHandler)
         */
        @Override
        public void eventPostExecute(FMVExecutor fmvExecutor, CommandLine command, Map environment, ExecuteResultHandler handler) {
            if (volumeDetect.isDetected()) {
                VolumeDetected detected = volumeDetect.getDetected();
                logger.log("VolumeDetect: nb_sample= " + detected.countSample());
                logger.log("VolumeDetect: max=       " + detected.getMax());
                logger.log("VolumeDetect: mean=      " + detected.getMean());
                logger.log("VolumeDetect: histogram= " + detected.getHistogram());
                logger.log("VolumeDetect: Add volume filter: " + detected.toMaxVolume());
            } else {
                logger.log("volume not detected");
            }
        }
    };
}
Also used : FFExecListener(org.fagu.fmv.ffmpeg.executor.FFExecListener) ExecuteResultHandler(org.apache.commons.exec.ExecuteResultHandler) CommandLine(org.apache.commons.exec.CommandLine) Map(java.util.Map) FMVExecutor(org.fagu.fmv.soft.exec.FMVExecutor) VolumeDetected(org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected)

Example 3 with VolumeDetected

use of org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected in project fmv by f-agu.

the class FFHelper method audioVolumeAdjustToMax.

/**
 * @param inFile
 * @param outFile
 * @throws IOException
 */
public static void audioVolumeAdjustToMax(File inFile, File outFile) throws IOException {
    VolumeDetected volumeDetected = audioVolumeDetect(inFile);
    System.out.println(volumeDetected);
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.addMediaInputFile(inFile);
    Volume volume = Volume.build().increaseToMax(volumeDetected);
    builder.filter(volume);
    builder.addMediaOutputFile(outFile).videoCodecCopy().overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Volume(org.fagu.fmv.ffmpeg.filter.impl.Volume) VolumeDetected(org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected)

Example 4 with VolumeDetected

use of org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected in project fmv by f-agu.

the class VolumeInfoFile method toLine.

/**
 * @see org.fagu.fmv.mymedia.file.InfoFile#toLine(org.fagu.fmv.utils.file.FileFinder.FileFound,
 *      org.fagu.fmv.media.Media)
 */
@Override
public String toLine(FileFound fileFound, FileFinder<Media>.InfosFile infosFile) throws IOException {
    Media main = infosFile.getMain();
    MovieMetadatas metadatas = (MovieMetadatas) main.getMetadatas();
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.addMediaInputFile(fileFound.getFileFound());
    VolumeDetect volumeDetect = VolumeDetect.build();
    builder.filter(volumeDetect);
    builder.addMediaOutput(NullMuxer.build()).overwrite();
    FFExecutor<Object> executor = builder.build();
    if (metadatas != null) {
        OptionalInt countEstimateFrames = metadatas.getVideoStream().countEstimateFrames();
        Progress progress = executor.getProgress();
        if (countEstimateFrames.isPresent() && progress != null) {
            try (TextProgressBar bar = FFMpegProgressBar.with(progress).byFrame(countEstimateFrames.getAsInt()).build().makeBar("Detect volume")) {
                executor.execute();
            }
            System.out.println();
        }
    } else {
        executor.execute();
    }
    VolumeDetected volumeDetected = volumeDetect.getDetected();
    return volumeDetected.toString();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Progress(org.fagu.fmv.ffmpeg.operation.Progress) VolumeDetect(org.fagu.fmv.ffmpeg.filter.impl.VolumeDetect) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) Media(org.fagu.fmv.media.Media) OptionalInt(java.util.OptionalInt) TextProgressBar(org.fagu.fmv.textprogressbar.TextProgressBar) VolumeDetected(org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected)

Aggregations

VolumeDetected (org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected)4 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)3 Map (java.util.Map)2 Volume (org.fagu.fmv.ffmpeg.filter.impl.Volume)2 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)2 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 CommandLine (org.apache.commons.exec.CommandLine)1 ExecuteResultHandler (org.apache.commons.exec.ExecuteResultHandler)1 FilenameUtils (org.apache.commons.io.FilenameUtils)1 FFMpegUtils (org.fagu.fmv.ffmpeg.FFMpegUtils)1 FFExecListener (org.fagu.fmv.ffmpeg.executor.FFExecListener)1 FFExecutor (org.fagu.fmv.ffmpeg.executor.FFExecutor)1 AutoRotate (org.fagu.fmv.ffmpeg.filter.impl.AutoRotate)1 ResampleAudio (org.fagu.fmv.ffmpeg.filter.impl.ResampleAudio)1 Rotate (org.fagu.fmv.ffmpeg.filter.impl.Rotate)1