HOWTO Merge video files

From LinuxReviews
Jump to: navigation, search

You have file1.(mpg|avi) and file2.(mpg|avi) and you want to create a longer video file3.(mpg|avi) using both these clips. This is kind of difficult to do, but it's very possible.


[edit] Introduction

Video file merging requires that the files you want to merge have the same resolution and file format.

[edit] File formats

[edit] Avi

Use avimerge if you want to merge two .avi video files. The syntax is:

avimerge -o name -i file1 [ file2 [ ... ] ] [ -p file ] [
-a num ] [ -A num ] [ -b num ] [ -c ] [ -f commentfile ] [
-x indexfile ]

See the avimerge manual page for details.

[edit] Mpeg

mpgjoin, which is a part of mpgtx[1]

The command is used like this:

mpgjoin file1.mpg file2.mpg file3.mpg -o newfile.mpg

You can (obviously) also simply use a wildcard if you have a folder full of .mpg files with the same resolution:

mpgjoin *.mpg -o test.mpg

The "fine" manual for mpgjoin isn't that fine (it is the same as the mpgtx manual, which this command is a part of). This is the output of -h:

mpgjoin  : join compatible mpeg files into one
Usage    : mpgjoin [command] [options] [mpegfile [mpegfile | range]...
Commands :
  -h              print this help screen.
  -v              print version informations.
Options  :
  -N              Do not print out excessive information while processing
                  If you use MacOS Classic, this is RECOMMENDED
                  Otherwise mpgtx will be dead slow!
  -f              force overwriting of files, don't ask for confirmation
  -P              keep headers of mpegs which sometimes is usefull
  -X              Try to search for a valid PACK header in the whole file.
                  Additionally option -N suppress output during search.
                  This may result in an endless loop if not successfull!
  -An             While joining or splitting, aspect ratio will be forced to:
                  n=1 -> 1:1, n=2 -> 4:3, n=3 -> 16:9, n=4 -> 2.21:1 
                  All Numbers from 0 - 16 will be accepted but the above are valid!
  -o FILE         set the output file name (join implied)
                  if FILE is - , standard output will be used
  --force         force joining of incompatible files
  --no-parachute  don't try to catch SIGSEGV (usefull for debugging)
Ranges   :
  Ranges must follow an mpeg file
  [a-b]           from 'a' inclusive to 'b' inclusive. If you want half opened
                  ranges, you may want to use ]a-b], [a-b[ or ]a-b[ instead
  [num/total]     the 'num' part if the mpeg file was split in 'total'.
                  [1/4] would result in the first quarter of the mpeg file.
Values   :
  Values can be time or offsets in the mpeg file
  Time Format     HH:MM:SS where the HH: part can be omited
  Offset Format   a number optionally followed by:
                    M : offset is in Megabytes
                    k : offset is in Kilobytes
  An empty value means the corresponding file boundary:
                  [-10M]  the first 10 Megabytes of file
                  [500M-] from 500 Megabytes to the end of file


It is also possible to just cat MPG files and pipe them to a program if you need to input several video files to a tool:

cat file1.mpg file2.mpg file3.mpg | ffmpeg -i - -ar 44100 flashvideofile.flv

[edit] See also

[edit] References

  1. mpgtx - a command line MPEG audio/video/system file toolbox, that slices and joins audio and video files, including MPEG1, MPEG2 and MP3.
Personal tools
hardware tests
Privacy policy
linux events


linux newz | random page | poetry | free blog