Results 1 to 10 of 22

Thread: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.

Hybrid View

  1. #1
    Join Date
    Jul 2005
    Beans
    16

    How to convert AVCHD (MTS/M2TS) to MP4 losslessly.

    I'll start with the end:

    Code:
    mencoder infile.mts -demuxer lavf -oac copy -ovc copy -of lavf=mp4 -o outfile.mp4
    ..and now to explain myself:

    AVCHD (MTS) is basically a container format for MPEG4-AVC video and AC-3 Audio. It's commonly found on modern camcorders. I have pulled files off a Sony Camcorder (I forget which model), which records in 1080i@50Hz. It seems there are timestamp problems, and both the even and odd fields are stamped with the same time, and not 1/50th of a second apart as you'd expect. This currently breaks ffmpeg (0.6~svn20100711), and the mencoder (SVN-r31722) internal demuxer doesn't like it either. The libavformat (lavf 0.6~svn20100711) demuxer/muxer seems to handle it, so that's what we'll use.

    If you run 'mediainfo' over an MTS file, you'll see something like this:

    Code:
    General
    ID                               : 0
    Complete name                    : infile.mts
    Format                           : BDAV
    Format/Info                      : Blu-ray Video
    File size                        : 62.6 MiB
    Duration                         : 56s 72ms
    Overall bit rate                 : 9 364 Kbps
    Maximum Overall bit rate         : 18.0 Mbps
    
    Video
    ID                               : 4113 (0x1011)
    Menu ID                          : 1 (0x1)
    Format                           : AVC
    Format/Info                      : Advanced Video Codec
    Format profile                   : High@L4.0
    Format settings, CABAC           : Yes
    Format settings, ReFrames        : 2 frames
    Duration                         : 56s 0ms
    Bit rate                         : 8 726 Kbps
    Width                            : 1 440 pixels
    Height                           : 1 080 pixels
    Display aspect ratio             : 16:9
    Frame rate                       : 25.000 fps
    Resolution                       : 8 bits
    Colorimetry                      : 4:2:0
    Scan type                        : Interlaced
    Scan order                       : Top Field First
    Bits/(Pixel*Frame)               : 0.224
    Stream size                      : 58.3 MiB (93%)
    
    Audio
    ID                               : 4352 (0x1100)
    Menu ID                          : 1 (0x1)
    Format                           : AC-3
    Format/Info                      : Audio Coding 3
    Duration                         : 56s 128ms
    Bit rate mode                    : Constant
    Bit rate                         : 256 Kbps
    Channel(s)                       : 2 channels
    Channel positions                : Front: L R
    Sampling rate                    : 48.0 KHz
    Video delay                      : -80ms
    Stream size                      : 1.71 MiB (3%)
    
    Text
    ID                               : 4608 (0x1200)
    Menu ID                          : 1 (0x1)
    Format                           : PGS
    Duration                         : 55s 575ms
    Video delay                      : -80ms

    Once you run it through the above command, the resultant container will look like this. The audio/video codec details will be the same because it's a straight (lossless) copy. Also note that the headers have been corrected from 25i to 50i.

    Code:
    General
    Complete name                    : outfile.mp4
    Format                           : MPEG-4
    Format profile                   : Base Media
    Codec ID                         : isom
    File size                        : 58.7 MiB
    Duration                         : 56s 160ms
    Overall bit rate                 : 8 761 Kbps
    Writing application              : Lavf52.73.0
    
    Video
    ID                               : 1
    Format                           : AVC
    Format/Info                      : Advanced Video Codec
    Format profile                   : High@L4.0
    Format settings, CABAC           : Yes
    Format settings, ReFrames        : 2 frames
    Format_Settings_FrameMode        : Frame tripling
    Codec ID                         : avc1
    Codec ID/Info                    : Advanced Video Coding
    Duration                         : 56s 140ms
    Bit rate mode                    : Variable
    Bit rate                         : 8 504 Kbps
    Width                            : 1 440 pixels
    Height                           : 1 080 pixels
    Display aspect ratio             : 4:3
    Original display aspect ratio    : 16:9
    Frame rate mode                  : Constant
    Frame rate                       : 50.000 fps
    Original frame rate              : 8.333 fps
    Resolution                       : 8 bits
    Colorimetry                      : 4:2:0
    Scan type                        : Interlaced
    Scan order                       : Top Field First
    Bits/(Pixel*Frame)               : 0.109
    Stream size                      : 56.9 MiB (97%)
    
    Audio
    ID                               : 2
    Format                           : AC-3
    Format/Info                      : Audio Coding 3
    Codec ID                         : ac-3
    Duration                         : 56s 160ms
    Bit rate mode                    : Constant
    Bit rate                         : 256 Kbps
    Channel(s)                       : 2 channels
    Channel positions                : Front: L R
    Sampling rate                    : 48.0 KHz
    Resolution                       : 16 bits
    Stream size                      : 1.71 MiB (3%)
    Note that the final video will still be interlaced. Removing the interlacing requires re-encoding.

    This was tested on 10.04 with the VDPAU team's cutting-edge-multimedia PPA installed.
    Last edited by pHr34kY; September 11th, 2010 at 11:55 AM.

  2. #2
    Join Date
    Nov 2008
    Location
    Melbourne
    Beans
    165

    Talking Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.

    I want to do this on files from a canon hg-21. Here is my output from mediainfo:


    General
    ID : 0
    Complete name : 00069.MTS
    Format : BDAV
    Format/Info : BluRay Video
    File size : 272 MiB
    Duration : 1mn 36s
    Overall bit rate : 23.8 Mbps
    Maximum Overall bit rate : 24.0 Mbps

    Video
    ID : 4113 (0x1011)
    Menu ID : 1 (0x1)
    Format : AVC
    Format/Info : Advanced Video Codec
    Format profile : High@L4.0
    Format settings, CABAC : Yes
    Format settings, ReFrames : 2 frames
    Duration : 1mn 35s
    Bit rate : 22.6 Mbps
    Width : 1 920 pixels
    Height : 1 080 pixels
    Display aspect ratio : 16/9
    Frame rate : 29.970 fps
    Resolution : 24 bits
    Colorimetry : 4:2:0
    Scan type : Interlaced
    Scan order : Top Field First
    Bits/(Pixel*Frame) : 0.363

    Audio
    ID : 4352 (0x1100)
    Menu ID : 1 (0x1)
    Format : AC-3
    Format/Info : Audio Coding 3
    Duration : 1mn 36s
    Bit rate mode : Constant
    Bit rate : 256 Kbps
    Channel(s) : 2 channels
    Channel positions : L R
    Sampling rate : 48.0 KHz
    Video delay : -66ms


    This is after conversion:


    General
    Complete name : RyanFreakout.mp4
    Format : MPEG-4
    Format profile : Base Media
    Codec ID : isom
    File size : 260 MiB
    Duration : 1mn 36s
    Overall bit rate : 22.7 Mbps
    Encoded date : UTC 1970-01-01 00:00:00
    Tagged date : UTC 1970-01-01 00:00:00
    Writing application : Lavf52.31.0

    Video
    Format : AVC
    Format/Info : Advanced Video Codec
    Format profile : High@L4.0
    Format settings, CABAC : Yes
    Format settings, ReFrames : 2 frames
    Codec ID : avc1
    Codec ID/Info : Advanced Video Coding
    Duration : 1mn 36s
    Bit rate mode : Variable
    Bit rate : 22.4 Mbps
    Width : 1 920 pixels
    Height : 1 080 pixels
    Display aspect ratio : 16/9
    Frame rate mode : Constant
    Frame rate : 59.940 fps
    Original frame rate : 29.970 fps
    Resolution : 24 bits
    Colorimetry : 4:2:0
    Scan type : Progressive
    Bits/(Pixel*Frame) : 0.181
    Stream size : 257 MiB (99%)
    Encoded date : UTC 1970-01-01 00:00:00
    Tagged date : UTC 1970-01-01 00:00:00

    Audio
    Format : AC-3
    Format/Info : Audio Coding 3
    Codec ID : ac-3
    Duration : 1mn 36s
    Bit rate mode : Constant
    Bit rate : 256 Kbps
    Channel(s) : 2 channels
    Channel positions : L R
    Sampling rate : 48.0 KHz
    Resolution : 16 bits
    Stream size : 2.93 MiB (1%)
    Encoded date : UTC 1970-01-01 00:00:00
    Tagged date : UTC 1970-01-01 00:00:00


    Does everything look right? The playback on .mp4 is still obviously interlaced but it seems to be worse than before. When usually I get better playback. Previously, I had always used Adobe Media Encoder on Windows (deinterlaces the file). Can I deinterlace this file (reencode with mencoder)? Are my settings right for converting this like yours?

    Cheers

  3. #3
    Join Date
    Sep 2009
    Beans
    52

    Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.

    looking to convert MTS into a usable format too...

    WinFF gives this error when trying to convert MTS files:

    Input #0, mpegts, from '/home/admin1/Pictures/AVCHD/BDMV/STREAM/00000.MTS':
    Duration: 00:04:56.32, start: 1.000067, bitrate: 17173 kb/s
    Program 1
    Stream #0.0[0x1011]: Video: h264, yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], 59.94 tbr, 90k tbn, 59.94 tbc
    Stream #0.1[0x1100]: Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s
    Unknown encoder 'libmp3lame'
    Press Enter to Continue

  4. #4
    Join Date
    Dec 2006
    Beans
    6,922

    Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.

    Hi web,

    Quote Originally Posted by webdevelopment View Post
    Code:
    Unknown encoder 'libmp3lame'
    Looks like your copy of FFmpeg has not been compiled for mp3 encoding, have a look here for the fix:

    HOWTO: Easily enable MP3, MPEG4, AAC, and other restricted encoders in FFmpeg
    http://ubuntuforums.org/showthread.php?t=1117283

    Andrew
    You think that's air you're breathing now?

  5. #5
    Join Date
    Sep 2009
    Beans
    52

    Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.

    Quote Originally Posted by andrew.46 View Post
    Hi web,



    Looks like your copy of FFmpeg has not been compiled for mp3 encoding, have a look here for the fix:

    HOWTO: Easily enable MP3, MPEG4, AAC, and other restricted encoders in FFmpeg
    http://ubuntuforums.org/showthread.php?t=1117283

    Andrew
    thanks!

    this worked...

    solution was to download winff then install the medibuntu codecs

    but i converted to mp4 and the output is only 15fps (using winff)

    i'm almost certain the source vidoe is 30fps 1080p HD video...

    how do i get a better output? (i guess the term is lossless?)

    i'd like the highest quality source that i can use from the MTS files...

  6. #6
    Join Date
    Jul 2006
    Location
    Lancashire
    Beans
    Hidden!
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.

    Use MediaInfo to show your before and after files.

  7. #7
    Join Date
    Mar 2008
    Beans
    29

    Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.

    Very good post. Very useful. It solved one of my problems. Now my question is how do you include the text stream as well, the PGS?

    Thanks

    Quote Originally Posted by pHr34kY View Post
    I'll start with the end:

    Code:
    mencoder infile.mts -demuxer lavf -oac copy -ovc copy -of lavf=mp4 -o outfile.mp4
    ..

  8. #8
    Join Date
    Oct 2010
    Location
    Not far from here at all.
    Beans
    3
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.

    How would you adapt your command for a media info output such as :

    $ mediainfo 00047.MTS
    General
    ID : 0 (0x0)
    Complete name : 00047.MTS
    Format : BDAV
    Format/Info : Blu-ray Video
    File size : 25.8 MiB
    Duration : 20s 974ms
    Overall bit rate mode : Variable
    Overall bit rate : 10.3 Mbps
    Maximum Overall bit rate : 18.0 Mbps

    Video
    ID : 4113 (0x1011)
    Menu ID : 1 (0x1)
    Format : AVC
    Format/Info : Advanced Video Codec
    Format profile : High@L4.0
    Format settings, CABAC : Yes
    Format settings, ReFrames : 2 frames
    Format settings, GOP : M=2, N=15
    Codec ID : 27
    Duration : 20s 954ms
    Bit rate mode : Variable
    Bit rate : 9 432 Kbps
    Maximum bit rate : 16.0 Mbps
    Width : 1 440 pixels
    Height : 1 080 pixels
    Display aspect ratio : 16:9
    Frame rate : 29.970 fps
    Color space : YUV
    Chroma subsampling : 4:2:0
    Bit depth : 8 bits
    Scan type : Interlaced
    Scan order : Top Field First
    Bits/(Pixel*Frame) : 0.202
    Stream size : 23.6 MiB (91%)

    Audio
    ID : 4352 (0x1100)
    Menu ID : 1 (0x1)
    Format : AC-3
    Format/Info : Audio Coding 3
    Mode extension : CM (complete main)
    Codec ID : 129
    Duration : 21s 24ms
    Bit rate mode : Constant
    Bit rate : 448 Kbps
    Channel(s) : 6 channels
    Channel positions : Front: L C R, Side: L R, LFE
    Sampling rate : 48.0 KHz
    Bit depth : 16 bits
    Compression mode : Lossy
    Delay relative to video : -67ms
    Stream size : 1.12 MiB (4%)

    Text
    ID : 4608 (0x1200)
    Menu ID : 1 (0x1)
    Format : PGS
    Codec ID : 144
    Duration : 20s 455ms
    Delay relative to video : -67ms

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •