Skip to content

C++ layer should use FPS if number of frames is missing #923

@scotts

Description

@scotts

When we report metadata at the Python layer, if we are in approximate mode and the number of frames is missing from the header, we estimate the number of frames using the FPS:

def num_frames(self) -> Optional[int]:
"""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
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
):
return int(self.average_fps_from_header * self.duration_seconds_from_header)
else:
return None

However, in C++, we don't do the same:
std::optional<int64_t> SingleStreamDecoder::getNumFrames(
const StreamMetadata& streamMetadata) {
switch (seekMode_) {
case SeekMode::custom_frame_mappings:
case SeekMode::exact:
return streamMetadata.numFramesFromContent.value();
case SeekMode::approximate: {
return streamMetadata.numFramesFromHeader;
}
default:
TORCH_CHECK(false, "Unknown SeekMode");
}
}

We should make the C++ layer have the same behavior as the Python layer. A downside here is that we don't have a test for this behavior. We've tested missing metadata in the Python layer by just overwriting values with None. To really test the C++ layer, we should get a video which is actually missing the number of frames from its metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions