Skip to content

Commit

Permalink
Issue 355: Allow users to override the Executor timeout from the FFmp…
Browse files Browse the repository at this point in the history
…eg fluent API
  • Loading branch information
marklassau committed Sep 7, 2023
1 parent a48df06 commit 30229b2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
18 changes: 17 additions & 1 deletion src/main/java/com/github/kokorin/jaffree/ffmpeg/FFmpeg.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class FFmpeg {

private LogLevel logLevel = LogLevel.INFO;
private String contextName = null;
private int executorTimeoutMillis = ProcessHandler.DEFAULT_EXECUTOR_TIMEOUT_MILLIS;

private final Path executable;

Expand Down Expand Up @@ -387,6 +388,20 @@ public FFmpeg setContextName(final String contextName) {
return this;
}

/**
* Overrides the default {@link com.github.kokorin.jaffree.process.Executor} timeout.
* <p>
* Most normal use cases will easily complete within the default timeout. It is not recommended
* to set an explicit timeout value unless you have actually experienced unwanted timeouts.
*
* @param executorTimeoutMillis the custom executor timeout in milliseconds
* @return this
*/
public FFmpeg setExecutorTimeoutMillis(final int executorTimeoutMillis) {
this.executorTimeoutMillis = executorTimeoutMillis;
return this;
}

/**
* Starts synchronous ffmpeg execution.
* <p>
Expand Down Expand Up @@ -484,7 +499,8 @@ protected ProcessHandler<FFmpegResult> createProcessHandler() {
.setStdErrReader(createStdErrReader(outputListener))
.setStdOutReader(createStdOutReader())
.setHelpers(helpers)
.setArguments(buildArguments());
.setArguments(buildArguments())
.setExecutorTimeoutMillis(executorTimeoutMillis);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public class ProcessHandler<T> {
private List<ProcessHelper> helpers = null;
private Stopper stopper = null;
private List<String> arguments = Collections.emptyList();
private int executorTimeoutMillis = DEFAULT_EXECUTOR_TIMEOUT_MILLIS;

@SuppressWarnings("checkstyle:MagicNumber") // 10,000ms is the default timeout
private static volatile int executorTimeoutMillis = 10_000;
public static final int DEFAULT_EXECUTOR_TIMEOUT_MILLIS = 10_000;
private static final Logger LOGGER = LoggerFactory.getLogger(ProcessHandler.class);

/**
Expand Down Expand Up @@ -121,6 +121,18 @@ public synchronized ProcessHandler<T> setArguments(final List<String> arguments)
return this;
}

/**
* Overrides the default Executor timeout.
*
* @param executorTimeoutMillis the new Executor timeout in milliseconds
* @return this
*/
public synchronized
ProcessHandler<T> setExecutorTimeoutMillis(final int executorTimeoutMillis) {
this.executorTimeoutMillis = executorTimeoutMillis;
return this;
}

/**
* Executes a program.
* <p>
Expand Down Expand Up @@ -270,15 +282,6 @@ public void run() {
return executor;
}

/**
* Overrides the default executor timeout to the given value.
*
* @param executorTimeoutMillis the new timeout value
*/
public static void setExecutorTimeoutMillis(final int executorTimeoutMillis) {
ProcessHandler.executorTimeoutMillis = executorTimeoutMillis;
}

protected static String joinArguments(final List<String> arguments) {
StringBuilder result = new StringBuilder();
boolean first = true;
Expand Down

0 comments on commit 30229b2

Please sign in to comment.