title: Add TOC chapters to MP4 with GStreamer 1.18 (VS2015)
body: <p><br />
  How can I add chapters to MP4 files with GStreamer 1.18?</p>
  <p>I have a Visual Studio 2015 C++ project that writes a video (H264) and audio (aac) stream to the disk using mp4mux. Now I would like to add chapters to the MP4 file that are compatible with regular video players like VLC.</p>
  <p>I have tried to follow the <a href="https://gstreamer.freedesktop.org/documentation/additional/design/toc.html?gi-language=c#implementation-coverage-specifications-" rel="nofollow noreferrer">documentation</a> to create a <code>GstToc</code> and a dummy <code>GstTocEntry</code>, but it doesn't appear to be written to the file:</p>
  <pre><code>GstToc* toc = gst_toc_new(GstTocScope::GST_TOC_SCOPE_CURRENT);
  GstTocEntry* new_entry = gst_toc_entry_new(GstTocEntryType::GST_TOC_ENTRY_TYPE_CHAPTER, &quot;some_uid&quot;);
  gst_toc_entry_set_start_stop_times(new_entry, 0, 50);
  gst_toc_append_entry(toc, new_entry);
  </code></pre>
  <p>I then also tried to generate a new toc event and pass it to the video GstElement <code>vin</code>:</p>
  <pre><code>gboolean result = gst_element_send_event(vin, gst_event_new_toc(toc, true));
  </code></pre>
  <p>Did I miss anything in order to map the GstToc to the video stream? Do I need to tell mp4mux to process the toc? Or is this not supported?<br />
  GStreamer documentation seems to imply, that there is <a href="https://gstreamer.freedesktop.org/documentation/additional/design/toc.html?gi-language=c#implementation-coverage-specifications-" rel="nofollow noreferrer">GstToc support</a> in mp4mux:</p>
  <blockquote>
  <p>Below hollow bullet point o indicate no support and filled bullets ***
  indicate that this feature is handled.</p>
  <p><strong>MP4: * elst</strong><br />
  The elst atom contains a list of edits. Each edit consists of (length, start, play-back speed).</p>
  </blockquote>
  <p>I didn't find much on the <em>elst atom</em> or what an <em>edit</em> is. I tried using <code>GST_TOC_ENTRY_TYPE_EDITION</code> instead of <code>GST_TOC_ENTRY_TYPE_CHAPTER</code>, but that didn't change anything.</p>
  <p><a href="https://gstreamer.freedesktop.org/GSOC/chaptersupport.html" rel="nofollow noreferrer">This page</a> mentions &quot;preliminary code in MP4 supporting chapters&quot; in GStreamer.</p>
  <p>I have seen ways to inject metadata files into existing mp4 files with ffmpeg and other tools which are not available on our system unfortunately. I could try to inject the chapters into the mp4 file header manually, but I'd very much like to avoid this post-processing step for obvious reasons. Any help would be greatly appreciated!</p>