-
Notifications
You must be signed in to change notification settings - Fork 423
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
Extract MP4 metadata-based chapters #1851
base: main
Are you sure you want to change the base?
Conversation
String chapterName = chpl.readString(titleLength); | ||
ChapterFrame chapterFrame = | ||
new ChapterFrame( | ||
/* chapterId= */ Integer.toString(i), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure if something else or perhaps C.INDEX_UNSET
should be used as the ID. MP4 chapters do not have this concept.
colorTransfer = 3 | ||
lumaBitdepth = 8 | ||
chromaBitdepth = 8 | ||
metadata = entries=[TSSE: description=null: values=[Lavf61.1.100], CHAP, CHAP, CHAP, Mp4Timestamp: creation time=0, modification time=0, timescale=1000] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line asserts that the chapters are detected in the file.
libraries/extractor/src/test/java/androidx/media3/extractor/mp4/BoxParserTest.java
Outdated
Show resolved
Hide resolved
…4/BoxParserTest.java
This PR adds extraction of metadata-based MP4 chapters. It is a follow-up to the issue in the old ExoPlayer repository: google/ExoPlayer#2316. I used the suggestion from this comment.
In the current solution, I only create
ChapterFrame
s and do not useChapterTOCFrame
, but I'm open to adding it if necessary.Specification
It is quite difficult to find reliable documentation around MP4 chapters. The best document describing them I found is this one. I attached the relevant part of the documentation at the bottom of this PR.
In summary, there are two types of chapters: QuickTime chapters, which are multiplexed into the data stream itself, and Nero chapters, which use a classic metadata approach. This PR handles only these chapters. To the best of my knowledge, most of M4A editors embed both types of chapters in the media files.
Test Data
I created the test sample in the following way:
sample_empty_track.mp4
.ffmpeg -i sample_empty_track.mp4 -f ffmetadata sample-metadata.txt
.sample-metadata.txt
file with these chapters:ffmpeg -i sample_empty_track.mp4 -i sample-metadata.txt -map_metadata 1 -codec copy sample_with_chapters.mp4
and used thesample_with_chapters.mp4
file in tests.MP4 metadata-based chapter specification
"Nero" chapters are an alternative to Quicktime chapters implemented by Nero software suite. It aims at providing a simpler, metadata-based chapter description akin to Vorbis chapters.
They are implemented as a specific atom located at moov.udta.chpl
The contents of the atom is as follows
(1) : Big-Endian convention
To my knowledge, understanding of Nero chapters comes from retro-engineering, as there are no official specifications.
NB1 : Quicktime player, iTunes and the built-in iOS audiobook player support Quicktime chapters only, and ignore Nero chapters entirely.
NB2 : Some players such as VLC seem to fail reading Nero chapters properly when there are more than 255 of them, for instance on (very) long audiobooks. As the Nero structure actually allows for any number of chapters to be written, I'm unsure if this is a bug or a part of the Nero standard I'm unaware of...