title: Copy chapters in MP4 input stream to output stream in ffmpeg
body: <p>I'm using ffmpeg to copy two MP4 input streams into one output container and I'm having trouble maintaining the chapter indexes from both files into the output stream.</p>
  
  <p>I have two files, specified by <code>streams.txt</code> which is in the correct format, that both contain an H.264 video stream, an AC-3 audio stream and an AAC audio stream, and am concatenating the two files using the following <code>ffmpeg</code> command:</p>
  
  <pre><code>ffmpeg -f concat -safe 0 -i streams.txt -map 0:0 -map 0:1 -map 0:2 -c:v copy -c:a:0 copy -c:a:1 copy output.mp4
  </code></pre>
  
  <p>This correctly produces the output file that I want, with both files combined into an output file with all three streams. I am however having trouble adding the chapters from both input files into the output one. I understand that I'm supposed to use the <code>-map_metadata</code> option, but I'm having trouble with the format of it that doesn't produce the following error message:</p>
  
  <pre><code>Invalid chapter index 0 while processing metadata maps.
  </code></pre>