<p>The metadata from an input file in any ffmpeg operation is used to interpret and handle the media data in that file. That metadata is not naively copied over, wholesale or piecemeal*. FFmpeg will always generate new metadata based on the specific set of media data received when generating the output. Since the output of concat operation is one file, it will have one moov box. If you want the concat output file to have moov box up front, you will have to add <code>-movflags +faststart</code>.</p>
<p>*exception is string tags such as ID3 or timecode data.</p>

CC BY-SA 4.0
2021-02-08T18:26:35.410Z
Thanks @Gyan I appreciate the response. This is good insight to know.
julesverne
CC BY-SA 4.0
2021-02-08T04:54:42.753Z
2021-02-08T04:54:42.753Z
Gyan
<p>Years ago I asked this question on: <a href="https://stackoverflow.com/questions/18474312/concatenate-join-mp4-files-using-ffmpeg-and-windows-command-line-batch-not-lin">stackoverflow</a> about correct syntax using the <strong>ffmpeg</strong> <code>Concat demuxer</code> to join mp4 files together. One question I hadn't thought to ask at the time was, when joining mp4s that have been encoded by ffmpeg with <code>-movflags +faststart</code> what happens to each joined file's moov atom? Is there only one now? Is the moov still at the top?</p>
<p>Ex: file1.mp4 and file2.mp4 both encoded with ffmpeg using <code>-movflags +faststart</code> and then are joined together using ffmpeg <code>concat demuxer</code> to create all.mp4</p>
<p>I did some investigative work but I'm not very knowledgeable and wanted a definite answer rather than my own assumption. Using the example above I compared the output for &quot;file1.mp4&quot; using atomic parsley and compared it to the output of &quot;all.mp4&quot; and it appears to me that the .moov atom is not in the &quot;faststart&quot; position.</p>
<p><strong>file1.mp4 output</strong></p>
<pre><code>Atom ftyp @ 0 of size: 32, ends @ 32
Atom moov @ 32 of size: 8067606, ends @ 8067638
     Atom mvhd @ 40 of size: 108, ends @ 148
     Atom trak @ 148 of size: 5898695, ends @ 5898843
         Atom tkhd @ 156 of size: 92, ends @ 248
         Atom edts @ 248 of size: 36, ends @ 284
             Atom elst @ 256 of size: 28, ends @ 284
         Atom mdia @ 284 of size: 5898559, ends @ 5898843
             Atom mdhd @ 292 of size: 32, ends @ 324
             Atom hdlr @ 324 of size: 45, ends @ 369
             Atom minf @ 369 of size: 5898474, ends @ 5898843
                 Atom vmhd @ 377 of size: 20, ends @ 397
                 Atom dinf @ 397 of size: 36, ends @ 433
                     Atom dref @ 405 of size: 28, ends @ 433
                 Atom stbl @ 433 of size: 5898410, ends @ 5898843
                     Atom stsd @ 441 of size: 150, ends @ 591
                         Atom avc1 @ 457 of size: 134, ends @ 591
                             Atom avcC @ 543 of size: 48, ends @ 591
                     Atom stts @ 591 of size: 24, ends @ 615
                     Atom stss @ 615 of size: 5584, ends @ 6199
                     Atom ctts @ 6199 of size: 2502720, ends @ 2508919
                     Atom stsc @ 2508919 of size: 1047220, ends @ 3556139
                     Atom stsz @ 3556139 of size: 1258620, ends @ 4814759
                     Atom stco @ 4814759 of size: 1084084, ends @ 5898843
     Atom trak @ 5898843 of size: 2168697, ends @ 8067540
         Atom tkhd @ 5898851 of size: 92, ends @ 5898943
         Atom edts @ 5898943 of size: 36, ends @ 5898979
             Atom elst @ 5898951 of size: 28, ends @ 5898979
         Atom mdia @ 5898979 of size: 2168561, ends @ 8067540
             Atom mdhd @ 5898987 of size: 32, ends @ 5899019
             Atom hdlr @ 5899019 of size: 45, ends @ 5899064
             Atom minf @ 5899064 of size: 2168476, ends @ 8067540
                 Atom smhd @ 5899072 of size: 16, ends @ 5899088
                 Atom dinf @ 5899088 of size: 36, ends @ 5899124
                     Atom dref @ 5899096 of size: 28, ends @ 5899124
                 Atom stbl @ 5899124 of size: 2168416, ends @ 8067540
                     Atom stsd @ 5899132 of size: 106, ends @ 5899238
                         Atom mp4a @ 5899148 of size: 90, ends @ 5899238
                             Atom esds @ 5899184 of size: 54, ends @ 5899238
                     Atom stts @ 5899238 of size: 32, ends @ 5899270
                     Atom stsc @ 5899270 of size: 40, ends @ 5899310
                     Atom stsz @ 5899310 of size: 1084092, ends @ 6983402
                     Atom stco @ 6983402 of size: 1084084, ends @ 8067486
                     Atom sgpd @ 8067486 of size: 26, ends @ 8067512                     ~
                     Atom sbgp @ 8067512 of size: 28, ends @ 8067540
     Atom udta @ 8067540 of size: 98, ends @ 8067638
         Atom meta @ 8067548 of size: 90, ends @ 8067638
             Atom hdlr @ 8067560 of size: 33, ends @ 8067593
             Atom ilst @ 8067593 of size: 45, ends @ 8067638
                 Atom ©too @ 8067601 of size: 37, ends @ 8067638
                     Atom data @ 8067609 of size: 29, ends @ 8067638
Atom free @ 8067638 of size: 8, ends @ 8067646
Atom mdat @ 8067646 of size: 403164726, ends @ 411232372
</code></pre>
<p><strong>all.mp4 output</strong></p>
<pre><code>Atom ftyp @ 0 of size: 32, ends @ 32
Atom free @ 32 of size: 8, ends @ 40
Atom mdat @ 40 of size: 197417544, ends @ 197417584
Atom moov @ 197417584 of size: 5203090, ends @ 202620674
     Atom mvhd @ 197417592 of size: 108, ends @ 197417700
     Atom trak @ 197417700 of size: 3803979, ends @ 201221679
         Atom tkhd @ 197417708 of size: 92, ends @ 197417800
         Atom edts @ 197417800 of size: 48, ends @ 197417848
             Atom elst @ 197417808 of size: 40, ends @ 197417848
         Atom mdia @ 197417848 of size: 3803831, ends @ 201221679
             Atom mdhd @ 197417856 of size: 32, ends @ 197417888
             Atom hdlr @ 197417888 of size: 45, ends @ 197417933
             Atom minf @ 197417933 of size: 3803746, ends @ 201221679
                 Atom vmhd @ 197417941 of size: 20, ends @ 197417961
                 Atom dinf @ 197417961 of size: 36, ends @ 197417997
                     Atom dref @ 197417969 of size: 28, ends @ 197417997
                 Atom stbl @ 197417997 of size: 3803682, ends @ 201221679
                     Atom stsd @ 197418005 of size: 150, ends @ 197418155
                         Atom avc1 @ 197418021 of size: 134, ends @ 197418155
                             Atom avcC @ 197418107 of size: 48, ends @ 197418155
                     Atom stts @ 197418155 of size: 104, ends @ 197418259
                     Atom stss @ 197418259 of size: 3464, ends @ 197421723
                     Atom ctts @ 197421723 of size: 1613944, ends @ 199035667
                     Atom stsc @ 199035667 of size: 675328, ends @ 199710995
                     Atom stsz @ 199710995 of size: 811620, ends @ 200522615
                     Atom stco @ 200522615 of size: 699064, ends @ 201221679
     Atom trak @ 201221679 of size: 1398897, ends @ 202620576
         Atom tkhd @ 201221687 of size: 92, ends @ 201221779
         Atom edts @ 201221779 of size: 36, ends @ 201221815
             Atom elst @ 201221787 of size: 28, ends @ 201221815
         Atom mdia @ 201221815 of size: 1398761, ends @ 202620576
             Atom mdhd @ 201221823 of size: 32, ends @ 201221855
             Atom hdlr @ 201221855 of size: 45, ends @ 201221900
             Atom minf @ 201221900 of size: 1398676, ends @ 202620576
                 Atom smhd @ 201221908 of size: 16, ends @ 201221924
                 Atom dinf @ 201221924 of size: 36, ends @ 201221960
                     Atom dref @ 201221932 of size: 28, ends @ 201221960
                 Atom stbl @ 201221960 of size: 1398616, ends @ 202620576
                     Atom stsd @ 201221968 of size: 106, ends @ 201222074
                         Atom mp4a @ 201221984 of size: 90, ends @ 201222074
                             Atom esds @ 201222020 of size: 54, ends @ 201222074
                     Atom stts @ 201222074 of size: 112, ends @ 201222186
                     Atom stsc @ 201222186 of size: 160, ends @ 201222346
                     Atom stsz @ 201222346 of size: 699112, ends @ 201921458
                     Atom stco @ 201921458 of size: 699064, ends @ 202620522
                     Atom sgpd @ 202620522 of size: 26, ends @ 202620548                         ~
                     Atom sbgp @ 202620548 of size: 28, ends @ 202620576
     Atom udta @ 202620576 of size: 98, ends @ 202620674
         Atom meta @ 202620584 of size: 90, ends @ 202620674
             Atom hdlr @ 202620596 of size: 33, ends @ 202620629
             Atom ilst @ 202620629 of size: 45, ends @ 202620674
                 Atom ©too @ 202620637 of size: 37, ends @ 202620674
                     Atom data @ 202620645 of size: 29, ends @ 202620674
</code></pre>
<p>Can anyone with moov knowledge prove my assumption right or wrong? If I'm right and ffmpeg concat does not automatically assume to move the moov atom to the top should I change my approach and add -movflags +faststart to the concat demuxer command?</p>

<ffmpeg><mp4><concatenation>
Does ffmpeg concat demuxer update the position of the moov atom if present in each video file?
julesverne
# Does ffmpeg concat demuxer update the position of the moov atom if present in each video file?

(Asked by: username_0 on 2021-02-07)

Years ago I asked this question on: stackoverflow about correct syntax using the ffmpeg Concat demuxer to join mp4 files together. One question I hadn't thought to ask at the time was, when joining mp4s that have been encoded by ffmpeg with -movflags +faststart what happens to each joined file's moov atom? Is there only one now? Is the moov still at the top?
Ex: file1.mp4 and file2.mp4 both encoded with ffmpeg using -movflags +faststart and then are joined together using ffmpeg concat demuxer to create all.mp4
I did some investigative work but I'm not very knowledgeable and wanted a definite answer rather than my own assumption. Using the example above I compared the output for "file1.mp4" using atomic parsley and compared it to the output of "all.mp4" and it appears to me that the .moov atom is not in the "faststart" position.
file1.mp4 output
Atom ftyp @ 0 of size: 32, ends @ 32
Atom moov @ 32 of size: 8067606, ends @ 8067638
     Atom mvhd @ 40 of size: 108, ends @ 148
     Atom trak @ 148 of size: 5898695, ends @ 5898843
         Atom tkhd @ 156 of size: 92, ends @ 248
         Atom edts @ 248 of size: 36, ends @ 284
             Atom elst @ 256 of size: 28, ends @ 284
         Atom mdia @ 284 of size: 5898559, ends @ 5898843
             Atom mdhd @ 292 of size: 32, ends @ 324
             Atom hdlr @ 324 of size: 45, ends @ 369
             Atom minf @ 369 of size: 5898474, ends @ 5898843
                 Atom vmhd @ 377 of size: 20, ends @ 397
                 Atom dinf @ 397 of size: 36, ends @ 433
                     Atom dref @ 405 of size: 28, ends @ 433
                 Atom stbl @ 433 of size: 5898410, ends @ 5898843
                     Atom stsd @ 441 of size: 150, ends @ 591
                         Atom avc1 @ 457 of size: 134, ends @ 591
                             Atom avcC @ 543 of size: 48, ends @ 591
                     Atom stts @ 591 of size: 24, ends @ 615
                     Atom stss @ 615 of size: 5584, ends @ 6199
                     Atom ctts @ 6199 of size: 2502720, ends @ 2508919
                     Atom stsc @ 2508919 of size: 1047220, ends @ 3556139
                     Atom stsz @ 3556139 of size: 1258620, ends @ 4814759
                     Atom stco @ 4814759 of size: 1084084, ends @ 5898843
     Atom trak @ 5898843 of size: 2168697, ends @ 8067540
         Atom tkhd @ 5898851 of size: 92, ends @ 5898943
         Atom edts @ 5898943 of size: 36, ends @ 5898979
             Atom elst @ 5898951 of size: 28, ends @ 5898979
         Atom mdia @ 5898979 of size: 2168561, ends @ 8067540
             Atom mdhd @ 5898987 of size: 32, ends @ 5899019
             Atom hdlr @ 5899019 of size: 45, ends @ 5899064
             Atom minf @ 5899064 of size: 2168476, ends @ 8067540
                 Atom smhd @ 5899072 of size: 16, ends @ 5899088
                 Atom dinf @ 5899088 of size: 36, ends @ 5899124
                     Atom dref @ 5899096 of size: 28, ends @ 5899124
                 Atom stbl @ 5899124 of size: 2168416, ends @ 8067540
                     Atom stsd @ 5899132 of size: 106, ends @ 5899238
                         Atom mp4a @ 5899148 of size: 90, ends @ 5899238
                             Atom esds @ 5899184 of size: 54, ends @ 5899238
                     Atom stts @ 5899238 of size: 32, ends @ 5899270
                     Atom stsc @ 5899270 of size: 40, ends @ 5899310
                     Atom stsz @ 5899310 of size: 1084092, ends @ 6983402
                     Atom stco @ 6983402 of size: 1084084, ends @ 8067486
                     Atom sgpd @ 8067486 of size: 26, ends @ 8067512                     ~
                     Atom sbgp @ 8067512 of size: 28, ends @ 8067540
     Atom udta @ 8067540 of size: 98, ends @ 8067638
         Atom meta @ 8067548 of size: 90, ends @ 8067638
             Atom hdlr @ 8067560 of size: 33, ends @ 8067593
             Atom ilst @ 8067593 of size: 45, ends @ 8067638
                 Atom ©too @ 8067601 of size: 37, ends @ 8067638
                     Atom data @ 8067609 of size: 29, ends @ 8067638
Atom free @ 8067638 of size: 8, ends @ 8067646
Atom mdat @ 8067646 of size: 403164726, ends @ 411232372

all.mp4 output
Atom ftyp @ 0 of size: 32, ends @ 32
Atom free @ 32 of size: 8, ends @ 40
Atom mdat @ 40 of size: 197417544, ends @ 197417584
Atom moov @ 197417584 of size: 5203090, ends @ 202620674
     Atom mvhd @ 197417592 of size: 108, ends @ 197417700
     Atom trak @ 197417700 of size: 3803979, ends @ 201221679
         Atom tkhd @ 197417708 of size: 92, ends @ 197417800
         Atom edts @ 197417800 of size: 48, ends @ 197417848
             Atom elst @ 197417808 of size: 40, ends @ 197417848
         Atom mdia @ 197417848 of size: 3803831, ends @ 201221679
             Atom mdhd @ 197417856 of size: 32, ends @ 197417888
             Atom hdlr @ 197417888 of size: 45, ends @ 197417933
             Atom minf @ 197417933 of size: 3803746, ends @ 201221679
                 Atom vmhd @ 197417941 of size: 20, ends @ 197417961
                 Atom dinf @ 197417961 of size: 36, ends @ 197417997
                     Atom dref @ 197417969 of size: 28, ends @ 197417997
                 Atom stbl @ 197417997 of size: 3803682, ends @ 201221679
                     Atom stsd @ 197418005 of size: 150, ends @ 197418155
                         Atom avc1 @ 197418021 of size: 134, ends @ 197418155
                             Atom avcC @ 197418107 of size: 48, ends @ 197418155
                     Atom stts @ 197418155 of size: 104, ends @ 197418259
                     Atom stss @ 197418259 of size: 3464, ends @ 197421723
                     Atom ctts @ 197421723 of size: 1613944, ends @ 199035667
                     Atom stsc @ 199035667 of size: 675328, ends @ 199710995
                     Atom stsz @ 199710995 of size: 811620, ends @ 200522615
                     Atom stco @ 200522615 of size: 699064, ends @ 201221679
     Atom trak @ 201221679 of size: 1398897, ends @ 202620576
         Atom tkhd @ 201221687 of size: 92, ends @ 201221779
         Atom edts @ 201221779 of size: 36, ends @ 201221815
             Atom elst @ 201221787 of size: 28, ends @ 201221815
         Atom mdia @ 201221815 of size: 1398761, ends @ 202620576
             Atom mdhd @ 201221823 of size: 32, ends @ 201221855
             Atom hdlr @ 201221855 of size: 45, ends @ 201221900
             Atom minf @ 201221900 of size: 1398676, ends @ 202620576
                 Atom smhd @ 201221908 of size: 16, ends @ 201221924
                 Atom dinf @ 201221924 of size: 36, ends @ 201221960
                     Atom dref @ 201221932 of size: 28, ends @ 201221960
                 Atom stbl @ 201221960 of size: 1398616, ends @ 202620576
                     Atom stsd @ 201221968 of size: 106, ends @ 201222074
                         Atom mp4a @ 201221984 of size: 90, ends @ 201222074
                             Atom esds @ 201222020 of size: 54, ends @ 201222074
                     Atom stts @ 201222074 of size: 112, ends @ 201222186
                     Atom stsc @ 201222186 of size: 160, ends @ 201222346
                     Atom stsz @ 201222346 of size: 699112, ends @ 201921458
                     Atom stco @ 201921458 of size: 699064, ends @ 202620522
                     Atom sgpd @ 202620522 of size: 26, ends @ 202620548                         ~
                     Atom sbgp @ 202620548 of size: 28, ends @ 202620576
     Atom udta @ 202620576 of size: 98, ends @ 202620674
         Atom meta @ 202620584 of size: 90, ends @ 202620674
             Atom hdlr @ 202620596 of size: 33, ends @ 202620629
             Atom ilst @ 202620629 of size: 45, ends @ 202620674
                 Atom ©too @ 202620637 of size: 37, ends @ 202620674
                     Atom data @ 202620645 of size: 29, ends @ 202620674

Can anyone with moov knowledge prove my assumption right or wrong? If I'm right and ffmpeg concat does not automatically assume to move the moov atom to the top should I change my approach and add -movflags +faststart to the concat demuxer command?

**Tags:** ffmpeg, mp4, concatenation


---

## 1 answers

### Answer by username_1 on 2021-02-08. Score: 1 | Accepted answer

The metadata from an input file in any ffmpeg operation is used to interpret and handle the media data in that file. That metadata is not naively copied over, wholesale or piecemeal\*. FFmpeg will always generate new metadata based on the specific set of media data received when generating the output. Since the output of concat operation is one file, it will have one moov box. If you want the concat output file to have moov box up front, you will have to add `-movflags +faststart`.

\*exception is string tags such as ID3 or timecode data.

> **Comments:**
> **username_0**: Thanks @username_1 I appreciate the response. This is good insight to know.  

---

