The slow death of my old PS3 together with the timely introduction of Live TV support on XBMC 12 prompted me to take the PlayTV peripheral and stick it in my Linux-based media centre PC running XMBC and setup TVheadend to pull the signal from the PlayTV's tuners. The result of this is the XBMC box has now become our DVR and TV viewing platform as well as all the other media content it serves up, however there was still a lot of decent recordings left on the PS3 that I wanted to keep and having exported them from PlayTV and transferred them from the PS3, I felt that the M2TS files are a little too large to warrant leaving them in that format using all that disk space.
So for any out there who are left with a bunch of these huge M2TS files and want to make them smaller or simply transcode them to a format that is supported by more devices then this post is for you.
Firstly you will need to have ffmpeg installed on your PC together with appropriate Xvid & LAME MP3 libraries.
ffmpegAs always ffmpeg is my goto toolkit for video convertion and a single MT2S file can be converted to a smaller file without much loss of quality with a one-liner.
ffmpeg -y -i "awesomeshow.m2ts" \ -vcodec libxvid \ -b 1200k \ -acodec libmp3lame \ -ac 2 -ar 44100 -ab 128k \ -s 576x460 -threads 2 -deinterlace "awesomeshow.avi"
In this example the filename of the M2TS file that is being converted (the input file) is 'awesomeshow.m2ts' and I've given the output file the name 'awesomeshow.avi'.
-vcodec = video codecHere I've used the Xvid MPEG4 library to achieve a higher compression ratio than the source file's MPEG2, reducing the size of the output file, also many devices (including the PS3) support Xvid playback.
-b = video bitrateI've specified a video stream bitrate of 1200 Kbits per second, after lots of tries this seems to be a nice compromise between quality & output file size.
-s = frame sizeMy PAL TV signal is processed at 576i, the resulting resolution of the original recording is 720x576. In the above example I've used the -s option to reduce the output file resolution to 576x460. This helps to further reduce the output file size.
-acodec = audio codecMP3 is the common counterpart to the Xvid video codec, it compresses audio well and playback is supported everywhere.
I specified the output audio stream to be a 2 channel stream with a sample rate of 44KHz and a bitrate of 128Kbps with the -ac, -ar & -ab options.
-deinterlaceAs the video source is an interlaced TV signal it will look terrible when played back on a progressive display unless deinterlacing is applied on the transcode or on the player playing the convertion. Therefore I've specified to deinterlace during the conversion with the delinterlace option, this also introduces additional processing on the transcode so ffmpeg will take noticeably longer to complete.
-threads = number of conversion processesSet this figure to match the number of processor cores on your computer, the more processors you can get to work on the conversion job the quicker it will finish.
Finally, a script...I had a lot of recordings to convert so naturally, to convert all of them all in one go on my media centre PC which runs a popular Linux distro I wrote a little shell script.
If you want to use this script just save it to your local filesystem (your Downloads directory presumably), pop it in your /usr/bin directory & make it executable;
cd ~/Downloads chmod +x playtv2xvid sudo mv playtv2xvid /usr/bin
Then in a terminal 'cd' to the location of your *.m2ts files and run...
It will show you what M2TS files have been found in the current location, press enter to begin the conversions and all will be logged in a log file for you to review later.
Download the playtv2xvid script here.