-
Notifications
You must be signed in to change notification settings - Fork 46
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
Changes from all commits
2c7722f
8167eb2
0ae588f
e71ab06
38aa16b
d6b2ef0
e94fc04
3b0d4ed
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 |
---|---|---|
|
@@ -85,17 +85,27 @@ class VideoStreamMetadata(StreamMetadata): | |
def duration_seconds(self) -> Optional[float]: | ||
"""Duration of the stream in seconds. We try to calculate the duration | ||
from the actual frames if a :term:`scan` was performed. Otherwise we | ||
fall back to ``duration_seconds_from_header``. | ||
fall back to ``duration_seconds_from_header``. If that value is also None, | ||
we instead calculate the duration from ``num_frames_from_header`` and | ||
``average_fps_from_header``. | ||
""" | ||
if ( | ||
self.end_stream_seconds_from_content is None | ||
or self.begin_stream_seconds_from_content is None | ||
self.end_stream_seconds_from_content is not None | ||
and self.begin_stream_seconds_from_content is not None | ||
): | ||
return ( | ||
self.end_stream_seconds_from_content | ||
- self.begin_stream_seconds_from_content | ||
) | ||
elif self.duration_seconds_from_header is not None: | ||
return self.duration_seconds_from_header | ||
return ( | ||
self.end_stream_seconds_from_content | ||
- self.begin_stream_seconds_from_content | ||
) | ||
elif ( | ||
self.num_frames_from_header is not None | ||
and self.average_fps_from_header is not None | ||
): | ||
return self.num_frames_from_header / self.average_fps_from_header | ||
else: | ||
return None | ||
|
||
@property | ||
def begin_stream_seconds(self) -> float: | ||
|
@@ -123,14 +133,22 @@ def end_stream_seconds(self) -> Optional[float]: | |
|
||
@property | ||
def num_frames(self) -> Optional[int]: | ||
"""Number of frames in the stream. This corresponds to | ||
``num_frames_from_content`` if a :term:`scan` was made, otherwise it | ||
corresponds to ``num_frames_from_header``. | ||
"""Number of frames in the stream (int or None). | ||
This corresponds to ``num_frames_from_content`` if a :term:`scan` was made, | ||
otherwise it corresponds to ``num_frames_from_header``. If that value is also | ||
None, the number of frames is calculated from the duration and the average fps. | ||
""" | ||
if self.num_frames_from_content is not None: | ||
return self.num_frames_from_content | ||
else: | ||
elif self.num_frames_from_header is not None: | ||
return self.num_frames_from_header | ||
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 commentThe 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 |
||
return int(self.average_fps_from_header * self.duration_seconds_from_header) | ||
else: | ||
return None | ||
|
||
@property | ||
def average_fps(self) -> Optional[float]: | ||
|
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.