Overview
The three execution modes are:- Slim - Lightweight execution with cancellation support only
- Standard - Standard execution with output monitoring
- Graceful - Full-featured execution with graceful shutdown and output monitoring
Slim
Minimal overhead, basic cancellation
Standard
Output monitoring for progress tracking
Graceful
Graceful shutdown with stdin quit command
Slim Mode
The slim mode is the lightest-weight variant that spawns ffmpeg, waits for it to complete, and returns the exit result. Use this when you don’t need to monitor output or implement graceful shutdown.Function Signature
~/workspace/source/libffmpeg/src/ffmpeg/slim.rs
Key Characteristics
- No output monitoring - stdout/stderr are not captured or streamed
- Basic cancellation - Process is killed immediately when token is cancelled
- Minimal overhead - Fastest execution with lowest resource usage
- Simple interface - Only requires a cancellation token and prepare function
When to Use
Simple batch processing where progress tracking isn’t needed
Fire-and-forget ffmpeg operations
Maximum performance with minimal overhead
Example Usage
Implementation Details
From~/workspace/source/libffmpeg/src/ffmpeg/slim.rs:24-34:
None is passed for the monitor server parameter, meaning no output monitoring occurs.
Standard Mode
The standard mode adds output monitoring capabilities, allowing you to stream stdout and stderr lines through aCommandMonitorServer. This is ideal for progress tracking and real-time logging.
Function Signature
~/workspace/source/libffmpeg/src/ffmpeg/standard.rs
Key Characteristics
- Output monitoring - stdout/stderr lines are streamed through the monitor
- Progress parsing - Can parse ffmpeg’s
-progress pipe:1output - Immediate cancellation - Process is killed immediately on cancellation (no graceful shutdown)
- Real-time feedback - Monitor output as the process runs
When to Use
Need to track encoding progress in real-time
Want to log or display ffmpeg output to users
Parse progress data for UI updates
Don’t require graceful shutdown behavior
Example Usage
From~/workspace/source/libffmpeg/examples/transcode_with_progress.rs:76-88:
Implementation Details
From~/workspace/source/libffmpeg/src/ffmpeg/standard.rs:35-40:
Some(server.clone()) instead of None for output monitoring.
Graceful Mode
The graceful mode provides the most sophisticated execution behavior, combining output monitoring with graceful shutdown. When cancelled, it sends theq command to ffmpeg’s stdin, allowing ffmpeg to finalize the output file properly before exiting.
Function Signature
~/workspace/source/libffmpeg/src/ffmpeg/graceful.rs
Key Characteristics
- Graceful shutdown - Sends
qto stdin on cancellation - 5-second timeout - Falls back to SIGKILL if process doesn’t exit cleanly
- Output monitoring - Full stdout/stderr streaming support
- Proper finalization - Allows ffmpeg to close files and write metadata
When to Use
Need to ensure output files are properly finalized
Want to avoid corrupted output on cancellation
Require both progress tracking and clean shutdown
Building user-facing applications with stop/cancel functionality
Shutdown Flow
From~/workspace/source/libffmpeg/src/ffmpeg/graceful.rs:45-51:
Example Usage
Implementation Details
The graceful mode uses a separateprocess_token and exit_token to coordinate shutdown:
From ~/workspace/source/libffmpeg/src/ffmpeg/graceful.rs:40-44:
Shutdown Handler
From~/workspace/source/libffmpeg/src/ffmpeg/graceful.rs:58-88:
The 5-second timeout is hardcoded in the implementation. If ffmpeg doesn’t respond to the
q command within this window, it will be forcefully killed with SIGKILL.Comparison Table
| Feature | Slim | Standard | Graceful |
|---|---|---|---|
| Output Monitoring | ❌ | ✅ | ✅ |
| Progress Tracking | ❌ | ✅ | ✅ |
| Graceful Shutdown | ❌ | ❌ | ✅ |
| SIGKILL Fallback | Immediate | Immediate | After 5s |
| Monitor Client Required | ❌ | ❌ | ✅ |
| Monitor Server Required | ❌ | ✅ | ✅ |
| Resource Usage | Lowest | Medium | Highest |
Choosing the Right Mode
Use this decision tree to select the appropriate execution mode:Related Topics
Binary Discovery
Learn how ffmpeg binaries are located
Cancellation
Understand CancellationToken usage patterns
Monitoring
Deep dive into CommandMonitor usage