Search in sources :

Example 1 with FMVExecutor

use of org.fagu.fmv.soft.exec.FMVExecutor 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 FMVExecutor

use of org.fagu.fmv.soft.exec.FMVExecutor 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 FMVExecutor

use of org.fagu.fmv.soft.exec.FMVExecutor in project fmv by f-agu.

the class ExecSoftFoundFactory method create.

/**
 * @see org.fagu.fmv.soft.find.SoftFoundFactory#create(java.io.File, Locator, SoftPolicy)
 */
@Override
public final SoftFound create(File file, Locator locator, SoftPolicy softPolicy) throws IOException {
    Parser parser = parserFactory.create(file, softPolicy);
    CommandLine commandLine = FMVCommandLine.create(file, parameters);
    String cmdLineStr = CommandLineUtils.toLine(commandLine);
    List<String> readLineList = new ArrayList<>();
    BufferedReadLine bufferedReadLine = new BufferedReadLine(readLineList);
    FMVExecutor executor = executorFactory.create(file, parser, bufferedReadLine);
    try {
        int exitValue = executor.execute(commandLine);
        SoftFound softFound = parser.closeAndParse(cmdLineStr, exitValue);
        if (locator != null && softFound != null) {
            softFound.setLocalizedBy(locator.toString());
        }
        return softFound;
    } catch (IOException e) {
        return parser.closeAndParse(e, cmdLineStr, readLineList);
    }
}
Also used : BufferedReadLine(org.fagu.fmv.soft.exec.BufferedReadLine) FMVCommandLine(org.fagu.fmv.soft.exec.FMVCommandLine) CommandLine(org.apache.commons.exec.CommandLine) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FMVExecutor(org.fagu.fmv.soft.exec.FMVExecutor)

Example 4 with FMVExecutor

use of org.fagu.fmv.soft.exec.FMVExecutor in project fmv by f-agu.

the class SoftExecutor method executeInBackground.

/**
 * @param executorService
 * @return
 * @throws IOException
 */
public Future<SoftExecutor.Executed> executeInBackground(ExecutorService executorService) throws IOException {
    return execute((fmvExecutor, commandLine, execListener, readLineList) -> {
        final String cmdLineStr = CommandLineUtils.toLine(commandLine);
        final AtomicLong startTime = new AtomicLong();
        final AtomicLong time = new AtomicLong();
        final PIDProcessOperator pidProcessOperator = new PIDProcessOperator();
        fmvExecutor.addProcessOperator(pidProcessOperator);
        return new WrapFuture<>(fmvExecutor.executeAsynchronous(geExecuteDelegate(), commandLine, executorService, // before
        () -> {
            startTime.set(System.currentTimeMillis());
            execListener.eventExecuting(cmdLineStr);
        }, // after
        exitValue -> {
            time.set(System.currentTimeMillis() - startTime.get());
            execListener.eventExecuted(cmdLineStr, exitValue, time.get());
        }, // exception
        exception -> {
            if (exception instanceof ExecuteException) {
                ExecuteException e = (ExecuteException) exception;
                FMVExecuteException fmvExecuteException = new FMVExecuteException(softProvider.getExceptionKnownAnalyzerClass(), e, cmdLineStr, readLineList);
                execListener.eventException(fmvExecuteException);
                ExceptionKnownAnalyzers.doOrThrows(softProvider.getExceptionKnownAnalyzerClass(), fmvExecuteException, exceptionKnowConsumer, exceptionConsumer);
            }
        }), exitValue -> new Executed(pidProcessOperator.getPID(), exitValue, time.get()));
    });
}
Also used : PIDProcessOperator(org.fagu.fmv.soft.exec.PIDProcessOperator) FMVCommandLine(org.fagu.fmv.soft.exec.FMVCommandLine) HashMap(java.util.HashMap) CommandLine(org.apache.commons.exec.CommandLine) PIDProcessOperator(org.fagu.fmv.soft.exec.PIDProcessOperator) ArrayList(java.util.ArrayList) SoftProvider(org.fagu.fmv.soft.find.SoftProvider) OptionalLong(java.util.OptionalLong) Future(java.util.concurrent.Future) ExceptionKnownConsumer(org.fagu.fmv.soft.exec.exception.ExceptionKnownConsumer) WrapFuture(org.fagu.fmv.soft.exec.WrapFuture) ExceptionConsumer(org.fagu.fmv.soft.exec.exception.ExceptionConsumer) Duration(java.time.Duration) Map(java.util.Map) LookReader(org.fagu.fmv.soft.exec.LookReader) ExecuteException(org.apache.commons.exec.ExecuteException) ExecutorService(java.util.concurrent.ExecutorService) CommandLineUtils(org.fagu.fmv.soft.exec.CommandLineUtils) FMVExecutor(org.fagu.fmv.soft.exec.FMVExecutor) ReadLine(org.fagu.fmv.soft.exec.ReadLine) ExceptionKnownAnalyzers(org.fagu.fmv.soft.exec.exception.ExceptionKnownAnalyzers) IOException(java.io.IOException) FMVExecuteException(org.fagu.fmv.soft.exec.exception.FMVExecuteException) ExecHelper(org.fagu.fmv.soft.exec.ExecHelper) File(java.io.File) Objects(java.util.Objects) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) BufferedReadLine(org.fagu.fmv.soft.exec.BufferedReadLine) Proxifier(org.fagu.fmv.soft.utils.Proxifier) Collections(java.util.Collections) AtomicLong(java.util.concurrent.atomic.AtomicLong) FMVExecuteException(org.fagu.fmv.soft.exec.exception.FMVExecuteException) WrapFuture(org.fagu.fmv.soft.exec.WrapFuture) ExecuteException(org.apache.commons.exec.ExecuteException) FMVExecuteException(org.fagu.fmv.soft.exec.exception.FMVExecuteException)

Example 5 with FMVExecutor

use of org.fagu.fmv.soft.exec.FMVExecutor in project fmv by f-agu.

the class SoftExecutor method execute.

// -------------------------------------------------------------
/**
 * @param executorService
 * @return
 * @throws IOException
 */
private <R> R execute(SoftExecutor.ForExec<R> forExec) throws IOException {
    ExecListener execListener = new Proxifier<>(ExecListener.class).addAll(execListeners).proxify();
    CommandLine commandLine = getCommandLine();
    String cmdLineStr = CommandLineUtils.toLine(commandLine);
    execListener.eventPrepare(cmdLineStr);
    List<String> readLineList = new ArrayList<>();
    ReadLine bufferedReadLine = new BufferedReadLine(readLineList);
    FMVExecutor fmvExecutor = createFMVExecutor(execFile.getParentFile(), bufferedReadLine);
    applyCustomizeExecutor(fmvExecutor);
    return forExec.exec(fmvExecutor, commandLine, execListener, readLineList);
}
Also used : BufferedReadLine(org.fagu.fmv.soft.exec.BufferedReadLine) FMVCommandLine(org.fagu.fmv.soft.exec.FMVCommandLine) CommandLine(org.apache.commons.exec.CommandLine) Proxifier(org.fagu.fmv.soft.utils.Proxifier) ArrayList(java.util.ArrayList) ReadLine(org.fagu.fmv.soft.exec.ReadLine) BufferedReadLine(org.fagu.fmv.soft.exec.BufferedReadLine) FMVExecutor(org.fagu.fmv.soft.exec.FMVExecutor)

Aggregations

CommandLine (org.apache.commons.exec.CommandLine)5 FMVExecutor (org.fagu.fmv.soft.exec.FMVExecutor)5 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)3 Map (java.util.Map)3 File (java.io.File)2 List (java.util.List)2 ExecuteResultHandler (org.apache.commons.exec.ExecuteResultHandler)2 FFExecListener (org.fagu.fmv.ffmpeg.executor.FFExecListener)2 VolumeDetected (org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected)2 BufferedReadLine (org.fagu.fmv.soft.exec.BufferedReadLine)2 FMVCommandLine (org.fagu.fmv.soft.exec.FMVCommandLine)2 ReadLine (org.fagu.fmv.soft.exec.ReadLine)2 Proxifier (org.fagu.fmv.soft.utils.Proxifier)2 Duration (java.time.Duration)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Objects (java.util.Objects)1