Changes between Version 12 and Version 13 of Concatenate


Ignore:
Timestamp:
Jan 6, 2013, 3:25:15 PM (6 years ago)
Author:
evilsoup
Comment:

Added concat protocol, added contents table

Legend:

Unmodified
Added
Removed
Modified
  • Concatenate

    v12 v13  
    1 If you have media files with exactly the same codec and codec parameters you can concatenate them as described in "1. Concatenation of files with same codecs". If you have media with different codecs you can concatenate them as described in "2. Concatenation of files with different codecs" below.
    2 
    3 
    4 = 1. Concatenation of files with same codecs =
    5 
    6 == Description ==
    7 
    8 The concat demuxer was added to ffmpeg 1.1 . You can read about it in the [http://ffmpeg.org/ffmpeg-formats.html#concat documentation]
    9 
    10 == Instructions ==
     1= Concatenating media files =
     2
     3[[PageOutline(2-3, Contents)]]
     4
     5If you have media files with exactly the same codec and codec parameters you can concatenate them as described in "[#samecodec Concatenation of files with same codecs]". If you have media with different codecs you can concatenate them as described in "[#differentcodec Concatenation of files with different codecs]" below.
     6
     7
     8== Concatenation of files with same codecs ==#samecodec
     9
     10There are two methods within ffmpeg that can be used to concatenate files of the same type: [#demuxer the concat ''demuxer''] and [#protocol the concat ''protocol'']. The demuxer is more flexible - it requires the same codecs, but different container formats can be used; and it can be used with any container formats, while the protocol only works with a select few containers. However, the concat protocol is available in older versions of ffmpeg.
     11
     12=== Concat demuxer ===#demuxer
     13
     14The concat demuxer was added to ffmpeg 1.1 . You can read about it in the [http://ffmpeg.org/ffmpeg-formats.html#concat documentation].
     15
     16==== Instructions ====
    1117
    1218Create a file "mylist.txt" with all the files you want to have concatenated in the following form ( Lines starting with a dash are ignored ) :
    1319{{{
    1420# this is a comment
    15 file /path/to/file1
    16 file /path/to/file2
    17 file /path/to/file3
    18 }}}
    19 
    20 then you can encode your files with:
     21file '/path/to/file1'
     22file '/path/to/file2'
     23file '/path/to/file3'
     24}}}
     25
     26Note that these can be either relative or absolute paths. Then you can encode your files with:
    2127{{{
    2228ffmpeg -f concat -i mylist.txt -c copy output
     
    2430
    2531
    26 = 2. Concatenation of files with different codecs =
    27 
    28 == Description ==
     32=== Concat protocol ===#protocol
     33
     34While 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.
     35
     36==== Instructions ====
     37
     38{{{
     39ffmpeg -i "concat:input1.mpg|input2.mpg|input3.mpg" -c copy output.mpg
     40}}}
     41
     42If 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:
     43
     44{{{
     45ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
     46ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
     47ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4
     48}}}
     49
     50If 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:
     51
     52{{{
     53mkfifo temp1 temp2
     54ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1 2> /dev/null & \
     55ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2 2> /dev/null & \
     56ffmpeg -f mpegts -i "concat:temp1|temp2" -c copy -bsf:a aac_adtstoasc output.mp4
     57}}}
     58
     59All 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).
     60
     61== Concatenation of files with different codecs ==#differentcodec
     62
     63=== Concat filter ===#filter
    2964
    3065The concat filter is available in recent versions of ffmpeg. [http://ffmpeg.org/ffmpeg-filters.html#concat Here] is the official documentation.
    3166
    32 == Instructions ==
     67==== Instructions ====
    3368
    3469This is easiest to explain using an example:
     
    66101As you can infer from this example, multiple types of input are supported, anything readable by ffmpeg should work. The inputs have to be of the same frame size, and a handful of other attributes have to match.
    67102
    68 = 3. Concatenation of files with different codecs using an external script =
    69 
    70 == Description ==
     103=== Using an external script ===#extscript
    71104
    72105The following script can be used to concatenate multiple input media files (containing audio/video streams) into one output file (just like as if all the inputs were played in a playlist, one after another). It is based on this FAQ item: [http://ffmpeg.org/faq.html#How-can-I-concatenate-video-files_003f How can I join video files], which also contains other useful information.
     
    74107If you find any bugs, feel free to correct the script, add yourself to the list of contributors and change the version string to reflect your change(s) or email the author with your patch, whatever you find more convenient.
    75108
    76 == Instructions ==
     109==== Instructions ====
    77110
    78111Save the script in a file named "mmcat" (or some other name), make it executable (chmod +x mmcat) and run it, using the syntax:
     
    87120that could mean that you don't have correct permissions set on /tmp directory (or whatever you set in TMP variable) or that decoding of your input media has failed for some reason. In this case, it would be the best to turn on the logging (described in the script's comments)
    88121
    89 == Script ==
     122==== Script ====
    90123
    91124{{{