-
Notifications
You must be signed in to change notification settings - Fork 42
Calculate num_frames if missing from metadata #732
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
@@ -129,8 +129,15 @@ def num_frames(self) -> Optional[int]: | |||
""" |
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.
In the doc string, we should also say what we do if num_frames is missing from all of the metadata.
elif ( | ||
self.average_fps_from_header is not None | ||
and self.duration_seconds_from_header is not 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.
I just went down an interesting rabbit-hole of asking "Should we instead use the average_fps
property?" And the answer is no! :) If self.average_fps_from_header is None
, then self.average_fps
actually calls this property, self.num_frames
and we'd (I think) hit infinite recursion. I do wonder if there is a way for us to be more systematic about this, where we could more centrally define the logic of under what circumstances we use which metadata.
test/test_decoders.py
Outdated
all_frames = decoder.get_frames_played_in_range( | ||
decoder.metadata.begin_stream_seconds, decoder.metadata.end_stream_seconds | ||
) | ||
assert_frames_equal(all_frames.data, decoder[:]) |
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.
Can we also add a simple assert len(decoder) == CORRECT_VALUE
?
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 had initially approved, but it looks like the tests are failing on Mac - let's make sure we're using the right tolerances there.
Thank you! Also, this is only half of #727. We also want to be able to handle if |
8d60d07
to
3075975
Compare
test/test_decoders.py
Outdated
) | ||
assert len(decoder) == 390 | ||
|
||
# Test get_frames_in_range |
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.
Let's add a comment here that we're really just testing the logic in the Python VideoDecoder
class when we do the decoding. We do checks that involve num_frames
at the Python layer, and that logic will use the mocked metadata. But the C++ layer does not use that mocked metadata, and will instead use what it read from the video file itself.
We should also create an issue about adding a video file that has the number of frames missing in its metadata so we can actually test the C++ logic as well. This test would then use that video file, and not need any mocking.
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.
Good point! I'll remove some unnecessary python calls here, and add a comment indicating that the python logic is the only aspect being tested.
It looks like issue #710 covers this subject.
Thanks, @Dan-Flores! I looked into the failures, and they're all known (#740, #734, #724). |
I've updated this PR to complete the other half of #727, and updated the description as well. |
This PR enables the instantiation of a VideoDecoder without certain metadata to resolve issue #727.
num_frames_from_content
ornum_frames_from_header
in the metadata, the VideoDecoder will calculate the number of frames usingaverage_fps_from_header
andduration_seconds_from_header
.duration_seconds_from_header
, orend_stream_seconds_from_content
andbegin_stream_seconds_from_content
from a scan, the VideoDecoder will calculate the duration usingnum_frames_from_header
andaverage_fps_from_header
.Tests in test_decoders.py
_get_stream_json_metadata
is mocked to ensure VideoDecoder is instantiated withoutnum_frames_from_content
ornum_frames_from_header
.get_frames_in_range
are tested.Tests in test_metadata.py
test_calculate_num_frames_using_fps_and_duration
instantiatesVideoStreamMetadata
withoutnum_frames_from_content
ornum_frames_from_header
, and checks that various values ofaverage_fps
andduration_seconds
result in the correct number of frames.In
test_num_frames_fallback
, the test where bothnum_frames_from_content
andnum_frames_from_header
areNone
is no longer valid. A similar test case is added intest_calculate_num_frames_using_fps_and_duration
.test_duration_seconds_fallback
validates that calculating metadata using a scan is prioritized over header metadata.test_calculate_duration_seconds_using_fps_and_num_frames
tests the fallback implemented in this PR.