Search in sources :

Example 1 with DefaultExecuteResultHandler

use of org.apache.commons.exec.DefaultExecuteResultHandler in project ddf by codice.

the class VideoThumbnailPlugin method generateThumbnailsWithoutDuration.

private void generateThumbnailsWithoutDuration(final String videoFilePath) throws IOException, InterruptedException {
    final CommandLine command = getFFmpegCreateThumbnailCommand(videoFilePath, getThumbnailFilePath(), null, THUMBNAIL_COUNT);
    final DefaultExecuteResultHandler resultHandler = executeFFmpeg(command, 15, DEV_NULL);
    resultHandler.waitFor();
    if (resultHandler.getException() != null) {
        throw resultHandler.getException();
    }
}
Also used : CommandLine(org.apache.commons.exec.CommandLine) DefaultExecuteResultHandler(org.apache.commons.exec.DefaultExecuteResultHandler)

Example 2 with DefaultExecuteResultHandler

use of org.apache.commons.exec.DefaultExecuteResultHandler in project ddf by codice.

the class VideoThumbnailPlugin method createGifThumbnailWithDuration.

private byte[] createGifThumbnailWithDuration(final String videoFilePath, final Duration duration) throws IOException, InterruptedException {
    final Duration durationFraction = duration.dividedBy(THUMBNAIL_COUNT);
    // Start numbering files with 1 to match FFmpeg's convention.
    for (int clipNum = FFMPEG_FILE_NUMBERING_START; clipNum <= THUMBNAIL_COUNT; ++clipNum) {
        final String thumbnailPath = String.format(getThumbnailFilePath(), clipNum);
        final String seek = durationToString(durationFraction.multipliedBy(clipNum - 1));
        final CommandLine command = getFFmpegCreateThumbnailCommand(videoFilePath, thumbnailPath, seek, 1);
        final DefaultExecuteResultHandler resultHandler = executeFFmpeg(command, 15, DEV_NULL);
        resultHandler.waitFor();
    }
    return createGifFromThumbnailFiles();
}
Also used : CommandLine(org.apache.commons.exec.CommandLine) DefaultExecuteResultHandler(org.apache.commons.exec.DefaultExecuteResultHandler) Duration(java.time.Duration)

Example 3 with DefaultExecuteResultHandler

use of org.apache.commons.exec.DefaultExecuteResultHandler in project ddf by codice.

the class VideoThumbnailPlugin method executeFFmpeg.

private DefaultExecuteResultHandler executeFFmpeg(final CommandLine command, final int timeoutSeconds, final PumpStreamHandler streamHandler) throws IOException {
    final ExecuteWatchdog watchdog = new ExecuteWatchdog(timeoutSeconds * 1000);
    final Executor executor = new DefaultExecutor();
    executor.setWatchdog(watchdog);
    if (streamHandler != null) {
        executor.setStreamHandler(streamHandler);
    }
    final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
    executor.execute(command, resultHandler);
    return resultHandler;
}
Also used : Executor(org.apache.commons.exec.Executor) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) DefaultExecuteResultHandler(org.apache.commons.exec.DefaultExecuteResultHandler) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) ExecuteWatchdog(org.apache.commons.exec.ExecuteWatchdog)

Example 4 with DefaultExecuteResultHandler

use of org.apache.commons.exec.DefaultExecuteResultHandler in project ddf by codice.

the class VideoThumbnailPlugin method createGifFromThumbnailFiles.

private byte[] createGifFromThumbnailFiles() throws IOException, InterruptedException {
    final DefaultExecuteResultHandler resultHandler = executeFFmpeg(getFFmpegCreateAnimatedGifCommand(), 15, DEV_NULL);
    resultHandler.waitFor();
    if (resultHandler.getException() == null) {
        return FileUtils.readFileToByteArray(new File(getGifFilePath()));
    } else {
        throw resultHandler.getException();
    }
}
Also used : DefaultExecuteResultHandler(org.apache.commons.exec.DefaultExecuteResultHandler) File(java.io.File)

Example 5 with DefaultExecuteResultHandler

use of org.apache.commons.exec.DefaultExecuteResultHandler in project xwiki-platform by xwiki.

the class XWikiExecutor method stopInternal.

private void stopInternal() throws Exception {
    String stopCommand = getDefaultStopCommand(getPort(), getStopPort());
    LOGGER.debug("Executing command: [{}]", stopCommand);
    DefaultExecuteResultHandler stopProcessHandler = executeCommand(stopCommand);
    // First wait for the stop process to have stopped, waiting a max of 5 minutes!
    // It's going to stop the start process...
    waitForProcessToFinish(stopProcessHandler, PROCESS_FINISH_TIMEOUT);
}
Also used : DefaultExecuteResultHandler(org.apache.commons.exec.DefaultExecuteResultHandler)

Aggregations

DefaultExecuteResultHandler (org.apache.commons.exec.DefaultExecuteResultHandler)15 CommandLine (org.apache.commons.exec.CommandLine)11 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)9 ExecuteWatchdog (org.apache.commons.exec.ExecuteWatchdog)8 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)8 ExecuteException (org.apache.commons.exec.ExecuteException)6 Executor (org.apache.commons.exec.Executor)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 File (java.io.File)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 URL (java.net.URL)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 LogOutputStream (org.apache.commons.exec.LogOutputStream)3 Jinjava (com.hubspot.jinjava.Jinjava)2 Properties (java.util.Properties)2 ShutdownHookProcessDestroyer (org.apache.commons.exec.ShutdownHookProcessDestroyer)2 SubmarineUI (org.apache.zeppelin.submarine.commons.SubmarineUI)2 ConfigConstants (io.georocket.constants.ConfigConstants)1 RxUtils (io.georocket.util.RxUtils)1