Monday, 10 September 2012

Video files concatenation

How to concatenate 2 files in Ubuntu? Using Pitivi is not good when you want to preserve the original quality. Actually while playing with Pitivi I haven't found good enough rendering options that will be suitable for me and have quality similar to the original. So I've tried to use command line. The software is called ffmpeg or  avconv in the Ubuntu 12.04.


Only few media containers allows to join video by concatenating them (MPEG-1, MPEG-2 PS, DV).
I had couple of h264 encoded files from my car DVR and I want to join them together. So first I need to convert them to the suitable format, then concatenate and reconvert to the original format. Here we go.

$ avconv -i gravel-fiat-1.MOV -same_quant gravel-fiat-1.mpg
$ avconv -i gravel-fiat-2.MOV -same_quant gravel-fiat-2.mpg
$ cat gravel-fiat-1.mpg gravel-fiat-2.mpg > gravel-fiat.mpg
$ avconv -i gravel-fiat.mpg -same_quant gravel-fiat.MOV

Notice the last command convert it to the mpeg4 format not to the h264, to convert the clip to the original format following command must be run

$ avconv -i gravel-fiat.MOV -same_quant -vcodec libx264 gravel-fiat.mp4

Now I need to cut some time from the beginning and in the end.

$ avconv -i gravel-fiat.MOV -ss 160 -t 702 -acodec copy -vcodec copy gravel-fiat-cut.MOV

The command will cut off first 160 seconds and everything after 702+160=862 seconds preserving original quality. Exactly what I'm looking for.

1 comment:

  1. Thank you for option -same_quant, it really helped with mov converting.

    ReplyDelete