How to merge videos by avconv?

Alex picture Alex · Aug 31, 2013 · Viewed 42.5k times · Source

I have several chunks in folder.

0001.mp4
0002.mp4
0003.mp4
...
0112.mp4

I would like to merge them into full.mp4

I tried to use:

avconv -f concat -i <(printf "file '%s'\n" /root/chunk/*.mp4) -y \
-c copy /root/test/full.mp4

Unknown input format: 'concat'

avconv -f concat -i <(printf "%s|" /root/chunk/*.mp4) -y \
-c copy /root/test/full.mp4

Unknown input format: 'concat'

avconv -i concat:`ls -ltr /root/chunk/*.mp4 | awk 'BEGIN {ORS="|"} { print $9 }'` \
 -c:v copy -c:a copy /root/test/full.mp4

In last edition only one input file was catched to output.

How to merge all chunks from folder into full video?

I don't want to use ffmpeg or other. Avconv only.

Answer

Dustin Kirkland picture Dustin Kirkland · Jul 11, 2014

mp4 files cannot be simply concatenated, as the "accepted" answer suggests.

If you run that, and that alone, you'll end up with output.mp4 having only the contents of file1.mp4.

That said, what you're looking to do in the original question can in fact be done, as long as you split original file into mpeg streams correctly.

The following commands will split input.mp4 into 3x 60 second segments, in file[1-3].ts:

avconv -ss 0 -i input.mp4 -t 60 -vcodec libx264 -acodec aac \
    -bsf:v h264_mp4toannexb -f mpegts -strict experimental -y file1.ts
avconv -ss 0 -i input.mp4 -t 60 -vcodec libx264 -acodec aac \
    -bsf:v h264_mp4toannexb -f mpegts -strict experimental -y file2.ts
avconv -ss 0 -i input.mp4 -t 60 -vcodec libx264 -acodec aac \
    -bsf:v h264_mp4toannexb -f mpegts -strict experimental -y file3.ts

You can then put them back together much as the other answer suggests:

avconv -i concat:"file1.ts|file2.ts|file3.ts" -c copy \
   -bsf:a aac_adtstoasc -y full.mp4

I used this process to create a scalable, parallel transcoder as described at: