HOWTO: Convert and write AVCHD (.mts) to DVD with Linux

You’ve got a brand-new AVCHD camcorder from Panasonic, Sony or Canon and recorded your kids the first time in HD quality and want now to show the footage to your children’s grandmother?
Sure, no problem.
Just plug your camcorder directly into your also brand-new BluRay-writer or convert and author the footage with your Windows box first ;-) *kidding*
We’re of course on Linux and we don’t have a BluRay-writer, at least grandma doesn’t have one. What now? Well – I assume granny has a DVD-player. And we’re in the game again. I assume also you know how to compile (see other articles at this site, if not) and you also know how to install missing packages (e.g.: “apt-get install dvdauthor growisofs” ).
We just need these free Linux tools:

  • mencoder (latest trunk: > ca. 27000, see mplayer note at the end)
  • dvdauthor (repo: 0.6.14)
  • growisofs (repo: 7.1)

  1. I’ve done the transcoding with just a single pass, and the quality was good enough for me. Here’s the line, which I didn’t tweaked a lot. So there maybe exists a much better solution. Just try yourself.
    >mencoder -oac copy -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576,harddup -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:aspect=16/9:threads=4 input-file.mts -ofps 50 -fps 50 -o output_file.mpg

    The example above is for PAL (Europe), for NTSC (USA) use “scale=720:480” and -(o)fps 60. “-lavcopts” was also running with an additional “:threads=4“. I left this away for compatibility reasons.
    My sample file was 515 seconds long ( 8,1/2 minutes) and it took me about 13 minutes (31.66fps avarage) to convert it on a Intel Q6600 2,4Ghz (quadcore) and a x86_64 Ubuntu 8.10.
    The input-file was 1GB in size and the output_file was 332MB. The footage was a recording from a Canon HF100, recorded at 15MBit/s (highest quality, H264 1920×1080).
    So a rule of thumb could be: 10GB AVCHD ~ 3,4GB MPEG2.
    In my footage was a lot panning, so you’ll get smaller output, if you don’t have a lot motion in your footage. But if you take the values above, your AVCHD footage could be about 14GB in size and it would still fit onto a single layer DVD (4,3GB), which in this case is a video length of about 110 minutes.
    Please consider that this example was also made for a PAL system (fps 50) and with a Canon HF100 camcorder. You probably have to use for a Panasonic HDC-SDxxx the ‘-demuxer lavf’ switch, instead of ‘-fps 50′ (or 60 for NTSC).


  2. After you’ve got your output file in MPEG2 format, you can prepare it for writing on a DVD with dvdauthor:

    dvdauthor -o dvd -x dvd.xml

    Test it, before writing:

    mplayer dvd:// -dvd-device ./dvd

    See/download the dvd.xml example in the link above, and adjust it to your needs.


  3. Finally write it to a DVD via growisofs:


    growisofs -dvd-compat -Z /dev/dvdrw -dvd-video ./dvd/


  4. I’ve been using for the examples above a Ubuntu 8.10 (Intrepid Ibex). It should make no difference to other distros, like Fedora, SuSE, Gentoo or all other Debian derivate, you just need latest mplayer (mencodere included) trunk:

    svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
    cd mplayer
    ./configure
    make && make install

    Report bugs, typos and stuff. Thanks!

25 thoughts on “HOWTO: Convert and write AVCHD (.mts) to DVD with Linux

  1. Frank

    I have tried your steps with .mts files from a Panasonic camcorder, but with or without -demuxer lavf switch I get many messages of the following kind:


    Pos: 1.4s 73f ( 2%) 33.20fps Trem: 1min 47mb A-V:0.008 [6423:384]
    1 duplicate frame(s)!
    Pos: 1.4s 75f ( 2%) 33.27fps Trem: 1min 47mb A-V:0.012 [6380:384]
    1 duplicate frame(s)!
    Pos: 1.5s 77f ( 2%) 33.39fps Trem: 1min 47mb A-V:0.016 [6319:384]
    1 duplicate frame(s)!
    Pos: 1.5s 79f ( 2%) 33.43fps Trem: 1min 47mb A-V:0.012 [6271:384]
    1 duplicate frame(s)!
    Pos: 1.5s 81f ( 2%) 33.42fps Trem: 1min 56mb A-V:0.016 [6447:384]
    1 duplicate frame(s)!
    Pos: 1.6s 83f ( 2%) 33.54fps Trem: 1min 56mb A-V:0.020 [6360:384]

    Also the output video shows some artefacts every few seconds. Do you have any ideas, which switches I could play around with?

    Thanks,
    Frank

  2. Frank

    Hmmmm, actually adding ‘-demuxer lavf’ (without removing ‘-fps 50′) got rid of the artefacts.

    Also using ‘-ofps 25 -fps 50′ seems to silence the warnings about duplicate frames, but I still have to check more closely whether I am breaking something else with that. At first sight it seems like this is cutting away the first second(s)(?) for some reason.

  3. acmelab68 Post author

    Hi,
    first of all, thanks for feedback.
    It’s important to know, that most footages behaves differently. I’ve got a Panasonic HDC-SD100 and a Canon HF100. For the Panasonic I had to add the “-demuxer lavf” part. Do you have a PAL or an NTSC model? Do you record 25p/30p or 50i/60i, or even something completely different.

    Anyhow, I’m glad you got it working, and reported back here. Thanks a lot.

    Regards,
    Andreas

  4. acmelab68 Post author

    @oguh
    Dunno,
    but actually it won’t make much sense to me, because
    a) they almost never release
    b) the sources changes very much every day
    c) ./configure && make && make install isn’t very difficult

    But it’s worth to give Google a try if you like.

  5. Illtud

    Works great for me – one issue:

    you create a output-file.mpg, but your dvd.xml file references output_file.mpg

    Can you fix that typo? You’re quite high on the AVCHD/linux google hit, so fixing that tiny mistake will help a lot of people.

  6. bcat

    Thank you very much for posting this.

    It works perfectly for me, with the Sony AVCHD and 64bit SuSE 11.0.

    All software was installed using the repositories listed on the SuSE website.

    The resulting mpeg plays for me with Mplayer, VLC, Kaffeine, etc.

  7. Wizzu

    I have to second those “-ofps 25″ and “-demuxer lavf” suggestions, seems to work well for me (converting from Sony Handycam AVCHD to DVD).

    Also there’s a document at the MPlayer site
    http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html
    which says that PAL DVDs should use fps of 25.
    (For NTSC, obviously different, 30000/1001 or 24000/1001.)

    I’ve also added “vstrict=0″ to the -lavcopts because the above document recommends it for DVDs.

  8. qwerty

    Hey people ;-)
    I own Canon HF200 and play mts on Fedora 9 and Fedora 11 using mplayer SVN-r29189-snapshot-4.4.0 passing -fps50. I sometimes encounter artifacts and mplayer says:
    “[h264_vdpau @ 0xe08d60]illegal short term buffer state detected1 0
    [h264_vdpau @ 0xe08d60]Missing reference picture”.
    -demuxer lavf solved an issue but then mplayer played mts file in slow motion-like. Tried to removed -fps 50 (different values for fps/ofps, the same behavor).
    What ya think?

  9. Dogman

    Hello everybody.
    I’m a Linux-user and I have a Panasonic HDC-SD200 camcorder who also makes .MTS-files. I want to convert them to .mpg with the line who is given for the Terminal, but it doens’t work.

    If I type ‘>mencoder -oac copy -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576,harddup -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:aspect=16/9:threads=4 input-file.mts -ofps 50 -demuxer lavf -o output_file.mpg’
    -> it says: bash: -oac: command not found

    Could someone help me?
    Thanks in advance.

  10. MarcWN

    Remove the “>” from the beginning of your command, then it should work. It thinks you are trying to run the “>mencoder” command, but the “>” actually just signifies the command line (terminal).

  11. Dogman

    I removed the “>”, but it still doesn’t work.
    Now de Terminal says:
    ————————————————————–
    MEncoder 2:1.0~rc2-0ubuntu13.1 (C) 2000-2007 MPlayer Team
    CPU: Intel(R) Core(TM)2 Duo CPU T5550 @ 1.83GHz (Family: 6, Model: 15, Stepping: 13)
    CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
    Compiled with runtime CPU detection.
    File not found: ‘input-file.mts’
    Failed to open input-file.mts.
    Cannot open file/device.

    Exiting…
    ————————————————————–
    I have renamed the file I want to convert to ‘input-file.mts’.
    Do I have to put the adress of the file in the command? Or is it something else?

  12. MarcWN

    Make sure the file extension is not “.MTS” as that would be different from “.mts”.

    Other than that, post the output of the “ls” command. Or type “ls input-file.mts” and post the output of that. You might be in the wrong folder in the terminal.

  13. Dogman

    I think I’m in the good folder in the Terminal now.
    Only the Terminal still doesn’t convert the file.

    ———————————————————————
    MEncoder 2:1.0~rc2-0ubuntu13.1 (C) 2000-2007 MPlayer Team
    CPU: Intel(R) Core(TM)2 Duo CPU T5550 @ 1.83GHz (Family: 6, Model: 15, Stepping: 13)
    CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
    Compiled with runtime CPU detection.
    success: format: 0 data: 0×0 – 0x5e2e8800
    libavformat file format detected.
    [h264 @ 0x8814710]PAFF interlacing is not implemented
    [h264 @ 0x8814710]concealing 4080 DC, 4080 AC, 4080 MV errors
    [lavf] Video stream found, -vid 0
    [lavf] Audio stream found, -aid 1
    [lavf] Audio stream found, -aid 2
    VIDEO: [H264] 1920×1080 0bpp 25.000 fps 0.0 kbps ( 0.0 kbyte/s)
    [V] filefmt:35 fourcc:0×34363248 size:1920×1080 fps:25.00 ftime:=0.0400
    PACKET SIZE: 2048 bytes, deltascr: 43885
    Opening video filter: [expand osd=1]
    Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
    Opening video filter: [harddup]
    Opening video filter: [scale w=720 h=576]
    ==========================================================================
    Opening video decoder: [ffmpeg] FFmpeg’s libavcodec codec family
    Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
    ==========================================================================
    audiocodec: framecopy (format=2000 chans=6 rate=48000 bits=0 B/s=48000 sample-0)
    Limiting audio preload to 0.4s.
    Increasing audio density to 4.
    [h264 @ 0x8814710]PAFF interlacing is not implemented
    [h264 @ 0x8814710]concealing 4080 DC, 4080 AC, 4080 MV errors
    VDec: vo config request – 1920 x 1080 (preferred colorspace: Planar YV12)
    VDec: using Planar YV12 as output csp (no 0)
    Movie-Aspect is 1.78:1 – prescaling to correct movie aspect.
    SwScaler: reducing / aligning filtersize 12 -> 12
    SwScaler: reducing / aligning filtersize 12 -> 12
    SwScaler: reducing / aligning filtersize 9 -> 8
    SwScaler: reducing / aligning filtersize 9 -> 8
    [swscaler @ 0x880f730]SwScaler: BICUBIC scaler, from yuv420p to yuv420p using MMX2
    [swscaler @ 0x880f730]SwScaler: using n-tap MMX scaler for horizontal luminance scaling
    [swscaler @ 0x880f730]SwScaler: using n-tap MMX scaler for horizontal chrominance scaling
    [swscaler @ 0x880f730]SwScaler: using n-tap MMX scaler for vertical scaling (YV12 like)
    [swscaler @ 0x880f730]SwScaler: 1920×1080 -> 720×576
    videocodec: libavcodec (720×576 fourcc=3267706d [mpg2])
    Writing header…
    INITV: 0.200, 0.180, fps: 50.000
    [h264 @ 0x8814710]PAFF interlacing is not implemented A-V:0.000 [0:0]
    [h264 @ 0x8814710]top block unavailable for requested intra mode at 39 1
    [h264 @ 0x8814710]error while decoding MB 39 1, bytestream (53724)
    [h264 @ 0x8814710]illegal short term buffer state detected
    [h264 @ 0x8814710]concealing 8160 DC, 8160 AC, 8160 MV errors
    Segmentation fault
    ———————————————————————
    What means this all?

  14. TimA

    Thanks for this! Sucessfully converted video from my Panasonic HDC SD20 using some of these instructions.

    Using ubuntu 9.04 jaunty.

    Connected camera via usb.

    Simply copied the AVCHD folder under the top level PRIVATE folder. You actually just need the MTS files in the AVCHD/BDMV/STREAM folder.

    I Installed the WinFF (via ubuntu menu Applications/Add&Remove). WinFF is just a front end to ffmpeg.

    In WinFF, I dragged and dropped all the MTS files to WinDD.

    In WinFF,Then I selected the “Output Details” and picked “Convert to: DVD”. “Device Preset” PAL DVD HQ (16:9).

    VERY IMPORTANT: I had to set “Additional Options/Audio Settings/Audio Channels: 2″. Otherwise I got an error on the console when trying to convert: “Error while opening codec for output stream #0.1 – maybe incorrect parameters such as bit_rate, rate, width or height”.

    In WinFF, click Convert. Its very very slow: 8 hours per hour of video!

    I ended up with one output mpg file per input MTS file.

    From here, I used the instructions above:

    dvdauthor -o dvd -x dvd.xml

    Check it worked with

    mplayer dvd:// -dvd-device ./dvd

    growisofs -dvd-compat -Z /dev/dvdrw -dvd-video ./dvd/

  15. Wizzu

    Hi,

    These days there’s more Linux video editors out there. The latest I tried is OpenShot (still evaluating, but it looks promising). If you’re willing to try the development version, you can install it on Ubuntu by following the instructions here:
    http://www.openshotvideo.com/2008/04/ppa-instructions.html

    OpenShot seems to support also Blu-Ray in addition to DVD, which is nice for those HD videos. I won’t be able to try that out yet, because I don’t have a Blu-Ray player nor Blu-Ray writing drive in my computer.

    For a nice overview of the available Linux video editors (done in september 2009, not quite current but a lot more recent than most other things I seem to find), look at http://www.tannerhelland.com/commentary/ubuntu-linux/day-5-ubuntu-10-10-features/

  16. pbt

    For Panasonic HDC-HS60 I used this:

    for file in *.MTS; do
    mencoder -demuxer lavf -oac copy -ovc lavc -of mpeg -mpegopts format=dvd -vf yadif,scale=720:576,harddup -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9000:vbitrate=5000:keyint=15:aspect=16/9:trell:vstrict=0 -ofps 25 -fps 50 -o $file.mpg $file
    done

    added options:
    yadif – for deinterlacing – without this moving objects on 25 fps has “ghosts” from previous/next frame
    trell – for better quality
    vstrict=0 – for better compatibility with standalone players

  17. Pingback: [??] ??? Ubuntu ??AVCHD mts ?? DVD Video – Sense's Blog

Comments are closed.