This guide covers how to use the video_to_frames.py script to extract frames from video files using FFmpeg. This command-line approach is ideal for batch processing, automation, or integration into existing workflows.
Before using the script, you need to have FFmpeg installed on your system.
macOS (using Homebrew):
brew install ffmpeg
Ubuntu/Debian:
sudo apt update
sudo apt install ffmpeg
Windows:
- Download FFmpeg from https://ffmpeg.org/download.html
- Extract the archive and add the
binfolder to your system PATH
Verify Installation:
ffmpeg -version
The script requires Python 3.6 or higher. No additional Python packages are needed as it only uses built-in modules.
python3 --version
Extract frames at 1 frame per second (default):
python3 video_to_frames.py video.mp4 -o output_frames/
View video details without extracting frames:
python3 video_to_frames.py video.mp4 --info
Output:
Video Information:
Resolution: 1920x1080
Frame Rate: 30.00 fps
Duration: 120.50 seconds
Total Frames: ~3615
| Option | Description | Default |
|---|---|---|
video |
Path to input video file | (required) |
-o, --output |
Output directory for frames | frames |
-f, --fps |
Frames per second to extract | 1 |
--format |
Output format: jpg, png, webp |
jpg |
-q, --quality |
Image quality (1-100) | 90 |
--start |
Start time in seconds | None |
--end |
End time in seconds | None |
--prefix |
Filename prefix for output files | frame |
--scale |
Output resolution (e.g., -1:720) |
None |
--info |
Show video info and exit | False |
1 frame per second (good for long videos):
python3 video_to_frames.py video.mp4 -o frames/ -f 1
5 frames per second:
python3 video_to_frames.py video.mp4 -o frames/ -f 5
Extract at original frame rate (30 fps example):
python3 video_to_frames.py video.mp4 -o frames/ -f 30
JPEG (smaller files, lossy compression):
python3 video_to_frames.py video.mp4 -o frames/ --format jpg
PNG (lossless, larger files):
python3 video_to_frames.py video.mp4 -o frames/ --format png
WebP (modern format, good compression):
python3 video_to_frames.py video.mp4 -o frames/ --format webp
High quality (larger files):
python3 video_to_frames.py video.mp4 -o frames/ --quality 95
Lower quality (smaller files):
python3 video_to_frames.py video.mp4 -o frames/ --quality 70
Extract frames from 10 seconds to 30 seconds:
python3 video_to_frames.py video.mp4 -o frames/ --start 10 --end 30
Extract first 60 seconds only:
python3 video_to_frames.py video.mp4 -o frames/ --end 60
Skip first 5 seconds:
python3 video_to_frames.py video.mp4 -o frames/ --start 5
python3 video_to_frames.py video.mp4 -o frames/ --prefix screenshot
# Output: screenshot_0001.jpg, screenshot_0002.jpg, ...
Resize to 720p (maintain aspect ratio):
python3 video_to_frames.py video.mp4 -o frames/ --scale -1:720
Resize to specific dimensions:
python3 video_to_frames.py video.mp4 -o frames/ --scale 1280:720
Extract PNG frames from a specific time range at 2 fps with high quality:
python3 video_to_frames.py movie.mp4 \
-o movie_frames/ \
-f 2 \
--format png \
--quality 95 \
--start 60 \
--end 120 \
--prefix scene
After extraction, your output directory will contain numbered image files:
output_frames/
frame_0001.jpg
frame_0002.jpg
frame_0003.jpg
...
The 4-digit numbering (%04d) supports up to 9,999 frames. For longer videos with higher frame rates, the script will continue numbering beyond this.
- 1 fps: Good for long videos, creating thumbnails, or general overview
- 2-5 fps: Balanced extraction for most use cases
- 10+ fps: Detailed analysis, animation, or short clips
- Original fps: When you need every frame (large output)
| Format | Best For | File Size |
|---|---|---|
| JPEG | Web use, sharing, storage efficiency | Small |
| PNG | Editing, transparency, lossless quality | Large |
| WebP | Modern web, good balance | Medium |
For large videos, using a time range can significantly speed up extraction:
# Instead of extracting entire video
python3 video_to_frames.py long_video.mp4 -o frames/
# Extract only the portion you need
python3 video_to_frames.py long_video.mp4 -o frames/ --start 300 --end 600
Process multiple videos with a shell loop:
for video in *.mp4; do
output_dir="${video%.mp4}_frames"
python3 video_to_frames.py "$video" -o "$output_dir" -f 1
done
Ensure FFmpeg is in your system PATH. After installation, restart your terminal or run:
# macOS/Linux
source ~/.bashrc # or ~/.zshrc
# Windows - restart Command Prompt or PowerShell
Use the full path to the video file:
python3 video_to_frames.py /full/path/to/video.mp4 -o frames/
Increase the quality parameter:
python3 video_to_frames.py video.mp4 -o frames/ --quality 95
Or use PNG format for lossless output:
python3 video_to_frames.py video.mp4 -o frames/ --format png
- Use a lower frame rate (
-f 0.5for 1 frame every 2 seconds) - Extract a specific time range (
--startand--end) - Use JPEG format with lower quality
| Feature | video_to_frames.py | VideoToJPG.com |
|---|---|---|
| Installation | Requires FFmpeg | None (browser-based) |
| Batch Processing | Yes | No |
| Automation | Yes (scriptable) | No |
| Sharpness Detection | No | Yes |
| Visual Frame Selection | No | Yes |
| Offline Use | Yes | Yes (after page loads) |
| Best For | Automation, batch jobs | Interactive selection |
Use the Python script when you need automation or batch processing. Use VideoToJPG.com when you want visual frame selection with sharpness detection.