title: Sending periodic metadata in fragmented live MP4 stream?
body: <p>As suggested by the topic, I'm wondering if it's possible to send metadata about the stream contents periodically in a fragmented MP4 live stream.</p>
  
  <p>I'm using the following command (1) to get fragmented MP4:</p>
  
  <pre><code>ffmpeg -i rtsp://admin:12345@192.168.0.157 -c:v copy -an -movflags empty_moov+omit_tfhd_offset+frag_keyframe+default_base_moof -f mp4 ...
  </code></pre>
  
  <p>My <strong>main program</strong> reads the fragments from this command from either stdout or from a (unix domain) socket and gets:</p>
  
  <pre><code>ftyp
  moov
  moof
  mdat
  moof
  mdat
  moof
  mdat 
  ...
  </code></pre>
  
  <p>So, the first fragments I get are <strong>ftyp</strong> and <strong>moov</strong> which are metadata and describe the stream contents.</p>
  
  <p>Now a <strong>client program</strong> connects at a later time to the <strong>main program</strong>.  The problem is, that at that point, the <strong>ftype</strong> and <strong>moov</strong> fragments are long gone.</p>
  
  <p><em>Is there a way (=ffmpeg command option) to make this work similar to MPEGTS (aka mpeg transport stream), and resend metadata periodically with the stream?</em>  Like this:</p>
  
  <pre><code>ftyp
  moov
  moof
  mdat
  moof
  mdat
  moof
  mdat 
  ftyp
  moov
  moof
  mdat
  moof
  mdat
  moof
  mdat 
  ...
  </code></pre>
  
  <p>.. or is my only option to cache the <strong>ftyp</strong> and <strong>moov</strong> packets in my <strong>main program</strong> and re-send them to the <strong>client program</strong> when it requests the stream?</p>
  
  <p>A related link: <a href="https://stackoverflow.com/questions/35177797/what-exactly-is-fragmented-mp4fmp4-how-is-it-different-from-normal-mp4">What exactly is Fragmented mp4(fMP4)? How is it different from normal mp4?</a></p>
  
  <p>Caching and resending <strong>ftyp</strong> and <strong>moov</strong> each time a new client connects is not that straightforward either .. as it somehow brokes the stream (at least the browser MSE extensions don't like such a stream).  There seems to be lots of sequence numbers and stuff in the <strong>moof</strong> packets that should be modified. <strong>(+)</strong></p>
  
  <p>Another option is to pass the stream through another FFmpeg process that does the remuxing (and corrects <strong>moof</strong> packets).  Things are further complicated by the fact that command (1) does not give cleanly-separated <strong>ftyp</strong>, <strong>moov</strong>, <strong>moof</strong>, etc. packets.</p>
  
  <p>Any thoughts / solutions appreciated.</p>
  
  <p><strong>EDIT</strong> : regarding <strong>(+)</strong>, MSE seems to have problems playing fragmented MP4 with gaps: <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=516114" rel="nofollow noreferrer">https://bugs.chromium.org/p/chromium/issues/detail?id=516114</a></p>