This Python script extracts frames from video files at a specified frame rate (FPS) and saves them in the desired image format (.jpg, .jpeg, .png, .tif). The script can be run interactively or with command-line parameters.
- Supports multiple video formats (
.mp4,.avi,.mov,.mkv). - Allows users to specify the desired FPS for frame extraction.
- Supports multiple output image formats (
.jpg,.jpeg,.png,.tif). - Provides an interactive prompt if no command-line arguments are given.
- Uses
tqdmfor progress tracking.
Ensure you have the following dependencies installed:
pip install opencv-python tqdmRun the script using Python:
python Video-Frame-Extractor.pyThe script will prompt for:
- Input directory: The directory containing video files.
- Output directory: The directory where extracted frames will be saved.
- Desired FPS: The frame rate for extraction.
- Output Image Format: Users can choose between
.jpg,.jpeg,.png,.tif.
Alternatively, users can provide all parameters in one command:
python Video-Frame-Extractor.py --input_dir path/to/videos --output_dir path/to/output --fps 5 --img_format jpg- Assume the following directory structure before running the script:
/videos
├── video1.mp4
├── video2.avi
- Running the script interactively and providing the
/videosdirectory as input and/framesas output:
Enter the input directory containing videos: /videos
Enter the output directory for extracted frames: /frames
Enter the desired frames per second (FPS): 5
Select the output image format:
1: jpg
2: jpeg
3: png
4: tif
Enter the format number: 1
- The extracted frames will be saved in:
/frames
├── video1
│ ├── frame_0000.jpg
│ ├── frame_0001.jpg
├── video2
├── frame_0000.jpg
├── frame_0001.jpg
- Reads video files from the input directory.
- Extracts frames at the specified FPS.
- Saves frames in the user-specified image format.
- Uses
tqdmto display a progress bar. - Handles both interactive and command-line executions.
This project is licensed under the MIT License.