Autopano Video - Concatenate several mp4
FFMPEG method (Concatenation of files with same codecs)
- For more information about [concatenation with ffmpeg ]
There are 2 methods!
Concat demuxer method (We used that method on Gopro Hero3 black mp4 videos)
The concat demuxer was added to ffmpeg 1.1. You can read about it in the [documentation].
Instructions: Create a file "Cam01.txt" with all the (files relative or absolute paths) you want to have concatenated in the following form ( Lines starting with a dash are ignored ):
# this is a comment file '/path/Cam01/GOPR0009.MP4' file '/path/Cam01/GP010009.MP4' file '/path/Cam01/GP020009.MP4'
Note that these can be either relative or absolute paths. Then you can encode your files with: ffmpeg -f concat -i Cam01.txt -c copy Cam01.mp4
Concat protocol method (We used that method on Gopro Hero3 black mp4 videos)
While the demuxer works at the stream level, the concat protocol works at the file level. Certain files (mpg and mpeg transport streams, possibly others) can be concatenated. This is analogous to using cat on UNIX-like systems or copy on Windows. In general, the demuxer is the better option.
Instructions: ffmpeg -i "concat:input1.mpg|input2.mpg|input3.mpg" -c copy output.mpg
If you have MP4 files, these could be losslessly concatenated by first transcoding them to mpeg transport streams. With h.264 video and AAC audio, the following can be used:
ffmpeg -i GOPR0009.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts GOPR0009.ts ffmpeg -i GP010009.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts GP010009.ts ffmpeg -i GP020009.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts GP020009.ts ffmpeg -i "concat:GOPR0009.mp4|GP010009.mp4|GP020009.mp4" -c copy -bsf:a aac_adtstoasc output.mp4
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 GOPR0009.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1 2> /dev/null & \ ffmpeg -i GP010009.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2 2> /dev/null & \ ffmpeg -i GP020009.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
All MPEG codecs (h.264, MPEG4/divx/xvid, MPEG2; MP2, MP3, AAC) are supported in the mpegts container format, though the commands above would require some alteration (the -bsf bitstream filters will have to be changed).