README.md
: The ultimate guide to understanding and using the code.extract_images.py
: Python script for extracting images from videos and editing their metadata.requirements.txt
: List of required libraries and their versions.videos/
: Directory for storing input video files.images/
: Directory for storing output extracted images.
- Clone the repository:
git clone https://github.com/your-username/extract-images-from-videos.git
- Install the required libraries:
pip install -r requirements.txt
- Place your video files in the
videos/
directory. - Run the script:
python extract_images.py
- Extracted images will be saved in the
images/
directory with updated metadata.
The extract_images.py
script contains the following steps:
- Import the necessary libraries (cv2, datetime, piexif) for video processing and metadata editing.
- Specify the paths for the input videos directory (
videos/
) and the output images directory (images/
). - Iterate through each video file in the input directory.
- Read the video file and get its frames per second (fps).
- Initialize variables for frame extraction.
- Extract frames at 5-second intervals and save them as images.
- Get the video's datetime created and update the image's metadata with it.
- Save the modified image with the updated metadata.
- Release the video capture.
- Print a message indicating the number of videos processed and images extracted.
This code allows you to extract images from multiple videos and edit their metadata using the piExifTool library.
- Load the videos from the specified file path.
- Read the video frames per second (fps).
- Loop through each video and extract frames at 5-second intervals.
- Get the metadata (datetime created) of the video.
- Rename each extracted image with the video's datetime and frame number.
- Update the image's EXIF metadata with the video's datetime.
- Save the modified image with the updated metadata.
- Release the video capture.
- Specify the directory paths for the videos and the output images.
- Run the code.
- The extracted images will be saved in the specified output directory.
- The images will have their metadata updated with the datetime information from the corresponding videos.
- cv2 library: Install using
!pip install cv2
. - piexif library: Install using
!pip install piexif
.
Please note that you need to have the specified libraries installed in order to run the code successfully.
Feel free to modify the code according to your specific requirements.
That's a brief overview of the code in the code.ipynb file. If you have any further questions, feel free to ask!