Search in sources :

Example 11 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 12 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 13 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 14 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 15 with CommandLine

use of org.apache.commons.exec.CommandLine in project sakuli by ConSol.

the class SahiCommandExecutionAspect method getCommandTokens.

/**
     * Due to the fact, the parsing of the sahi method {@link net.sf.sahi.util.Utils#getCommandTokens(String)} won't
     * work correctly, this {@link Around} advice use the Apache libary {@link CommandLine#parse(String)} to modify it.
     * See http://community.sahipro.com/forums/discussion/8552/sahi-os-5-0-and-chrome-user-data-dir-containing-spaces-not-working.
     *
     * @param joinPoint     the {@link ProceedingJoinPoint} of the invoked method
     * @param commandString the original argument as{@link String}
     * @return the result of {@link CommandLine#parse(String)}
     */
@Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)")
public String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString) {
    Logger LOGGER = getLogger(joinPoint);
    CommandLine parsed = CommandLine.parse(commandString);
    String[] tokens = new String[] { parsed.getExecutable() };
    tokens = ArrayUtils.addAll(tokens, parsed.getArguments());
    try {
        Object result = joinPoint.proceed();
        if (result instanceof String[] && !Arrays.equals(tokens, (String[]) result)) {
            if (commandString.startsWith("sh -c \'")) {
                //LOGGER.info("SAKULI-RESULT {}", printArray(tokens));
                return (String[]) result;
            }
            LOGGER.info("MODIFIED SAHI COMMAND TOKENS: {} => {}", printArray((String[]) result), printArray(tokens));
        }
    } catch (Throwable e) {
        LOGGER.error("Exception during execution of JoinPoint net.sf.sahi.util.Utils.getCommandTokens", e);
    }
    return tokens;
}
Also used : CommandLine(org.apache.commons.exec.CommandLine) Logger(org.slf4j.Logger) Around(org.aspectj.lang.annotation.Around)

Aggregations

CommandLine (org.apache.commons.exec.CommandLine)44 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)26 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)20 IOException (java.io.IOException)18 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 ExecuteException (org.apache.commons.exec.ExecuteException)12 ExecuteWatchdog (org.apache.commons.exec.ExecuteWatchdog)11 File (java.io.File)8 PipedInputStream (java.io.PipedInputStream)4 PipedOutputStream (java.io.PipedOutputStream)4 DefaultExecuteResultHandler (org.apache.commons.exec.DefaultExecuteResultHandler)4 ExecuteResultHandler (org.apache.commons.exec.ExecuteResultHandler)4 InputStream (java.io.InputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 Map (java.util.Map)3 Executor (org.apache.commons.exec.Executor)3 BufferedWriter (java.io.BufferedWriter)2 DataInputStream (java.io.DataInputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2