-
-
Notifications
You must be signed in to change notification settings - Fork 344
add Random Frame Extractor #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
resolved #463 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new Random Frame Extractor utility that extracts a specified number of random frames from video files. The tool uses OpenCV to process videos and saves extracted frames as PNG images with unique identifiers.
- Adds a complete Python script for random frame extraction with command-line interface
- Updates the README.md table to document the new utility
- Implements video processing with error handling and frame sampling logic
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
File | Description |
---|---|
Random Frame Extractor/RandomFrameExtractor.py | Main implementation of the frame extraction utility with OpenCV |
README.md | Adds table entry documenting the new Random Frame Extractor tool |
# Load video | ||
cap = cv2.VideoCapture(video_path) | ||
if not cap.isOpened(): | ||
print("Error: Could not open video.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message should be more descriptive and include the video path to help users identify which file failed to open.
print("Error: Could not open video.") | |
print(f"Error: Could not open video at path: {video_path}") |
Copilot uses AI. Check for mistakes.
save_idx += 1 | ||
|
||
frame_idx += 1 | ||
if save_idx > num_frames: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition should be save_idx > len(selected_frames)
or removed entirely. The current logic could cause early termination when save_idx exceeds num_frames, but save_idx starts at 1 while num_frames represents the count.
if save_idx > num_frames: | |
if save_idx > len(selected_frames): |
Copilot uses AI. Check for mistakes.
@@ -163,6 +163,7 @@ More information on contributing and the general code of conduct for discussion | |||
| Word to PDF | [Word to PDF](https://github.com/DhanushNehru/Python-Scripts/tree/main/Word%20to%20PDF%20converter) | A Python script to convert an MS Word file to a PDF file. | | |||
| Youtube Downloader | [Youtube Downloader](https://github.com/DhanushNehru/Python-Scripts/tree/main/Youtube%20Downloader) | Downloads any video from [YouTube](https://youtube.com) in video or audio format! | | |||
| Youtube Playlist Info Scraper | [Youtube Playlist Info Scraper](https://github.com/DhanushNehru/Python-Scripts/tree/main/Youtube%20Playlist%20Info%20Scraper) | This python module retrieve information about a YouTube playlist in json format using playlist link. | | |||
| Random Frame extractor | [Random Frame extractor ](https://github.com/DhanushNehru/Python-Scripts/tree/main/Random%Frame%20Extractor) | This python based command prompt will help you generate n number of frame from a video as an input. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple issues: 'extractor' should be capitalized as 'Extractor' for consistency, there's an extra space before the closing bracket in the link text, the URL has '%Frame%20Extractor' which should be '%20Frame%20Extractor', and the description has grammatical errors - should be 'This Python-based command-line tool will help you generate n number of frames from a video input.'
| Random Frame extractor | [Random Frame extractor ](https://github.com/DhanushNehru/Python-Scripts/tree/main/Random%Frame%20Extractor) | This python based command prompt will help you generate n number of frame from a video as an input. | | |
| Random Frame Extractor | [Random Frame Extractor](https://github.com/DhanushNehru/Python-Scripts/tree/main/Random%20Frame%20Extractor) | This Python-based command-line tool will help you generate n number of frames from a video input. | |
Copilot uses AI. Check for mistakes.
import uuid | ||
import argparse | ||
|
||
def extract_random_frames(video_path, num_frames=15, output_folder="./datasets/images"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function should validate that num_frames is a positive integer to prevent unexpected behavior with zero or negative values.
def extract_random_frames(video_path, num_frames=15, output_folder="./datasets/images"): | |
def extract_random_frames(video_path, num_frames=15, output_folder="./datasets/images"): | |
if not isinstance(num_frames, int) or num_frames <= 0: | |
raise ValueError("num_frames must be a positive integer.") |
Copilot uses AI. Check for mistakes.
Adding Random Frame Extractor
Summary
summary...
add Random Frame Extractor
Description
This python based command prompt will help you generate n number of frame from a video as an input.
The changes are as follows:
Checks
in the repository
in the PR
Thank You,
Hafiz Azhari