Concatenate Video Files with "ffmpeg"

This section provides a tutorial example on how to concatenate two short video files into a longer video file with 'ffmpeg' using '-complex_filter' option and 'concat' filter.

What about merging multiple shorter video files into a single video file? "ffmpeg" command can do that too:

C:\herong>\local\ffmpeg\bin\ffmpeg -i input_1 -i input_2 
 -filter_complex "[0:1] [0:0] [1:1] [1:0] concat=n=2:v=1:a=1 [v] [a]"
 -map [v] -map [a] output_file

The above command uses:

The following illustration may help to understand the above command:

                   Video     Audio
                   Stream    Stream
                   
input_file_1 ----> [0:1]     [0:0]
                     |         |
input_file_2 ----> [1:1]     [1:0]
                     |         |
                   "concat" filter
                     |         |
                    [v]       [a]
                     |         |
                   "map"     "map"
                     |         |
Output_file <-------------------

Important note: "concat" filter requires the video stream to be specified before the audio stream.

In order to test the above concatenating command, I extracted another segment, "Spider-Man: The Peril of Doc Ock", from Tony_reelshow_2009_512kb.swf:

C:\herong>\local\ffmpeg\bin\ffmpeg 
   -i Tony_reelshow_2009_512kb.swf 
   -ss 00:00:49.56 -to 00:00:71.48 Spider_Man.swf

Now I am ready to merge two SWF video files into a longer video file:

C:\herong>\local\ffmpeg\bin\ffmpeg 
 -i Anchor_Great_Escape.swf -i Spider_Man.swf 
 -filter_complex "[0:1] [0:0] [1:1] [1:0] concat=n=2:v=1:a=1 [v] [a]"
 -map [v] -map [a] Anchor_and_Spider_Man.swf

...
Input #0, swf, from 'Anchor_Great_Escape.swf':
 Duration: 00:01:02.60, start: 0.000000, bitrate: 127 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
  Stream #0:1: Video: flv1, yuv420p, 416x240, 25 fps, 25 tbr, 25 tbn

Input #1, swf, from 'Spider_Man.swf':
 Duration: 00:01:09.56, start: 0.000000, bitrate: 128 kb/s
  Stream #1:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
  Stream #1:1: Video: flv1, yuv420p, 416x240, 25 fps, 25 tbr, 25 tbn

Output #0, swf, to 'Anchor_and_Spider_Man.swf':
 Metadata:
  encoder         : Lavf55.40.100
 Stream #0:0: Video: flv1 (flv), yuv420p, 416x240, q=2-31, 200 kb/s, 
              25 fps,90k tbn, 25 tbc (default)
  Metadata:
   encoder         : Lavc55.63.100 flv
 Stream #0:1: Audio: mp3 (libmp3lame), 44100 Hz, stereo, s16p(default)
  Metadata:
   encoder         : Lavc55.63.100 libmp3lame

Stream mapping:
  Stream #0:0 (mp3) -> concat:in0:a0
  Stream #0:1 (flv) -> concat:in0:v0
  Stream #1:0 (mp3) -> concat:in1:a0
  Stream #1:1 (flv) -> concat:in1:v0
  concat:out:v0 -> Stream #0:0 (flv)
  concat:out:a0 -> Stream #0:1 (libmp3lame)

Press [q] to stop, [?] for help
frame=293 fps=0.0 q= 4.8  size= 677kB time=00:00:11.72 bitrate= 473.5
frame=578 fps=577 q=26.9  size=1247kB time=00:00:23.12 bitrate= 441.9
frame=869 fps=579 q=31.0  size=1758kB time=00:00:34.76 bitrate= 414.3
frame=986 fps=583 q=31.0 Lsize=1939kB time=00:00:39.44 bitrate= 402.6

video:1294kB audio:617kB subtitle:0kB other streams:0kB 
   global headers:0kB muxing overhead: 1.442786%

The command worked! You can play concatenated video file with Flash Player Projector:

C:\herong>\local\bin\flashplayer_13_sa Anchor_and_Spider_Man.swf

Last update: 2014.

Table of Contents

 About This Book

 Introduction of Adobe Flash

 Adobe Flash Player Plugin for Firefox

 Adobe Flash Player Plugin for Chrome

 Adobe Flash Player Plugin for Safari

 Adobe Flash Player ActiveX for IE

 Using "object" Elements for Flash Files

 Using "embed" Elements for Flash Files

 "mp3player" - MP3 Music Player

 SWFObject - Hidding "object" behind JavaScript

 Flash Player Projector

 SWFTools - SWF File Manipulation Tools

 SWFC Script to Generate Flash SWF Files

 ActionScript Embedded in SWFC Script

 AS3Compile - ActionScript 3 Compiler

 Adobe Flex SDK 4

 SWF File Structure and Tags

 SWF File Processing Rules

SWF Files for Video and Audio Streams

 Video and Audio Stream SWF File Structure

 Installing FFmpeg to Manipulate Video SWF Files

 Playing Movie with FFmpeg "ffplay" Command

 See File Properties with FFmpeg "ffprobe" Command

 Convert File Format with "ffmpeg" Command

 Issue with "ffplay" on SWF Output File

 "ffplay" Interactive Commands

 Break Long Video into Parts with "ffmpeg"

Concatenate Video Files with "ffmpeg"

 Video/Audio Stream Concatenation Order

 Split Audio Stream Out of SWF File

 Split Video Stream Out of SWF File

 Merge Video and Audio Streams to SWF File

 Reduce Video Stream Resolution

 Reduce Video Frame Rate

 Outdated Tutorials

 References

 PDF Printing Version