Skip to content

Conversation

NicolasHug
Copy link
Contributor

@NicolasHug NicolasHug commented Mar 24, 2025

This PR does a bunch of related things:

  • We add a new begin_stream_seconds_from_header field to audio and video metadata. It is derived from the AVStream's start_time field. This field is useful e.g. in our tutorial example because it is now clear that the stream doesn't exactly starts at 0.
  • We move the begin_stream_seconds_from_content and end_stream_seconds_from_content fields as video-only: these fields are derived from a scan, so there's no point having them for audio.
  • As a consequence of that, we move the duration_seconds metadata as video-only, because it is derived from begin_stream_seconds_from_content and end_stream_seconds_from_content. This means that audio metadata now only contains duration_seconds_from_header.
  • We now allow negative start_seconds in the call to get_samples_played_in_range: the input check was based on begin_stream_seconds_from_content so that didn't make much sense. We still have tests that make sure we provide good error messages in the incorrect cases.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 24, 2025
@NicolasHug NicolasHug changed the title Rework metadata Move "scanned" metadata as video-only and add begin_stream_from_header Mar 24, 2025
from torchcodec.decoders._decoder_utils import (
create_decoder,
get_and_validate_stream_metadata,
ERROR_REPORTING_INSTRUCTIONS,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes below: we previously had a common util for audio and video that extracted and validated the metadata: get_and_validate_stream_metadata(). Since we moved a bunch of fields as video-only, this util wasn't generic enough anymore to justify its existence, hence a few edits here and in the video_decoder.py file.

if (streamMetadata.beginStreamFromHeader.has_value()) {
map["beginStreamFromHeader"] =
std::to_string(*streamMetadata.beginStreamFromHeader);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminded me to create Issue #593.

@NicolasHug NicolasHug merged commit abc9b10 into meta-pytorch:main Mar 24, 2025
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants