Extract frames
A Rust-based command-line application for extracting frames from video files
using FFmpeg, supporting both sequential and parallel processing modes.
Table of Contents
Features
- Support for parallel processing using multiple CPU cores
- Optional combined full-pane image output for reviewing all extracted frames at once
- Optional output image resizing
- PNG compression and JPEG quality controls
- Robust error handling for file operations and FFmpeg interactions
- Comprehensive test suite for core functionality
Usage
The application provides several command-line options to control frame
extraction.
Basic Usage
To extract frames from a video file using default settings (every 30th frame):
cargo run -- --file input.mp4
The extracted frames will be saved as PNG files in the frames directory.
Resize and Compress Output Images
To resize extracted frames to 640 pixels wide while preserving aspect ratio:
cargo run -- --file input.mp4 --output-width 640
To write JPEG frames with a smaller file size:
cargo run -- --file input.mp4 --output-format jpeg --jpeg-quality 75
To use stronger PNG compression:
cargo run -- --file input.mp4 --png-compression best
PNG compression is optimized losslessly with oxipng.
To skip PNG optimization for faster PNG writes:
cargo run -- --file input.mp4 --no-png-optimization
Create a Combined Full-Pane Image
To render all extracted frames into one near-square grid image instead of
writing each frame separately:
cargo run -- --file input.mp4 --output-full-pane
The combined image is saved to frames/full-pane.png by default. It uses the
same resize, format, JPEG quality, PNG compression, and frame sampling options
as regular extraction. If the combined pane would exceed 8192x8192 pixels, the
frame tiles are resized proportionally so the final image fits within that
limit.
Extract One Frame Per Second
To extract one frame per second using the seek-based method:
cargo run -- --file input.mp4 --use-seek
Parallel Processing
To enable parallel processing by splitting the video into segments and
processing them concurrently:
cargo run -- --file input.mp4 --multicore
Command Line Arguments
--file <PATH>: Specify input video file (default: "video.mp4")
--use-seek: Enable seek-based frame extraction (one frame per second)
--multicore: Enable parallel processing using multiple CPU cores
--frames-between <N>: Number of frames to skip between extracted frames
(default: 30)
--output-width <PIXELS>: Resize output images to this width
--output-height <PIXELS>: Resize output images to this height
--output-format <png|jpeg>: Output image format (default: png)
--jpeg-quality <1-100>: JPEG quality when writing JPEGs (default: 90)
--png-compression <fast|default|best>: PNG compression level (default:
default)
--no-png-optimization: Disable lossless PNG optimization with oxipng
--output-full-pane: Save all extracted frames as one near-square grid image
at frames/full-pane.<format> instead of writing individual frame files
(capped at 8192x8192 pixels)
Requirements
- FFmpeg installed and available in system PATH
- Rust toolchain (including cargo)
Development
To contribute to this project, you'll need:
- Rust toolchain (nightly version recommended)
just init-macos or just init-linux
Building and Testing
- Clone the repository
- Run
just build to compile the application
- Run
just test to execute the test suite
- Run
cargo run -- --help to see command-line options
Building on Ubuntu
You need to install these packages:
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libavfilter-dev libavdevice-dev libavutil-dev yasm
Contributing
Contributions are welcome! Please submit pull requests with clear descriptions
of changes and ensure that all tests pass before submitting.
Troubleshooting
- If you encounter issues with FFmpeg, ensure it's installed and available in
your system's PATH.
- If you experience errors during parallel processing, verify that your system
has sufficient resources (CPU cores and memory).
- For other issues, please check the issues
page or submit a new
issue with detailed information about your problem.