(Chapter) markers in a media file

Is it possible to read (chapter)markers from a media file?

For a project I’m working on, I have an audio track, in an MP4 (M4A) file, that supports chapter markers.
I use those markers to define loop-points, where I want the music to jump to a specific point in the audio to continue.

I edit the audio in video-editing software I use on a daily base. When I export it, I know that the cue-points are being exported. Because, when I import it again, it shows the markers. And when I open the audio file in a HEX editor, I can clearly see those markers.

The reason I choose this approach, is that it makes it easier to set those markers: right in the software I edit the tracks.

I have tried some MBS classes. But I can’t seem to find a method or property where I can get access to the markers. They are clearly in the file. So, somehow, it must be possible to extract the data, right?

If you’re using the MBS VLC plugin look at VLCMediaMBS.SubItems. (The corresponding property in my open source libvlc wrapper for Xojo is Medium.Subitems)

In both cases, “Subitems” is a playlist of tracks/chapters/etc. within a single media file.

I forgot to mention that the app I’m working on is for iOS. The VLC plugin isn’t supported. But that would have been a good solution.

When I look closely at the HEX editor, I see the words trackName="markers"
Somhow that makes me think that there is an extra track that holds these timed metadata.

But when I iterate through the tracks, in the MBS Audio Plugins, I only see 1 track, the audio track.

I haven’t tried this in iOS, but you should be able to adapt it since AVTimedMetadataGroupMBS and AVAssetMBS are both iOS compatible

Dim f As FolderItem = SpecialFolder.Desktop.Child("Whats Up by 4 Non Blondes   Easy Guitar Lesson.mp4")

if not f.Exists then
  MsgBox "This app looks for this file on your desktop..."
  break
  quit
  Return
End If


Dim a As AVAssetMBS = AVAssetMBS.assetWithFile(f)
//language code = "en"

Var s() As AVTimedMetadataGroupMBS

If a.chapterMetadataGroupsBestMatchingPreferredLanguages <> Nil Then
  
  s = a.chapterMetadataGroupsBestMatchingPreferredLanguages
  
  
  If s.Count <> 0 Then
    
    Var allChapters As String
    
    For i As Integer = 0 To s.LastIndex
      Var v() As AVMetadataItemMBS = s(i).items
      Var t As CMTimeMBS = v(0).time
      Var b As String = v(0).stringValue
      Var n As Double = t.Seconds
      
      
      ListboxChapters.AddRow Timestamp(t.Seconds), v(0).stringValue
      
      
    Next i
    
  End If
  
End If

The result when running the code:

Now if only I could figure out how to add Chapter Markers to a video file, I’d be all set!

1 Like

I played with AVTimedMetadataGroupMBS a bit. But in my case it returned an empty array. I might have missed something. I will check it out later. Thanks!

I am a freelance cameraman and video editor. Besides AVID I use Adobe Premiere a lot.
I added the chapter markers as sequence markers on my timeline. Just make sure you select the option “chapter marker” in the marker dialogue. At the top you can name the chapter.
When exporting the video, make sure you enable the markers in the metadata tab. I selected Sidecar File. But with MP4 the metadata will be embedded within the file, as you might want.

But, in case you don’t have the Adobe Package, there are alternatives. Like the free apps ChapterMaker or Drax for Windows
Or a paid mChapters app for Mac. A free Mac App is Chapter Maker 2.0.

But Google is your best friend in finding a solution.

ZSolrry - I meant how to add chapter markers to a video file in Xojo using AVTimedMetadataGroupMBS and AVAssetMBS.

I currently copy chapter marker information from YouTube, paste into an app I wrote to convert it to a chapter marker text file, and then open the video in Subler and add the marker text file.
Subler embeds the chapter marker data into the video file without re-exporting the entire video file.

Now I have a video with chapter markers, just like the original YouTube Video.

Ah, well…
I read somewhere about Mutable Metadata, or something like that. I think, that is where you might have to look.

EDIT: I’m not sure, but AVMutableTimedMetadataGroupMBS might be the class you’re looking for.
I have not tried it yet. And I have no clue how it works.

Weirdly, “chapterMetadataGroupsBestMatchingPreferredLanguages” returns an empty array. :thinking:

EDIT:
After some digging around in the Hex Editor, I found that the chapters where actually XMP values. MBS has a plugin for that. Bonus: it is MacOS and iOS compatible. My guess is that I can find my chapters using that XMP plugin