Sunday, August 30, 2009

Re-encoding AVCHD video using FFMpeg

There's been some changes to how ffmpeg operates starting from revision 19459 and simply pointing out the input and output files with libx264 will not do the trick anymore. This is due to the fact that ffmpeg now recognizes the subtitles track and doesn't know how to deal with it in the resulting MKV file. To overcome this issue add the -sn to the parameters and you're done.

Also some of the x264 options don't have working default values so one must specify the preset for video encoding. Here's an example:

ffmpeg.bat -i 00001.MTS -acodec aac -ac 2 -ab 128k -sn -vcodec libx264 -deinterlace -s 1280x720 -vpre ./libx264-hq.ffpreset -crf 23 -threads 2 00001.mkv

To make it work make sure you've copied the libx264-hq.ffpreset file from ffmpeg archive into the folder with your MTS file to be re-encoded.

Also you can adjust the -crf 23 parameter to steer the final size and quality of the resulting MKV file.

Enjoy!

Joining MTS files (AVCHD)

I've been looking for a long time to find out how to join 2 consecutive MTS files from my Sony SR-11 camera. The case is simple: re-encode the recorded material into a smaller resolution and/or DVD format.

If you'd just take all the files the camera spitted out and join them afterwards a number of issues would emerge: jittered frames at the splitting points, audio desynchronization - you name it.

The solution couldn't be simplier but it was nowhere to be found directly on the net (google could have done a better job this time):

copy /b 00001.MTS + 00002.MTS + 00003.MTS output.mts

This example will join the files 00001.MTS, 00002.MTS, 00003.MTS into output.mts without doing any re-encoding, loosing synchronization or anything like that. And it's doing it extremly fast.

Enjoy!