-
Notifications
You must be signed in to change notification settings - Fork 1
Improve frame metadata handling in video converter #3
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,31 +2,41 @@ | |||||||
| import json | ||||||||
| import os | ||||||||
| from datetime import datetime | ||||||||
| from os.path import isfile, join | ||||||||
|
|
||||||||
| import cv2 | ||||||||
| import numpy as np | ||||||||
|
|
||||||||
| # Initialize parser | ||||||||
| parser = argparse.ArgumentParser() | ||||||||
|
|
||||||||
| # Adding optional argument | ||||||||
| parser.add_argument("-n", "--name", help="name of video") | ||||||||
|
|
||||||||
| # Load the frame data from JSON | ||||||||
| frame_data = open("./frameCreationInfo.json") | ||||||||
| frame_data = json.load(frame_data) | ||||||||
|
|
||||||||
|
|
||||||||
| def convert_frames_to_video(pathIn, pathOut, fps): | ||||||||
| def convert_frames_to_video(pathIn, pathOut, fps, frame_data, cv2_module=cv2): | ||||||||
| """ | ||||||||
| Optimized OpenCV method with better codec and settings | ||||||||
| """ | ||||||||
| try: | ||||||||
| # Load the first image to get video dimensions | ||||||||
| first_frame_key = frame_data["frame_key"]["0"] | ||||||||
| frame_keys = frame_data.get("frame_key") | ||||||||
| if not frame_keys: | ||||||||
| print("Error: Metadata is missing frame_key entries.") | ||||||||
| return False | ||||||||
|
|
||||||||
| first_frame_key = frame_keys.get("0") if isinstance(frame_keys, dict) else None | ||||||||
| if first_frame_key is None: | ||||||||
| print("Error: Metadata does not contain a first frame entry.") | ||||||||
| return False | ||||||||
|
|
||||||||
| first_frame_path = pathIn + first_frame_key + ".png" | ||||||||
| img = cv2.imread(first_frame_path) | ||||||||
|
|
||||||||
| if not os.path.exists(first_frame_path): | ||||||||
| print( | ||||||||
| "Error: First frame not found at" | ||||||||
| f" {first_frame_path}. Please ensure frames are generated." | ||||||||
|
Comment on lines
+34
to
+35
|
||||||||
| "Error: First frame not found at" | |
| f" {first_frame_path}. Please ensure frames are generated." | |
| f"Error: First frame not found at {first_frame_path}. Please ensure frames are generated." |
Copilot
AI
Oct 14, 2025
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.
Using string concatenation for file paths can cause issues on different operating systems. Use os.path.join(pathIn, frame_key + '.png') instead for cross-platform compatibility.
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.
Using string concatenation for file paths can cause issues on different operating systems. Use
os.path.join(pathIn, first_frame_key + '.png')instead for cross-platform compatibility.