-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
09074bd
Pull true fps from input videos and use it when making new videos
jasper-tms d960d82
Add `--output-fps` command line argument
jasper-tms a0d4125
Handle and log possible errors in extracting fps from video files
jasper-tms 7f96462
Tell tests about output video framerate used in test data
jasper-tms 66b17b0
Recreate the test data output videos with updated framerates
Dominic-DallOsto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,36 @@ 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] | ||||||||
| try: | ||||||||
| rates.append(subprocess.check_output(cmd, text=True)) | ||||||||
| except: | ||||||||
| logger.warning(f"Command failed: {' '.join(cmd)}") | ||||||||
| break | ||||||||
| 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).") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.