Search in sources :

Example 1 with FFExecListener

use of org.fagu.fmv.ffmpeg.executor.FFExecListener in project fmv by f-agu.

the class FFReducer method createCropDetectFFExecListener.

/**
 * @param logger
 * @param cropDetect
 * @param videoMetadatas
 * @return
 */
private FFExecListener createCropDetectFFExecListener(Logger logger, CropDetect cropDetect, MovieMetadatas videoMetadatas) {
    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) {
            CropDetection cropDetection = cropDetect.getCropSizeDetected();
            SortedSet<CropSize> orderedCropSizes = cropDetection.getOrderedCropSizes();
            if (!orderedCropSizes.isEmpty()) {
                CropSize first = orderedCropSizes.first();
                Size size = first.toSize();
                if (!videoMetadatas.getVideoStreams().stream().anyMatch(s -> size.equals(s.size()))) {
                    logger.log("CropDetect: " + cropDetection.getTotalCount() + " lines parsed");
                    orderedCropSizes.stream().limit(10).forEach(cs -> logger.log("CropDetect: " + cs));
                    logger.log("CropDetect: Add crop filter: " + first.toCrop());
                }
            }
        }
    };
}
Also used : FFExecListener(org.fagu.fmv.ffmpeg.executor.FFExecListener) Arrays(java.util.Arrays) H264(org.fagu.fmv.ffmpeg.coder.H264) SortedSet(java.util.SortedSet) Stream(org.fagu.fmv.ffmpeg.metadatas.Stream) Duration(org.fagu.fmv.utils.time.Duration) CommandLine(org.apache.commons.exec.CommandLine) StringUtils(org.apache.commons.lang3.StringUtils) Decoders(org.fagu.fmv.ffmpeg.coder.Decoders) Size(org.fagu.fmv.utils.media.Size) ScaleMode(org.fagu.fmv.ffmpeg.filter.impl.ScaleMode) Map(java.util.Map) Formats(org.fagu.fmv.ffmpeg.format.Formats) VolumeDetected(org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected) FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) CommandLineUtils(org.fagu.fmv.soft.exec.CommandLineUtils) Rotation(org.fagu.fmv.utils.media.Rotation) Scale(org.fagu.fmv.ffmpeg.filter.impl.Scale) SubtitleStream(org.fagu.fmv.ffmpeg.metadatas.SubtitleStream) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Collection(java.util.Collection) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) List(java.util.List) Optional(java.util.Optional) ResampleAudio(org.fagu.fmv.ffmpeg.filter.impl.ResampleAudio) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) TextProgressBar(org.fagu.fmv.textprogressbar.TextProgressBar) Libx264NotDisibleBy2FFExecFallback(org.fagu.fmv.ffmpeg.executor.fallback.Libx264NotDisibleBy2FFExecFallback) FilenameUtils(org.apache.commons.io.FilenameUtils) FFExecFallback(org.fagu.fmv.ffmpeg.executor.FFExecFallback) CropDetection(org.fagu.fmv.ffmpeg.filter.impl.CropDetection) Strict(org.fagu.fmv.ffmpeg.flags.Strict) FFExecListener(org.fagu.fmv.ffmpeg.executor.FFExecListener) OptionalInt(java.util.OptionalInt) ArrayList(java.util.ArrayList) AutoRotate(org.fagu.fmv.ffmpeg.filter.impl.AutoRotate) StreamOrder(org.fagu.fmv.mymedia.movie.StreamOrder) StringTokenizer(java.util.StringTokenizer) CropSize(org.fagu.fmv.ffmpeg.filter.impl.CropDetection.CropSize) Type(org.fagu.fmv.ffmpeg.operation.Type) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Loggers(org.fagu.fmv.mymedia.logger.Loggers) FFExecutor(org.fagu.fmv.ffmpeg.executor.FFExecutor) FMVExecutor(org.fagu.fmv.soft.exec.FMVExecutor) IOException(java.io.IOException) Progress(org.fagu.fmv.ffmpeg.operation.Progress) FrameRate(org.fagu.fmv.ffmpeg.utils.FrameRate) FMVExecuteException(org.fagu.fmv.soft.exec.exception.FMVExecuteException) ExecuteResultHandler(org.apache.commons.exec.ExecuteResultHandler) CropDetect(org.fagu.fmv.ffmpeg.filter.impl.CropDetect) File(java.io.File) AudioStream(org.fagu.fmv.ffmpeg.metadatas.AudioStream) FFMpegProgressBar(org.fagu.fmv.ffmpeg.progressbar.FFMpegProgressBar) Logger(org.fagu.fmv.mymedia.logger.Logger) StringJoiner(java.util.StringJoiner) VolumeDetect(org.fagu.fmv.ffmpeg.filter.impl.VolumeDetect) ExecuteResultHandler(org.apache.commons.exec.ExecuteResultHandler) CropSize(org.fagu.fmv.ffmpeg.filter.impl.CropDetection.CropSize) CommandLine(org.apache.commons.exec.CommandLine) Size(org.fagu.fmv.utils.media.Size) CropSize(org.fagu.fmv.ffmpeg.filter.impl.CropDetection.CropSize) Map(java.util.Map) CropDetection(org.fagu.fmv.ffmpeg.filter.impl.CropDetection) FMVExecutor(org.fagu.fmv.soft.exec.FMVExecutor)

Example 2 with FFExecListener

use of org.fagu.fmv.ffmpeg.executor.FFExecListener 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 FFExecListener

use of org.fagu.fmv.ffmpeg.executor.FFExecListener in project fmv by f-agu.

the class FFHelper method resize.

/**
 * @param inFile
 * @param size
 * @param outFile
 * @throws IOException
 */
public static void resize(File inFile, Size size, File outFile) throws IOException {
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
    builder.filter(Scale.to(size, ScaleMode.fitToBoxKeepAspectRatio()));
    builder.mux(MP4Muxer.to(outFile)).qualityScaleVideo(0).codecCopy(Type.AUDIO).codecCopy(Type.SUBTITLE).mapAllStreams(inputProcessor).overwrite();
    FFExecutor<Object> executor = builder.build();
    executor.addListener(new FFExecListener() {

        @Override
        public void eventExecFailed(IOException e, CommandLine command) {
            System.out.println("FAILED: " + CommandLineUtils.toLine(command));
        }

        @Override
        public void eventPreExecFallbacks(CommandLine command, Collection<FFExecFallback> fallbacks) {
            System.out.println("With fallback: " + fallbacks);
            System.out.println(" -->: " + CommandLineUtils.toLine(command));
        }
    });
    executor.execute();
}
Also used : FFExecListener(org.fagu.fmv.ffmpeg.executor.FFExecListener) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) CommandLine(org.apache.commons.exec.CommandLine) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) IOException(java.io.IOException) FFExecFallback(org.fagu.fmv.ffmpeg.executor.FFExecFallback)

Aggregations

CommandLine (org.apache.commons.exec.CommandLine)3 FFExecListener (org.fagu.fmv.ffmpeg.executor.FFExecListener)3 IOException (java.io.IOException)2 Map (java.util.Map)2 ExecuteResultHandler (org.apache.commons.exec.ExecuteResultHandler)2 FFExecFallback (org.fagu.fmv.ffmpeg.executor.FFExecFallback)2 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)2 VolumeDetected (org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected)2 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)2 FMVExecutor (org.fagu.fmv.soft.exec.FMVExecutor)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 SortedSet (java.util.SortedSet)1 StringJoiner (java.util.StringJoiner)1 StringTokenizer (java.util.StringTokenizer)1