A Python utility that extracts the first frame from video files in a directory and saves them as PNG images. This tool is useful for creating thumbnails or previews from a collection of videos.
- 🎥 Supports multiple video formats (MP4, AVI, MOV, MKV, WebM)
- 🔄 Recursive directory scanning
- ⚡ Uses ffmpeg for robust video processing
- 📊 Processing summary statistics
- 🔒 Error handling and validation
- 📁 Separate output directory for organized frame storage
- Python 3.6 or higher
- ffmpeg (must be installed on your system)
Linux (Debian/Ubuntu):
sudo apt update
sudo apt install ffmpegLinux (Arch/Garuda):
sudo pacman -S ffmpegmacOS:
brew install ffmpegWindows: Download from ffmpeg.org or use:
winget install ffmpeg- Clone the repository:
git clone https://github.com/yourusername/Extract_Video_First_Frame.git
cd Extract_Video_First_Frame- (Optional but recommended) Create and activate a virtual environment:
python -m venv .venv
# On Windows
.venv\Scripts\activate
# On macOS/Linux
source .venv/bin/activate- Install Python dependencies:
pip install -r requirements.txtpython extract_frames.py <input_dir> <output_dir>Extract frames from videos in videos/ directory and save to frames/:
python extract_frames.py videos/ frames/Using absolute paths:
python extract_frames.py /path/to/videos /path/to/output- Recursively scans the input directory for video files
- Extracts the first frame from each video using ffmpeg
- Saves frames as high-quality PNG files in the output directory
- Names output files using the video's filename (e.g.,
video.mp4→video.png) - Provides a summary of successful and failed extractions
Found 5 video files.
✓ Saved frame to output/video1.png
✓ Saved frame to output/video2.png
✗ Failed to extract frame from corrupted_video.mp4
Error: Invalid data found when processing input
✓ Saved frame to output/video3.png
✓ Saved frame to output/video4.png
============================================================
Summary: 4/5 frames extracted successfully
Failed files (1):
- corrupted_video.mp4
- MP4 (
.mp4) - AVI (
.avi) - MOV (
.mov) - MKV (
.mkv) - WebM (
.webm)
The script handles common issues gracefully:
- Missing or invalid directories
- Corrupted video files
- Unsupported video encodings
- Missing ffmpeg installation
- Insufficient permissions
All errors are reported with descriptive messages to help troubleshoot issues.
Extract_Video_First_Frame/
├── extract_frames.py # Main script
├── requirements.txt # Python dependencies
├── README.md # This file
├── input/ # Default input directory (optional)
└── output/ # Default output directory (optional)
"ffmpeg: command not found"
- Install ffmpeg using the instructions in the Prerequisites section
No video files found
- Check that your input directory contains videos with supported extensions
- Verify the path to your input directory is correct
Failed to extract frame
- The video file may be corrupted
- The video codec may not be supported by ffmpeg
- Try re-encoding the video with a standard codec
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This means you are free to use, modify, and distribute this software for personal or commercial purposes, with attribution.
If you encounter any issues or have questions:
- Check the Troubleshooting section above
- Review existing issues in the GitHub repository
- Create a new issue with a detailed description of your problem
- Include any error messages and your environment details (OS, Python version, ffmpeg version)