-
Notifications
You must be signed in to change notification settings - Fork 17
Pull true fps from input videos and use it when making new videos #63
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
Changes from 1 commit
09074bd
d960d82
a0d4125
7f96462
66b17b0
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -76,6 +76,7 @@ def __init__( | |||||||
| self.output_folder = output_folder | ||||||||
|
|
||||||||
| self.expand_videos() # turn .mp4 into .jpg | ||||||||
| self.fps = self.get_fps() | ||||||||
| self.num_images_max = num_images_max if num_images_max is not None else 0 | ||||||||
| self.max_img_id = get_max_img_id(self.input_folder) | ||||||||
| if self.num_images_max > 0: | ||||||||
|
|
@@ -412,6 +413,21 @@ def setup_camera_ordering(self, camera_ordering) -> np.ndarray: | |||||||
| # self.cidread2cid, self.cid2cidread = read_camera_order(self.output_folder) | ||||||||
| return np.array(camera_ordering) | ||||||||
|
|
||||||||
| def get_fps(self): | ||||||||
| rates = [] | ||||||||
| for vid in glob.glob(os.path.join(self.input_folder, "camera_?.mp4")): | ||||||||
| cmd = ["ffprobe", "-v", "error", "-select_streams", "v:0", | ||||||||
| "-show_entries", "stream=avg_frame_rate", "-of", | ||||||||
| "default=noprint_wrappers=1:nokey=1", vid] | ||||||||
| rates.append(subprocess.check_output(cmd, text=True)) | ||||||||
| if len(rates) == 0: | ||||||||
| return None | ||||||||
| if any(rate != rates[0] for rate in rates): | ||||||||
|
||||||||
| if any(rate != rates[0] for rate in rates): | |
| if any(rate != rates[0] for rate in rates): | |
| logger.warning("Inconsistent frame rates detected across videos. Falling back to default FPS (None).") |
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.
What's the default output if no FPS information is saved in the video metadata? In other words, will this line fail because "/" is not detected?
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.
Wrap the
subprocess.check_outputcall in a try/except to handle situations where ffprobe fails, and log a warning rather than letting the exception crash the run.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.
I agree with Copilot here - if this goes wrong, it can be very hard to debug because ffprobe runs in a different process. This can be especially chaotic when someone runs df3d on a cluster or in the background because different STDOUT/STDERR streams from different processes can be redirected to the same file but with different buffering configurations. Potentially this can make the location of the error message in the log very confusing.