Skip to content
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

Handle Partially Corrupted Videos #505

Open
phuturesh opened this issue Feb 8, 2025 · 2 comments
Open

Handle Partially Corrupted Videos #505

phuturesh opened this issue Feb 8, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@phuturesh
Copy link

🚀 The feature

In the scanning procedure, a video corruption may stop scanning, and it will fall on an Error in the decoding procedure. I expect the scanning process to be more robust, allowing it to ignore such corruptions and continue scanning the remaining frames.

Motivation, pitch

As mentioned in #165, I will repeat my comment here for clarity:

Currently, the VideoDecoder may raise a RuntimeError or other exceptions when decoding videos that are partially corrupted. During the scanning process, it seems to just stop upon encountering the first error.

Ex. In a video containing 10,000 frames with corruption around the 4,000th frame, VideoDecoder._num_frames will only be about 4,000. The last 6,000 frames are discarded and we can not access them through VideoDecoder.

The thing is many real-world videos contain partial corruptions, yet various media players manage to ignore this and play them like there are no errors. Now the implementation of VideoDecoder may not properly align with this approach.

There may be a potential solution. In the scanning process we should somehow get the ``true'' num_frames. And in the decoding process, we can either

  1. ignore a corrupted frame and return a 0 tensor.
  2. or raise an Error, so programmers are to handle it. I prefer this one.
@phuturesh
Copy link
Author

phuturesh commented Feb 9, 2025

The above unexpected behavior seems to be a bug triggered when reading from bytes:

with open('xxx.mp4', "rb") as f:
    raw_video_bytes = f.read()
from torchcodec.decoders import VideoDecoder
decoder = VideoDecoder(raw_video_bytes, device='cuda')

The _num_frames is as expected when directly reading from a file path like:
decoder = VideoDecoder('xxx.mp4', device='cuda')

@scotts
Copy link
Contributor

scotts commented Feb 27, 2025

@phuturesh, can you point us to a video that triggers this behavior?

@scotts scotts added the enhancement New feature or request label Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants