ffmpeg module provides three variants of ffmpeg execution, each with different levels of control and monitoring capabilities.
ffmpeg_slim
Run ffmpeg with cancellation support only (no output monitoring). This is the lightest-weight variant — it spawns ffmpeg, waits for it to complete, and returns the exit result. Useffmpeg if you need to stream stdout/stderr, or ffmpeg_graceful for graceful shutdown.
Parameters
A token to cancel the ffmpeg process. When cancelled, the process is killed immediately.
A closure that configures the ffmpeg command before execution. Use this to add arguments, set environment variables, etc.
Returns
ReturnsResult<CommandExit, FfmpegError>:
Ok(CommandExit)- Contains the exit code, stdout, and stderr from the ffmpeg processErr(FfmpegError::NotFound)- The ffmpeg binary could not be found in PATH or viaLIBFFMPEG_FFMPEG_PATH
Example
ffmpeg
Run ffmpeg with output monitoring via aCommandMonitorServer.
Stdout and stderr lines are streamed through the monitor, allowing real-time progress parsing or logging. On cancellation the process is killed immediately — use ffmpeg_graceful if you need stdin-based quit with a SIGKILL fallback.
Parameters
A token to cancel the ffmpeg process. When cancelled, the process is killed immediately.
A server that monitors stdout/stderr output from the ffmpeg process. Use this to track progress or parse output in real-time.
A closure that configures the ffmpeg command before execution.
Returns
ReturnsResult<CommandExit, FfmpegError>:
Ok(CommandExit)- Contains the exit code, stdout, and stderr from the ffmpeg processErr(FfmpegError::NotFound)- The ffmpeg binary could not be found
Example
ffmpeg_graceful
Run ffmpeg with output monitoring and graceful shutdown. On cancellation, sendsq to ffmpeg’s stdin (its built-in quit command), giving the process up to 5 seconds to exit cleanly before falling back to SIGKILL. This allows ffmpeg to finalize the output file properly.
Parameters
A token to cancel the ffmpeg process. When cancelled, the function sends “q” to stdin and waits up to 5 seconds before force-killing.
A client used to send the “q” command to ffmpeg’s stdin during graceful shutdown.
A server that monitors stdout/stderr output from the ffmpeg process.
A closure that configures the ffmpeg command before execution.
Returns
ReturnsResult<CommandExit, FfmpegError>:
Ok(CommandExit)- Contains the exit code, stdout, and stderr from the ffmpeg processErr(FfmpegError::NotFound)- The ffmpeg binary could not be found
Graceful Shutdown Flow
- If the process exits naturally before cancellation, do nothing and return early
- User requests cancellation via the
cancellation_token - Send “q” to ffmpeg’s stdin
- Wait up to 5 seconds for the process to exit gracefully
- If the process doesn’t exit after 5 seconds, send SIGKILL