Transcoding AVCHD (.mts or .m2ts) files using mencoder on Linux

The current top-of-trunk version of mplayer will decode and playback .mts and .m2ts AVCHD files. The one caveat is that your computer has to be fast enough to decode them, which mine isn’t.

Therefore, transcoding the .mts files to a more easily playable format is preferred. Since mplayer can decode the orignials, then mencoder can transcode them directly. I’m still experimenting, but the following command produces a pretty nice output, and is significantly smaller than the original .mts file.

# mencoder $file -o ./$file.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=5000 -fps 60 -vf scale=1280:720

This will run at about 35FPS on my Athlon 4400+. I’m not specifying any fancy filters, like deinterlacing or denoising, and both of those could probably increase the quality of the output. Doing a 2-pass encode would also increase the quality of the output. Those commands would look like this:

# mencoder $file -o $file.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=5000:vpass=1:turbo -fps 60 -vf scale=1280:720
# mencoder $file -o $file.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=5000:vpass=2 -fps 60 -vf scale=1280:720

You’d probably only really need to do a 2-pass encode if you set the bitrate much lower than the 5Mbps that I’ve specified.

Now, I might actually think about buying that Canon HG10 instead of just borrowing it…

Tags: , , ,

5 Responses to “Transcoding AVCHD (.mts or .m2ts) files using mencoder on Linux”

  1. Chris Says:

    I’m trying to get my mts files to play in Ubuntu 7.10. I installed MPlayer using ‘Add/Remove Apps”, but it does not play these files. Now I’ll admit I have no idea what top-of-trunk means. Is there anything special I need to do to play mts files?

  2. linux-tipps.blogspot.com Says:

    It works well for me but at some point mplayer produces only garbled video and keeps showing me.

    [h264 @ 0x11e64b0]Missing reference picture 0min 21mb A-V:-0.014 [2870:384]
    [h264 @ 0x11e64b0]illegal short term buffer state detected
    [h264 @ 0x11e64b0]Missing reference picture 0min 21mb A-V:-0.014 [2870:384]
    [h264 @ 0x11e64b0]Missing reference picture

    Any idea?

  3. linux-tipps.blogspot.com Says:

    I’m getting closer an closer, but I still have A-V delay problems.

    here’s my current script
    http://linux-tipps.blogspot.com/2008/08/comfortable-direct-hd-video-encoding.html

  4. r0bertz Says:

    I also get this:
    [h264 @ 0x11e64b0]Missing reference picture 0min 21mb A-V:-0.014 [2870:384]
    [h264 @ 0x11e64b0]illegal short term buffer state detected
    [h264 @ 0x11e64b0]Missing reference picture 0min 21mb A-V:-0.014 [2870:384]
    [h264 @ 0x11e64b0]Missing reference picture

    my work around is add “-demuxer lavf”

    I am now using this command to convert m2ts file:
    mencoder $i -o ${i}.avi -vc ffh264 -demuxer lavf -oac mp3lame -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=3000 -fps 50 -vf scale=640:360

  5. J Says:

    if you can’t open them, try some of the software listed here http://dotwhat.net/mts/9029/ worked fine for me

Leave a Reply