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

Should Media3 use media duration to calculate frame rate rather than track duration? #1531

Open
ybai001 opened this issue Jul 4, 2024 · 0 comments

Comments

@ybai001
Copy link
Contributor

ybai001 commented Jul 4, 2024

Background

When I contribute this code: #1235, I find there is a potential issue in Mp4Extractor.java.

Technical Details

(1) Using AndroidX Media to parse mp4 file. For example, one Media3 test media: https://github.com/androidx/media/blob/release/libraries/test_data/src/test/assets/media/mp4/dolbyVision-hdr.MOV

(2) This test media includes one video track with 5 samples and frame rate is 30fps (You can check it by MediaInfo or other tools.). The key point here is this mp4 file has 'elst' box with segment duration = 64 (timescale = 600, so it is ~0.107s.) If you check the "TRACK DURATION" (moov->trak->tkhd→duration), it is same. But the "MEDIA DURATION" (moov->trak->mdia->mdhd->duration) is 100 (timescale = 600, so it is ~0.167s.) All of above follow ISO spec and there is NO problem.

(3) In AndroidX Media, Mp4Extractor::processMoovAtom(), https://github.com/androidx/media/blob/release/libraries/extractor/src/main/java/androidx/media3/extractor/mp4/Mp4Extractor.java#L553, it calculates framerate by "TRACK DURATION" rather than "MEDIA DURATION", https://github.com/androidx/media/blob/release/libraries/extractor/src/main/java/androidx/media3/extractor/mp4/Mp4Extractor.java#L622
So the result is framerate = 5 / (106667/1000000) = 46.875fps, which is very different from the file's actual framerate (30fps).

(4) If the "MEDIA DURATION" is used, framerate = 5 / (166667/1000000) = 30fps, which is same as the file's actual framerate.

Thought

I think, as long as there is 'elst' box in MP4 file, the calculated frame rate will be wrong here.

Do you think we should change the behavior here (replace track duration with media duration) in Media3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants