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.
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
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
Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.
Hi web,
Quote:
Originally Posted by
webdevelopment
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
Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.
Quote:
Originally Posted by
andrew.46
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...
Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.
Use MediaInfo to show your before and after files.
Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.
Quote:
Originally Posted by
ron999
Use MediaInfo to show your before and after files.
where do i get this? its not in my synaptec installer
Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.
download mediainfo from their site now it requires libmediainfo0 which is not easy to find... this is down the rabbit hole of crappy linux stuff
Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.
winff to convert MTS (sony HD cam) to MPEG4 but it's giving me an output of 15 frames per second even though my source video files are 30 frames per second...
how do i fix this?
also, whats the best and easiest video editor for MTS/mpeg4 1080p files? i just need to put in some titles and cut/splice out unwanted video scenes, but i need a video editor that wont crash.
Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.
how do i change this to preserve the original dimensions, bitrate, and fps? i tried entering 30fps in the additional options in WinFF but it ignored them as you can see below and converted my HD video at a 704x384 size and lower bitrate and lower fps...
Quote:
FFmpeg version SVN-r19352-4:0.5+svn20090706-2ubuntu2.2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --extra-version=4:0.5+svn20090706-2ubuntu2.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --extra-cflags=-I/build/buildd/ffmpeg-0.5+svn20090706/debian/include --enable-shared --disable-static
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 0 / 52.20. 0
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Apr 23 2010 15:38:06, gcc: 4.4.1
Input #0, mpegts, from '/home/admin1/Pictures/00031.MTS':
Duration: 00:01:41.63, start: 1.000067, bitrate: 17131 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
Output #0, mp4, to '/home/admin1/00031.mp4':
Stream #0.0: Video: libx264, yuv420p, 704x384 [PAR 32:33 DAR 16:9], q=10-51, 1250 kb/s, 90k tbn, 30 tbc
Stream #0.1: Audio: libfaac, 48000 Hz, stereo, s16, 112 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
[libx264 @ 0x1f50d40]using SAR=32/33
[libx264 @ 0x1f50d40]using cpu capabilities: MMX2 SSE2Fast FastShuffle SSEMisalign LZCNT
[libx264 @ 0x1f50d40]profile Main, level 3.0
Press [q] to stop encoding
frame= 1938 fps= 9 q=22.0 Lsize= 10753kB time=63.87 bitrate=1379.2kbits/s
video:9836kB audio:872kB global headers:1kB muxing overhead 0.415946%
[libx264 @ 0x1f50d40]slice I:621 Avg QP:24.70 size: 5383
[libx264 @ 0x1f50d40]slice P:378 Avg QP:20.23 size: 9592
[libx264 @ 0x1f50d40]slice B:939 Avg QP:21.61 size: 3305
[libx264 @ 0x1f50d40]consecutive B-frames: 4.3% 1.5% 0.9% 93.2%
[libx264 @ 0x1f50d40]mb I I16..4: 72.7% 0.0% 27.3%
[libx264 @ 0x1f50d40]mb P I16..4: 14.6% 0.0% 13.6% P16..4: 39.8% 18.1% 10.5% 0.0% 0.0% skip: 3.3%
[libx264 @ 0x1f50d40]mb B I16..4: 2.2% 0.0% 1.1% B16..8: 65.5% 2.1% 5.3% direct: 2.3% skip:21.5% L0:37.7% L1:53.0% BI: 9.3%
[libx264 @ 0x1f50d40]coded y,uvDC,uvAC intra:65.8% 72.6% 23.4% inter:18.2% 42.4% 2.7%
[libx264 @ 0x1f50d40]SSIM Mean Y:0.9571350
[libx264 @ 0x1f50d40]kb/s:1247.3
Press Enter to Continue