Better error message if metadata is missing in approximate mode #540
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We haven't had this problem yet for videos, but as I'm developing audio support I started hitting some "bad optional access" errors. In my case, it was due to this bad access:
https://github.com/pytorch/torchcodec/blob/b7271fa66c0c1127144f2e4149c974a30ca75a3a/src/torchcodec/decoders/_core/VideoDecoder.cpp#L1594-L1595
We set the value here, when the decoder is created:
https://github.com/pytorch/torchcodec/blob/b7271fa66c0c1127144f2e4149c974a30ca75a3a/src/torchcodec/decoders/_core/VideoDecoder.cpp#L155-L158
Turns out that this value doesn't exist for our audio mp3 test file.
This PR changes the un-informative error message into something more informative. Note that we have to do the checks / enforcements at the very last moment instead of when the decoder is initiated (and when those fields are set), because that would prevent us from returning metadata in approximate mode.