MP4 files can store chapters in a Nero chpl list or in QuickTime chapter tracks. OneMedia reads only the Nero list, so it returns no chapters for files with only a QuickTime chapter track. Try chapters.mp4 from the zip.
dotnet add package RecursiveAI.OneMediaRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneMedia; using var media = Media.Open("chapters.mp4"); foreach (var chapter in media.Metadata.Chapters) Console.WriteLine("{0:c} {1}", chapter.Start.ToTimeSpan(), chapter.Title);
Prints each start time and title:
00:00:00 Opening 00:00:01.2500000 Closing
Unzip the example, then dotnet run.
The full program
The sample is a three-second solid-color clip with no audio and only a Nero chapter list. To open your own file, run dotnet run -- "my video.mp4".
using RecursiveAI.OneMedia; string path = args.Length > 0 ? args[0] : "chapters.mp4"; using var media = Media.Open(path); var chapters = media.Metadata.Chapters; if (chapters.Count == 0) { Console.WriteLine("No Nero chapter markers found."); return; } foreach (var chapter in chapters) { var start = chapter.Start.ToTimeSpan(); Console.WriteLine($"{start:c} {chapter.Title}"); }
00:00:00 Opening 00:00:01.2500000 Closing
If no supported list is found, Chapters is empty; the full program prints No Nero chapter markers found.
Variations
Print decimal seconds instead of a clock time. In the full program’s loop, replace the two lines inside the braces with:
var seconds = chapter.Start.ToTimeSpan().TotalSeconds; Console.WriteLine(FormattableString.Invariant( $"{seconds:0.#######}\t{chapter.Title}"));
This prints 0 and 1.25 before the corresponding titles, separated by a tab.
Related recipes
The short answer
Open the MP4 with Media.Open and enumerate media.Metadata.Chapters. Each entry gives you a Title and a Start. Convert Start to a TimeSpan to print it as elapsed time, or use the decimal-seconds variation above for a tab-separated list. The reader is for Nero chapter lists. An empty result means it found no readable Nero markers, not necessarily that a player will show no chapters.
Does MP4 support chapter markers?
Yes. The OneMedia metadata docs describe two forms to distinguish: a Nero chpl list stores titles and start times together, while a QuickTime text chapter track is a separate track. OneMedia 1.0.2 reads the Nero form and does not read QuickTime text chapter tracks or Matroska Chapters elements. Changing the filename extension does not change how the markers are stored.
If a player lists chapters but this program prints none, check how the file was authored. A Nero list and a QuickTime chapter track can coexist; the sample in this recipe contains only the list. For an app that reads files from different sources, report “No Nero chapter markers found” rather than “This video has no chapters.” That distinguishes what the reader returned from what the file may contain.
How do I extract chapter timestamps from an MP4?
Use Start as a position on the video timeline, not as the length of the chapter. Nero version 1 stores each start in 100-nanosecond units and each title as length-prefixed UTF-8. Here the second marker starts one and a quarter seconds into the clip. The TimeSpan c format prints 00:00:01.2500000; the decimal variation prints the same position as 1.25 seconds. Both avoid rounding the start to a whole second.
Chapter has no end timestamp. A list of chapter starts is enough to build a menu or an index of jump points, but it is not a list of clip ranges. If you treat each chapter as running until the next marker, that is a boundary you infer. For the last chapter you would need a separate endpoint, such as the duration of the video you’re indexing. Keep the original start values rather than parsing back the strings you print for display.