Jump to: navigation, search

Difference between revisions of "Autopano Video - Concatenate several mp4"

(Concat protocol method (It works with Gopro Hero3 black mp4 files))
(2) oncat protocol method (It works with Gopro Hero3 black mp4 files))
Line 16: Line 16:
 
  ffmpeg -f concat -i Cam01.txt -c copy Cam01.mp4
 
  ffmpeg -f concat -i Cam01.txt -c copy Cam01.mp4
  
====2) oncat protocol method (It works with Gopro Hero3 black mp4 files)====
+
====2) Concat protocol method (It works with Gopro Hero3 black mp4 files)====
 
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.
 
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.
  

Revision as of 17:13, 28 May 2013

FFMPEG method (Concatenation of files with same codecs)

There are 2 methods!

1) Concat demuxer method (It works with Gopro Hero3 black mp4 files)

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

2) Concat protocol method (It works with Gopro Hero3 black mp4 files)

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:

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 Cam01.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 temp3
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|temp3" -c copy -bsf:a aac_adtstoasc Cam01.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).