34

I posted an same question to another community Video Production that I've found later, and which seems to be a better place for this question:

See: https://video.stackexchange.com/questions/12156/how-can-i-convert-mts-file-avchd-to-mp4-by-ffmpeg-without-re-encoding-h264-v/


1. What I tried

I have some .MTS (AVCHD format) files recoreded with my AVCHD camera. Its specification is as shown below:

$ ffprobe 140612_Canon-00000.MTS 
ffprobe version 2.2.1 Copyright (c) 2007-2014 the FFmpeg developers
(snip)
Input #0, mpegts, from '140612_Canon-00000.MTS':
  Duration: 00:48:58.40, start: 0.800300, bitrate: 5563 kb/s
  Program 1 
    Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), 
      yuv420p, 1440x1080 [SAR 4:3 DAR 16:9], 
      29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x1100]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 
      stereo, fltp, 256 kb/s

Pay attention to the part of framerate/timebase: 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc

Now I’d like to convert this file to .mp4 file, without re-encoding H264 video stream, on the other hand, with transcoding its audio stream to AAC. So I tried the following command:

ffmpeg -i 140612_Canon-00000.MTS -t 60 -y -vcodec copy -acodec libfaac -ab 128k 140612_Canon-00001.MTS.mp4

2. Result

and output file’s specification is as shown below:

$ ffprobe 140612_Canon-00000.MTS.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '140612_Canon-00000.MTS.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.33.100

  Duration: 00:01:00.04, start: 0.021333, bitrate: 4590 kb/s

    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 
        1440x1080 [SAR 4:3 DAR 16:9], 4448 kb/s, 
        59.94 fps, 59.94 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler

    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 
        48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

Look at the part of framerate/timebase: 59.94 fps, 59.94 tbr, 90k tbn, 59.94 tbc. Although ffmpeg just copied the video stream, framerate and timebase has been changed to twice value.

So, when I open and playback the output file with QuickTime Player or VLC Player, the audio has no problem, however, the video stream is not played correctly. The video is played back with having its frame forward and backward quiveringly repeatedly.

3. Question

  1. How can I convert .MTS file (AVCHD) to .mp4 by ffmpeg without re-encoding H264 video stream correctly?
  2. How can I keep the original framerate/timebase values (fps/tbr/tbn/tbc) when I convert the container with ffmpeg and its -vcodec copy switch.
  3. How can I set framerate/timebase values (fps/tbr/tbn/tbc) by ffmpeg’s command line options without re-encoding a video stream.

Any ideas?

2 Answers 2

50

Here it is:

ffmpeg -i input.m2ts -c:v copy -c:a aac -strict experimental -b:a 128k output.mp4

This will only copy the video stream without re-encoding and encode the audio track to AAC VBR stereo, it requires a recent FFmpeg version.

6
  • 1
    why does the output size reduce significantly when I omit -c:v copy? The quality (as far as I noticed) is the same.
    – Emadpres
    Feb 20, 2018 at 22:13
  • It is because it is being encoded, the "-c" flag defines the codec to use, the "-c:v" defines the video codec, you can find more on encoding here: trac.ffmpeg.org/wiki/Encode/H.264 Nov 6, 2018 at 0:40
  • FYI: You may also want to add as a tip, that MTS typically uses ac3 encoding. To do a direct extraction of ac3 audio, use ffmpeg -i ${INPUT}.MTS -vn -acodec copy ${OUTPUT}.ac3.
    – Brian
    Dec 13, 2019 at 9:58
  • Indeed, BTW ac3to is a great tool for demuxing, here is a full guide I wrote a couple of years ago github.com/rodrigopolo/brripguide/blob/master/guide_en.md Dec 15, 2019 at 4:09
  • 1
    I gave this command {ffmpeg -i input.m2ts -c:v copy -c:a aac -strict experimental -b:a 128k output.mp4} but the size of the output file remained the same large as the input file. Any sugestions how can I reduce the output file size?
    – vincent
    Mar 21, 2020 at 22:45
4

Since there are always multiple files we need to combine, I find the following command helpful in doing it.

$ ffmpeg -i "concat:$(echo *.MTS | tr ' ' '|')" out.mp4

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.