Wednesday, May 11, 2011

FFMPEG: Convert AVCHD (*.mts, *.m2ts) to H264

Most Camcorders including the "Canon LEGRIA HF R16" record Digital High Definition Video in full HD resolution at 50 frames (interlaced) in mts/m2ts-format.

Cross platform and one of the best compressions out there today is to my personal preference H264

Assuming you have installed ffmpeg and all the libraries you might need,
use the following command to get the job done relatively fast. 

  

1.Conversion at full HD resolution (same as the source file).


ffmpeg -i inputfile.m2ts -acodec libfaac -ar 48000 -ab 128k -coder ac -vcodec libx264 -threads 0 -deinterlace -b:v 3000k -cmp +chroma -g 250 -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -flags +loop outputfile.mp4

2. conversion at lower resolution.


ffmpeg -i inputfile.m2ts -acodec libfaac -ar 48000 -ab 128k -coder ac -vcodec libx264 -threads 0 -deinterlace -s 720x576 -b:v 1600k -cmp +chroma -g 250 -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -flags +loop outputfile.mp4


3. conversion 1440x1080i (Anamophic) to FHD 1920x1080p (MP4).



If your camera records HD in 1440x1080, (non-square pixels or anamorphic) you can add the re-size and aspect ratio to make it 1920x1080 square pixels. A square pixel is easier on LCD monitors. (You basically change the pixel-aspect-ratio from wide pixel to square pixel)

ffmpeg -i InputFile.mt2s -acodec libfaac -ar 48000 -ab 128k -coder ac -vcodec libx264 -threads 0 -deinterlace -s 1920x1080 -aspect 16:9 -b:v 3000k -cmp +chroma -g 250 -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -r 25 -b_strategy 1 -flags +loop OutputFile.mp4



Change the -b parameter to control compression rate. A good quality at full HD resolution (1080i or 1080p) requires a setting between 1600 and 6000, depending on the content. (slow moving video v.s. fast moving content like sports). If you lower the resolution you can drastically lower the bit rate and still obtain a good quality movie. Use -threads parameter to utilize available cpu power. (0 = auto and will use all cores balanced)


For full FFmpeg manual visit: ffmpeg.org
For installation instruction on the Latest version for Ubuntu visit this forum article.

4 comments:

Please be courteous, even if you do not share the same view.