Search in sources :

Example 1 with CropDetection

use of org.fagu.fmv.ffmpeg.filter.impl.CropDetection 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)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)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 CommandLine (org.apache.commons.exec.CommandLine)1 ExecuteResultHandler (org.apache.commons.exec.ExecuteResultHandler)1 FilenameUtils (org.apache.commons.io.FilenameUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Decoders (org.fagu.fmv.ffmpeg.coder.Decoders)1 H264 (org.fagu.fmv.ffmpeg.coder.H264)1 FFExecFallback (org.fagu.fmv.ffmpeg.executor.FFExecFallback)1 FFExecListener (org.fagu.fmv.ffmpeg.executor.FFExecListener)1