Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22

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

  1. #11
    Join Date
    Sep 2006
    Beans
    3,713

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

    You can use FFmpeg directly to copy the video and audio into a MP4 container:
    Code:
    ffmpeg -i 00031.MTS -vcodec copy -acodec copy output.mp4
    You can then combine this with find to do a batch type conversion:

    Linux Basics: A gentle introduction to 'find'

    Or you could make a new WinFF preset based on my example.

  2. #12
    Join Date
    Sep 2009
    Beans
    52

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

    here is the mpeg4 preset in WinFF

    <?xml version="1.0"?>
    <presets>
    <x264HQWS>
    <label>MP4 Widescreen</label>
    <params>-f mp4 -r 29.97 -vcodec libx264 -s 704x384 -b 1000kb -aspect 16:9 -flags +loop -cmp +chroma -deblockalpha 0 -deblockbeta 0 -b 1250k -maxrate 1500k -bufsize 4M -bt 256k -refs 1 -bf 3 -coder 1 -me_method umh -me_range 16 -subq 7 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -g 250 -keyint_min 25 -level 30 -qmin 10 -qmax 51 -qcomp 0.6 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -acodec libfaac -ab 112kb -ar 48000 -ac 2</params>
    <extension>mp4</extension>
    <category>MPEG4</category>
    </x264HQWS>
    </presets>
    where can i find one that is for 1080p HD MPEG4?

  3. #13
    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
    ..

  4. #14
    Join Date
    Oct 2010
    Location
    Not far from here at all.
    Beans
    7
    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

  5. #15
    Join Date
    Dec 2012
    Beans
    1

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

    Hi:

    This is indeed a very useful thread. I was working a lot on a smooth way to convert MTS to a more useful mp4 container without recompress it (loosely). I use for it ffmpeg.. and I correct timestamp issues.. but I couldn't fix the issue on converting to mp4 AC3 5.1..

    let's take video 1 (MTS format). This is what mediainfo says:

    General
    ID : 0 (0x0)
    Complete name : 1.MTS
    Format : BDAV
    Format/Info : Blu-ray Video
    File size : 96.3 MiB
    Duration : 47s 287ms
    Overall bit rate mode : Variable
    Overall bit rate : 17.1 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 : 46s 480ms
    Bit rate mode : Variable
    Bit rate : 16.0 Mbps
    Width : 1 920 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.257
    Stream size : 88.3 MiB (92%)

    Audio
    ID : 4352 (0x1100)
    Menu ID : 1 (0x1)
    Format : AC-3
    Format/Info : Audio Coding 3
    Mode extension : CM (complete main)
    Format settings, Endianness : Big
    Codec ID : 129
    Duration : 46s 560ms
    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
    Stream size : 2.49 MiB (3%)

    Text
    ID : 4608 (0x1200)
    Menu ID : 1 (0x1)
    Format : PGS
    Codec ID : 144
    Duration : 45s 981ms

    ok.. 6 channels..

    so I run my ffmpeg command on a batch:

    for f in *.MTS

    do

    DATE=$(exiftool-5.12 -d "%Y-%m-%d %H:%M:%S" "$f" | grep Date.*Original | awk '{print $4, $5;}')


    ffmpeg -i "$f" -y -acodec copy -vcodec copy -f mp4 -metadata creation_time="$DATE" "./original/${f%.MTS}.MP4"


    done


    Here is the mediainfo output of the MP4...

    General
    Complete name : 1.MP4
    Format : MPEG-4
    Format profile : Base Media
    Codec ID : isom
    File size : 91.2 MiB
    Duration : 46s 560ms
    Overall bit rate mode : Variable
    Overall bit rate : 16.4 Mbps
    Encoded date : UTC 2012-10-27 11:07:24
    Tagged date : UTC 2012-10-27 11:07:24
    Writing application : Lavf54.29.104

    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, GOP : M=2, N=15
    Codec ID : avc1
    Codec ID/Info : Advanced Video Coding
    Duration : 46s 547ms
    Bit rate mode : Variable
    Bit rate : 16.0 Mbps
    Width : 1 920 pixels
    Height : 1 080 pixels
    Display aspect ratio : 16:9
    Frame rate mode : Variable
    Frame rate : 59.940 fps
    Original frame rate : 29.970 fps
    Minimum frame rate : 59.920 fps
    Maximum frame rate : 59.960 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.129
    Stream size : 88.6 MiB (97%)
    Encoded date : UTC 2012-10-27 11:07:24
    Tagged date : UTC 2012-10-27 11:07:24

    Audio
    ID : 2
    Format : AC-3
    Format/Info : Audio Coding 3
    Mode extension : CM (complete main)
    Format settings, Endianness : Big
    Codec ID : ac-3
    Duration : 46s 560ms
    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
    Stream size : 2.49 MiB (3%)
    Encoded date : UTC 2012-10-27 11:07:24
    Tagged date : UTC 2012-10-27 11:07:24

    but Exiftool said:

    ExifTool Version Number : 9.06
    File Name : 1.MP4
    Directory : .
    File Size : 91 MB
    File Modification Date/Time : 2012:12:10 02:12:46+01:00
    File Access Date/Time : 2012:12:10 02:14:25+01:00
    File Permissions : rw-r--r--
    File Type : MP4
    MIME Type : video/mp4
    Major Brand : MP4 Base Media v1 [IS0 14496-12:2003]
    Minor Version : 0.2.0
    Compatible Brands : isom, iso2, avc1, mp41
    Movie Data Size : 95557281
    Movie Header Version : 0
    Create Date : 2012:10:27 11:07:24
    Modify Date : 2012:10:27 11:07:24
    Time Scale : 1000
    Duration : 0:00:46
    Preferred Rate : 1
    Preferred Volume : 100.00%
    Preview Time : 0 s
    Preview Duration : 0 s
    Poster Time : 0 s
    Selection Time : 0 s
    Selection Duration : 0 s
    Current Time : 0 s
    Next Track ID : 3
    Track Header Version : 0
    Track Create Date : 2012:10:27 11:07:24
    Track Modify Date : 2012:10:27 11:07:24
    Track ID : 1
    Track Duration : 0:00:46
    Track Layer : 0
    Track Volume : 0.00%
    Image Width : 1920
    Image Height : 1080
    Graphics Mode : srcCopy
    Op Color : 0 0 0
    Compressor ID : avc1
    Source Image Width : 1920
    Source Image Height : 1080
    X Resolution : 72
    Y Resolution : 72
    Bit Depth : 24
    Video Frame Rate : 59.94
    Matrix Structure : 1 0 0 0 1 0 0 0 1
    Media Header Version : 0
    Media Create Date : 2012:10:27 11:07:24
    Media Modify Date : 2012:10:27 11:07:24
    Media Time Scale : 48000
    Media Duration : 0:00:46
    Media Language Code : und
    Handler Description : SoundHandler
    Balance : 0
    Audio Channels : 2
    Audio Bits Per Sample : 16
    Audio Sample Rate : 48000
    Handler Type : Metadata
    Handler Vendor ID : Apple
    Encoder : Lavf54.29.104
    Avg Bitrate : 16.4 Mbps
    Image Size : 1920x1080
    Rotation : 0

    So... I lost 3 audio channels .. on exiftool but mediainfo gaves me a perfect conversion...

    how can I be sure that I have a loosely audio and video MP4 file? which of them lies?


    Any help?

    Thanks
    Last edited by alvgarci; December 10th, 2012 at 02:21 AM. Reason: Error

  6. #16
    Join Date
    Jul 2012
    Beans
    322
    Distro
    Xubuntu 18.04 Bionic Beaver

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

    My problem on converting mts files and re-encoding them (say for example I have 4 x 4gb MTS files with a 1.5 hour runtime in total, and these need to be encoded to fit on a DVD). All attempts whether directly using ffmpeg (compiled) or WinFF or on W7 DVD Flick or winff result in an audio delay.

    Now I normally get an a/v delay if I try to encode ts files from my dvb stick. I get round this by demuxing them using ProjectX then encdoing the video and audio separately before muxing them back together. However ProjectX won't demux my mts files

    Is there a fix in ffmpeg for this a/v delay (Video is running slightly behind audio, at the same gap throughout the encode - e.g. it doesn't get worse as time progresses.....
    The best things in life are free, so what are we paying for?

  7. #17
    Join Date
    Apr 2009
    Location
    Aotearoha
    Beans
    2,692
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    m2ts & mpeg-ts files have PTS presentation time stamps for all streams.
    It is normal for dvb OTA mpegts to have 2 seconds delay between video & audio so the decoder can handle out-of-order video encoding & post process video.

    I don't have any a/v sync problems using ffmpeg on with mpegts files for selective stream transcoding/removal. I just use mpeg(2)-ts output container
    -f mpegts

    If you convert these to a deprecated container like AVI then you get a/v sync problems.
    I believe you have to fine-tune the a/v sync with ‘-delay[:stream_specifier] integer ()’ to find a solution for your DVD player & use constant bitrate & packed B frames etc.

    If you are remuxing into mkv or mpeg4 container then this could help:
    -vsync passthrough -copyts

  8. #18
    Join Date
    Jul 2012
    Beans
    322
    Distro
    Xubuntu 18.04 Bionic Beaver

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

    Thanks Bicycler Boy, useful info.

    Using -f mpegts as an output will mean no encoding or reduction in filesize I am guessing? (Hence no problem with A/V sync )

    I've got to get from 16GB of video down to 4.3Gb
    Last edited by Merrattic; December 17th, 2012 at 03:31 PM.
    The best things in life are free, so what are we paying for?

  9. #19
    Join Date
    Apr 2009
    Location
    Aotearoha
    Beans
    2,692
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    Most of what I just posted is of little use here..

    The transport stream formats have 10%-20% overhead (over PS) but can be cut & joined & seeked at random.

    The PS & TS & mkv containers have audio & video packet timing info.

    Problems start when trying to stuff modern video codecs into AVI container as it does not have adequate timing info. It needs constant frame rate & bitrates & lots of stuffing tricks to allow out-of-order frames.

    Are you trying to make a DVD-video (mpeg2 PS VOB) or *.avi (DVD data)?

    The AVI method could let you to use DivX compression.

  10. #20
    Join Date
    Jul 2012
    Beans
    322
    Distro
    Xubuntu 18.04 Bionic Beaver

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

    Seems OK now, found that outputting to -target pal-dvd gives good a/v sync and the right file size
    The best things in life are free, so what are we paying for?

Page 2 of 3 FirstFirst 123 LastLast

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
  •