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 ffmpegUbuntu/Debian:
sudo apt update
sudo apt install ffmpegWindows:
- Download FFmpeg from https://ffmpeg.org/download.html
- Extract the archive and add the
binfolder to your system PATH
Verify Installation:
ffmpeg -versionThe script requires Python 3.6 or higher. No additional Python packages are needed as it only uses built-in modules.
python3 --versionExtract 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 --infoOutput:
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 15 frames per second:
python3 video_to_frames.py video.mp4 -o frames/ -f 5Extract at original frame rate (30 fps example):
python3 video_to_frames.py video.mp4 -o frames/ -f 30JPEG (smaller files, lossy compression):
python3 video_to_frames.py video.mp4 -o frames/ --format jpgPNG (lossless, larger files):
python3 video_to_frames.py video.mp4 -o frames/ --format pngWebP (modern format, good compression):
python3 video_to_frames.py video.mp4 -o frames/ --format webpHigh quality (larger files):
python3 video_to_frames.py video.mp4 -o frames/ --quality 95Lower quality (smaller files):
python3 video_to_frames.py video.mp4 -o frames/ --quality 70Extract frames from 10 seconds to 30 seconds:
python3 video_to_frames.py video.mp4 -o frames/ --start 10 --end 30Extract first 60 seconds only:
python3 video_to_frames.py video.mp4 -o frames/ --end 60Skip first 5 seconds:
python3 video_to_frames.py video.mp4 -o frames/ --start 5python3 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:720Resize to specific dimensions:
python3 video_to_frames.py video.mp4 -o frames/ --scale 1280:720Extract 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 sceneAfter 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 600Process 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
doneEnsure FFmpeg is in your system PATH. After installation, restart your terminal or run:
# macOS/Linux
source ~/.bashrc # or ~/.zshrc
# Windows - restart Command Prompt or PowerShellUse 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 95Or 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.