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.

share|improve this question
    
I've filed a related bug when it comes to webm here: bugzilla.libav.org/show_bug.cgi?id=775 – v010dya Nov 9 '14 at 9:15
    
There's a link rot problem, since you've deleted the avconv.txt file from your dropbox. I'm going to remove it from the question. – v010dya Nov 9 '14 at 9:17
    
    
I used avconv -i "concat:`ls *.mp4 | tr '\r\n' '\|'" -c copy "combined.mp4" on windows. For linux I think you'd just use \n, not \r\n – alirobe Aug 25 '16 at 5:47
up vote 20 down vote accepted
avconv -i concat:file1.mp4\|file2.mp4 -c copy output.mp4

I don't know if works with any container's type ( worked for me with AVI ).

share|improve this answer
8  
Didnt work for me... had to do it with mencoder... mencoder -oac pcm -ovc copy -o merged_file.mp4 ls *.mp4 – Philippe Gachoud Mar 2 '14 at 17:01
    
Doesn't work for me with mp3 and avconv 0.8.10 – Andy May 5 '14 at 15:20
5  
mp4 containers cannot be concatenated in this way. – Dustin Kirkland Jul 9 '14 at 14:47
3  
The accepted answer did not work for me. Instead, I used the MP4Box command (from gpac package) as follows: MP4Box video1.mp4 -cat video2.mp4 -cat video3.mp4 [...] -out video-full.mp4 – ray Sep 23 '15 at 10:43
1  
Nope, doesn't work. The net result is that the video is just as long as the first one, and the viewable content is exactly the content of the first video. Other videos seem to be ignored. – filmil May 27 '16 at 15:03

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:

share|improve this answer
1  
This solution isn't working for me. If I use the word concat anywhere in the command line, I always get errors like Unknown input format: 'concat' or Requested output format 'concat:test.mp3' is not a suitable output format. Any suggestions? – Mr Lister Jul 30 '14 at 8:01
1  
What version of avconv do you have? – Aaron Sep 9 '14 at 14:30
    
I'm having the same problem with avconv version 12. Version 11 doesn't work either – omnibrain Feb 14 '17 at 17:49

For mp4 the only working solution I found was with MP4Box from gpac package

#!/bin/bash
filesList=""
for file in $(ls *.mp4|sort -n);do
    filesList="$filesList -cat $file"
done
MP4Box $filesList -new merged_files_$(date +%Y%m%d_%H%M%S).mp4

or command is

MP4Box -cat file1.mp4 -cat file2.mp4 -new mergedFile.mp4

with mencoder and avconv I could'nt make it work :-(

share|improve this answer
    
i'm on debian jessie and this is the only answer that i could run (mostly due to missing packages).the result is weird though, the actual stream is shorter than what VLC shows, and when seeking there it just restarts the playback. – Attila Lendvai Feb 27 '15 at 1:00
    
This is an amazing tool, thanks for mentioning it! – Ivan Kapitonov May 31 '15 at 2:11
    
A shorter command line that will take in all mp4 files in the current directory is: MP4Box $(printf -- "-cat %s " *.mp4) -new mergedFile.mp4 – filmil May 27 '16 at 15:12

this works

avconv -i 1.mp4 1.mpeg
avconv -i 2.mp4 2.mpeg
avconv -i 3.mp4 3.mpeg

cat 1.mpeg 2.mpeg 3.mpeg | avconv -f mpeg -i - -vcodec mpeg4 -strict experimental output.mp4

Above works if you only have avconv - however ffmpeg has added functions ... to quote :

"Above avconv steps does unnecessary additional lossy encoding steps which is slow and reduces the quality of the output. I would recommend using the concat demuxer (additional info) or concat filter instead, but avconv lacks those features available in ffmpeg from FFmpeg" – @LordNeckbeard

    SEE  https://trac.ffmpeg.org/wiki/Concatenate

If you're using a system that supports named pipes, you can use those to avoid creating intermediate files - this sends stderr (which ffmpeg sends all the written data to) to /dev/null, to avoid cluttering up the command-line:

mkfifo temp1 temp2
ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1 2> /dev/null & \
ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2 2> /dev/null & \
ffmpeg -f mpegts -i "concat:temp1|temp2" -c copy -bsf:a aac_adtstoasc output.mp4
share|improve this answer
    
Shows a lot of errors (at the last step), but the only answer that does result in a merged file for me so +1! – Mark Nov 14 '14 at 20:02
1  
only this work for me – Huang Dongsung Oct 19 '17 at 17:20

This one works for me:

avconv -i "concat:001.mp4|002.mp4|003.mp4" -c copy full.mp4

Just concats all the files into one mp4 without re-encoding them.

share|improve this answer
    
The only reason I found this page is because this solution just outputs concat:: Protocol not found (even though it's on the list of protocols output by avconv -protocol) – Jeremy List Apr 19 '17 at 6:04

This method will do for concating raw *.avi files only, I suppose. But since lots of people willing to join avi files will end up viewing this question I'll post my answer here anyway:

cat *.avi > out_tmp.avi
avconv -i out_tmp.avi -c copy output.avi

One more time: works for uncompressed *.avi files only.

share|improve this answer

I did that with avidemux (gtk tool). It is available as a package under most linuxes, also for Windows and Mac. I simply opened the first file. Then I added the next ones in order. Finally, I saved the concatenated video using audio and video copy and format mp4.

It worked great !

share|improve this answer

I am using ffmpeg command to do this. Here is example:

ffmpeg -i concat:/dev/null|file1.ts|file2.ts -c copy -bsf:a aac_adtstoasc -y output.mp4

Take a look at this github project for Distributed parallel video trascoding

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.