Skip to content

Some videos' duration is missing, and they can't work with approximate mode #945

@NicolasHug

Description

@NicolasHug

Some videos, like these ones

torchcodec/test/utils.py

Lines 752 to 756 in 9fa4fd1

def supports_approximate_mode(asset: TestVideo) -> bool:
# TODONVDEC P2: open an issue about his. That's actually not related to
# NVDEC at all, those don't support approximate mode because they don't set
# a duration. CPU decoder fails too!
return asset not in (AV1_VIDEO, TEST_SRC_2_720P_VP9, TEST_SRC_2_720P_VP8)

simply do not work with approximate mode. They're all missing the duration_from_header metadata because avStream->duration is invalid here:

if (avStream->duration > 0 && avStream->time_base.den > 0) {
streamMetadata.durationSecondsFromHeader =
ptsToSeconds(avStream->duration, avStream->time_base);
}

and they end up failing with:

if metadata.end_stream_seconds is None:
raise ValueError(
"The maximum pts value in seconds is unknown. "
+ ERROR_REPORTING_INSTRUCTIONS
)

which isn't a particularly helpful error message, especially since ERROR_REPORTING_INSTRUCTIONS says:

ERROR_REPORTING_INSTRUCTIONS = """
This should never happen. Please report an issue following the steps in
https://github.com/pytorch/torchcodec/issues/new?assignees=&labels=&projects=&template=bug-report.yml.
"""


We should, at the very least, provide a more sensible error message. But we should also probably try to figure what we can do with those videos to support approximate mode. ffprobe is able to report the duration of those videos: we should try to see if they're able to report it without scanning.

And if really, we conclude that they can't support approximate mode, we should probably automatically fallback to exact mode (CC @scotts as this was your idea!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions