ffmpeg_slim function, which provides basic cancellation support without output monitoring.
Complete Example
Breaking Down the Code
1. Import Dependencies
ffmpeg_slim: The lightest-weight variant of the ffmpeg runner. It spawns ffmpeg, waits for completion, and returns the exit result without output monitoring.CancellationToken: Allows you to cancel the operation if needed (e.g., on user interrupt or timeout).
2. Create Cancellation Token
cancellation_token.cancel(), ffmpeg will be terminated. This is useful for:
- Handling Ctrl+C signals
- Implementing timeouts
- Responding to user cancellation requests
3. Configure FFmpeg Command
&mut Command that you configure with ffmpeg arguments:
-i input.mp4: Specifies the input file-c:v libx264: Use H.264 video codec-preset fast: Balance between encoding speed and compression-crf 23: Constant Rate Factor (quality level, 18-28 is typical)-c:a aac: Use AAC audio codec-b:a 128k: Set audio bitrate to 128 kbps-y: Overwrite output file without prompting
4. Check the Result
CommandExit result contains:
exit_code: The process exit statussuccess: Whether the exit code indicates success (typically 0)
When to Use ffmpeg_slim
Use this variant when:
- You don’t need real-time progress updates
- You don’t need to monitor stdout/stderr output
- You want the minimal overhead
- You still want cancellation support