sobota 13. března 2010

Batch conversion avchd (MTS) to AVI

I'm owner of Sony HDR-SR11 camcorder and proud user of linux (ubuntu in my case). So i'm facing the problem of processing avchd on linux. These days the situation on linux is still better and better - for example kdenlive video editor is able to process this format - but not ideal, there are some bugs while processing and rendering, you also need pretty powerfull hardware (which is my first 64bit amd on the world not unfortunately).
The other way is to convert avchd to something more usefull on linux. For a long time I used virtual windows with original camcorder soft for conversion to mpeg. But these days the linux ffmpeg is able to do the job. Unfortunately the parameters to use are different fow each camcorder and almost each video. You can read the howto and discussion here - really usefull site.
Based on that i created simple python script for my handycam, which will do the conversion for all MTS files in current directory. It is quite dummy - you cannot specify another directory, or more directories and so, but it is sufficient to my use. The script has also hardcoded audio settings (which is the same in all my vids), but it is simple to make it dynamically set or to change it to your needs. I will really apprecieate when someone make some changes then please post it here to forum under this article.
I really hope it will help more people than me ;-) Finally here is the script promissed:



#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import subprocess
import re

for filename in os.listdir('.'):
if re.match('.*\.MTS',filename):
output = subprocess.Popen([r"ffmpeg", "-i", filename], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
bitrate = re.search('(?<=bitrate: )\w+', output)
filebase = re.search('.*(?=\.MTS)',filename)
subprocess.Popen([r"ffmpeg", "-i", filename, "-vcodec", "libxvid", "-b", bitrate.group(0)+"k", "-acodec", "libmp3lame", "-ac", "2", "-ab", "256k", "-ar", "48000", "-deinterlace", "-s", "1440x1080", filebase.group(0)+".avi"]).wait()

Žádné komentáře: