-
Notifications
You must be signed in to change notification settings - Fork 11
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
Adding FPS metadata to Video
formats
#105
Conversation
WalkthroughThe recent updates enhance the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #105 +/- ##
==========================================
- Coverage 96.04% 96.03% -0.01%
==========================================
Files 17 17
Lines 2022 2044 +22
==========================================
+ Hits 1942 1963 +21
- Misses 80 81 +1 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- sleap_io/io/video.py (9 hunks)
- sleap_io/model/video.py (4 hunks)
- tests/io/test_video_backends.py (1 hunks)
Additional comments not posted (8)
tests/io/test_video_backends.py (1)
17-17
: LGTM! Assertion forframe_rate
is correctly added.The assertion verifies that the
frame_rate
attribute is correctly set to 15.0.sleap_io/model/video.py (2)
65-65
: LGTM!_frame_rate
parameter is correctly added.The
_frame_rate
parameter is correctly passed to theVideoBackend.from_filename
method.Also applies to: 83-83, 98-98
113-121
: LGTM!frame_rate
property is correctly added.The
frame_rate
property correctly retrieves the frame rate from the backend.sleap_io/io/video.py (5)
52-52
: LGTM!_frame_rate
attribute andframe_rate
property are correctly added.The
_frame_rate
attribute andframe_rate
property are correctly implemented.Also applies to: 58-58, 197-201
69-69
: LGTM!_frame_rate
parameter and frame rate calculation are correctly added.The
_frame_rate
parameter is correctly passed, and the frame rate is correctly calculated using OpenCV.Also applies to: 83-83, 88-92, 113-113, 122-122
327-327
: LGTM!_frame_rate
attribute is correctly added.The
_frame_rate
attribute is correctly implemented.
483-483
: LGTM!_frame_rate
attribute is correctly added.The
_frame_rate
attribute is correctly implemented.
725-725
: LGTM!_frame_rate
attribute is correctly added.The
_frame_rate
attribute is correctly implemented.
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.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- sleap_io/io/video.py (8 hunks)
Additional context used
Ruff
sleap_io/io/video.py
89-90: Use a single
if
statement instead of nestedif
statements(SIM102)
Additional comments not posted (5)
sleap_io/io/video.py (5)
52-52
: Addition of_frame_rate
attribute in class docstringThe addition of the
_frame_rate
attribute in the class docstring ofVideoBackend
is well-documented, providing clear information about its purpose.
58-58
: Initialization of_frame_rate
attributeThe
_frame_rate
attribute is properly initialized toNone
, which is appropriate for optional values. This allows for flexibility in cases where the frame rate might not be applicable or available.
83-83
: Documentation for_frame_rate
parameterThe documentation for the
_frame_rate
parameter in thefrom_filename
method is clear and concise, explaining its purpose effectively.
122-122
: Passing_frame_rate
toHDF5Video
constructorThe
_frame_rate
is correctly passed to theHDF5Video
constructor, ensuring that the frame rate information is preserved across different video backends.
197-201
: Property method forframe_rate
The
frame_rate
property method is correctly implemented to return the_frame_rate
attribute. This provides a clean API for accessing the frame rate of a 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.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- sleap_io/io/video.py (7 hunks)
Additional context used
Ruff
sleap_io/io/video.py
194-195: Use a single
if
statement instead of nestedif
statements(SIM102)
Additional comments not posted (2)
sleap_io/io/video.py (2)
324-324
: Addition of_frame_rate
attribute toMediaVideo
.The addition of the
_frame_rate
attribute to theMediaVideo
class is consistent with the PR objectives and aligns with the changes made to theVideoBackend
class.
480-480
: Addition of_frame_rate
attribute toHDF5Video
.The addition of the
_frame_rate
attribute to theHDF5Video
class is consistent with the PR objectives and aligns with the changes made to theVideoBackend
class.
I am getting the error |
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- sleap_io/io/video.py (6 hunks)
Files skipped from review as they are similar to previous changes (1)
- sleap_io/io/video.py
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.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (1)
sleap_io/io/video.py (1)
58-58
: Ensure_frame_rate
is correctly handled inVideoBackend
class.The
_frame_rate
attribute is initialized toNone
and is returned by a method, but there are no other assignments or method calls involving_frame_rate
found. This suggests that_frame_rate
might not be properly set to a meaningful value before being used.
- File:
sleap_io/io/video.py
- Lines:
_frame_rate
initialization:sleap_io/io/video.py: _frame_rate = None
- Method returning
_frame_rate
:sleap_io/io/video.py: return self._frame_rate
Please ensure
_frame_rate
is correctly set to a valid float value before being used in any operations.Analysis chain
Ensure
_frame_rate
is correctly handled inVideoBackend
class.The
_frame_rate
attribute has been initialized toNone
. Ensure that it is correctly set and used in the class methods.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that `_frame_rate` is correctly set and used in the `VideoBackend` class. # Test: Search for the `_frame_rate` usage. Expect: Correct handling in the class methods. rg --type python '_frame_rate' -A 5Length of output: 66
Script:
#!/bin/bash # Description: Verify that `_frame_rate` is correctly set and used in the `VideoBackend` class. # Test: Search for the `_frame_rate` usage. Expect: Correct handling in the class methods. rg --type py '_frame_rate' -A 5Length of output: 3490
Script:
#!/bin/bash # Description: Verify that `_frame_rate` is correctly set and used in the `VideoBackend` class. # Test: Search for assignments to `_frame_rate` and method calls involving `_frame_rate`. rg --type py '_frame_rate\s*=' -A 5 rg --type py 'self\._frame_rate' -A 5Length of output: 942
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- sleap_io/io/video.py (6 hunks)
- sleap_io/model/video.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- sleap_io/model/video.py
Additional comments not posted (5)
sleap_io/io/video.py (5)
52-52
: Addition of_frame_rate
attribute toVideoBackend
class.The addition of the
_frame_rate
attribute aligns with the PR objectives and enhances the functionality of theVideoBackend
class by storing the frame rate of the video.
330-330
: Addition of_frame_rate
attribute toMediaVideo
class.The addition of the
_frame_rate
attribute in the docstring aligns with the PR objectives and enhances the functionality of theMediaVideo
class by storing the frame rate of the video.
486-486
: Addition of_frame_rate
attribute toHDF5Video
class.The addition of the
_frame_rate
attribute in the docstring aligns with the PR objectives and enhances the functionality of theHDF5Video
class by storing the frame rate of the video.
728-728
: Addition of_frame_rate
attribute toImageVideo
class.The addition of the
_frame_rate
attribute aligns with the PR objectives and enhances the functionality of theImageVideo
class by storing the frame rate of the video.
195-203
: Optimize conditional checks for file extension inframe_rate
property.The nested
if
statements checking for file extensions can be optimized into a single conditional expression. This simplifies the code and improves readability.- if isinstance(self.filename, str) and any( - self.filename.endswith(ext) for ext in video_extensions - ): + if isinstance(self.filename, str) and any(self.filename.endswith(ext) for ext in video_extensions):Likely invalid or redundant comment.
@@ -77,6 +79,7 @@ def from_filename( | |||
frames. If False, will close the reader after each call. If True (the | |||
default), it will keep the reader open and cache it for subsequent calls | |||
which may enhance the performance of reading multiple frames. | |||
_frame_rate: Frame rate of the 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.
Update type hint for _frame_rate
parameter in from_filename
method.
The type hint for _frame_rate
should be Optional[float]
instead of Optional[bool]
.
- _frame_rate: Optional[bool] = None,
+ _frame_rate: Optional[float] = None,
Committable suggestion was skipped due to low confidence.
sleap_io/io/video.py
Outdated
video_extensions = ["mp4", "avi", "mov", "mj2", "mkv", "slp"] | ||
if isinstance(self.filename, str) and any( | ||
self.filename.endswith(ext) for ext in video_extensions | ||
): | ||
return cv2.VideoCapture(self.filename).get(cv2.CAP_PROP_FPS) |
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.
SUBGROUP REVIEW: We don't need to check the video extension or filename here since this property of frame_rate would only ever be accessed if filename pointed to a VIdeo object anyways
…oding/io_fork into kloding/add_video_fps_data
def frame_rate(self) -> Optional[float]: | ||
"""Frames per second of the video.""" | ||
video_extensions = ["mp4", "avi", "mov", "mj2", "mkv"] | ||
if not any(self.filename.endswith(ext) for ext in video_extensions): |
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 conditional is necessary because ImageVideo
inherits from VideoBackend
. If we try to check the frame rate of ImageVideo
objects, which are stored as image files, we will get an error.
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- sleap_io/io/video.py (6 hunks)
Files skipped from review as they are similar to previous changes (1)
- sleap_io/io/video.py
Description
Right now, our video classes such as
Video
andMediaVideo
can't store information about the fps of the video. Adding attributes to these classes that store this data will allow the user to set the frame rate, rather than setting it to a default value. I will write new tests and load videos with different frame rates in the GUI. I will also update the documentation, as necessary.Types of changes
Does this address any currently open issues?
#103
Outside contributors checklist
Thank you for contributing to SLEAP!
❤️
Summary by CodeRabbit