Search in sources :

Example 16 with CommandLine

use of org.apache.commons.exec.CommandLine 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 17 with CommandLine

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

the class VideoThumbnailPlugin method getFFmpegCreateThumbnailCommand.

private CommandLine getFFmpegCreateThumbnailCommand(final String videoFilePath, final String thumbnailFilePath, final String seek, final int numFrames) {
    final String filterChainFlag = "-vf";
    final String filterChain = "thumbnail,scale=200:-1";
    final String videoFramesToOutputFlag = "-frames:v";
    final String videoFramesToOutput = String.valueOf(numFrames);
    final String videoSyncFlag = "-vsync";
    final String videoSyncVariableFrameRate = "vfr";
    final CommandLine command = new CommandLine(ffmpegPath).addArgument(SUPPRESS_PRINTING_BANNER_FLAG);
    if (seek != null) {
        final String seekFlag = "-ss";
        command.addArgument(seekFlag).addArgument(seek);
    }
    command.addArgument(INPUT_FILE_FLAG).addArgument(videoFilePath, DONT_HANDLE_QUOTING).addArgument(filterChainFlag).addArgument(filterChain).addArgument(videoFramesToOutputFlag).addArgument(videoFramesToOutput).addArgument(videoSyncFlag).addArgument(videoSyncVariableFrameRate);
    command.addArgument(thumbnailFilePath, DONT_HANDLE_QUOTING).addArgument(OVERWRITE_EXISTING_FILE_FLAG);
    return command;
}
Also used : CommandLine(org.apache.commons.exec.CommandLine)

Example 18 with CommandLine

use of org.apache.commons.exec.CommandLine 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 19 with CommandLine

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

the class VideoThumbnailPlugin method getFFmpegInfoCommand.

private CommandLine getFFmpegInfoCommand(final String videoFilePath) {
    CommandLine commandLine = new CommandLine(ffmpegPath).addArgument(SUPPRESS_PRINTING_BANNER_FLAG).addArgument(INPUT_FILE_FLAG).addArgument(videoFilePath, DONT_HANDLE_QUOTING);
    LOGGER.debug("FFmpeg command : {}", commandLine.toString());
    return commandLine;
}
Also used : CommandLine(org.apache.commons.exec.CommandLine)

Example 20 with CommandLine

use of org.apache.commons.exec.CommandLine in project storm by apache.

the class Utils method execCommand.

public static int execCommand(String... command) throws ExecuteException, IOException {
    CommandLine cmd = new CommandLine(command[0]);
    for (int i = 1; i < command.length; i++) {
        cmd.addArgument(command[i]);
    }
    DefaultExecutor exec = new DefaultExecutor();
    return exec.execute(cmd);
}
Also used : CommandLine(org.apache.commons.exec.CommandLine) DefaultExecutor(org.apache.commons.exec.DefaultExecutor)

Aggregations

CommandLine (org.apache.commons.exec.CommandLine)40 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)25 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)19 IOException (java.io.IOException)17 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 ExecuteException (org.apache.commons.exec.ExecuteException)11 ExecuteWatchdog (org.apache.commons.exec.ExecuteWatchdog)10 File (java.io.File)6 PipedInputStream (java.io.PipedInputStream)4 PipedOutputStream (java.io.PipedOutputStream)4 DefaultExecuteResultHandler (org.apache.commons.exec.DefaultExecuteResultHandler)4 InputStream (java.io.InputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 Map (java.util.Map)3 ExecuteResultHandler (org.apache.commons.exec.ExecuteResultHandler)3 BufferedWriter (java.io.BufferedWriter)2 DataInputStream (java.io.DataInputStream)2 HashSet (java.util.HashSet)2 Executor (org.apache.commons.exec.Executor)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2