Answers.Body: <p>Seeing that in the text of your question you have started discussing other utilities, i will assume that you are not interested in sticking with ffmpeg, but rather in getting the job done.</p>
  
  <p>In my experience with libav and MTS i have had no problems with the framerate, the files get remuxed perfectly.</p>
  
  <p>I have just attempted the following with one of my files:</p>
  
  <pre><code>avconv -i 00174.MTS -c:a copy -c:v copy 00174.mp4
  </code></pre>
  
  <p>The resulting MP4 file played correctly with VLC.</p>
  
  <p>My file is progressive MTS, i don't have any interlaced laying around, but if need be i can do more checking with that.</p>
  
  <p><strong>Report about the file test</strong></p>
  
  <p>The topic starter was able to provide a file, that was remuxed from MTS to MP4 and did not play on that person's machine with QuickTime Player (version unknown). It did, however, play with that individual's VLC player.</p>
  
  <p>I do not have a Mac OS computer, but i have tried it with Ubuntu.
  I have played it on Ubuntu on VLC (2.0.8) and GNOME Videos (used to be called Totem) (3.8.2); both play perfectly.</p>
  
  <p>I then asked a friend of mine, who is on a Mac to play it. He is on Mavericks (10.9.4), and it played fine with QuickTime Player 10.3 (727.4).</p>
  
  <p>At this time it appears to be a problem with the particular player or a problem with configuration settings on the computer. And it is probably best to attempt to update to the newest version of QTP, possibly with first removing the current version and completely wiping the old configuration.</p>
  
  <p><strong>Another possibility</strong></p>
  
  <p>When i have had an old machine i have had some high bitrate files play incorrectly in some players, and it was container specific. For example, VLC would refuse to play MTS file, it would show a frame, and then show the next one only in a second and a half. GNOME Videos played it fine. But when remuxing it to MKV, both players played it reasonably well. This maybe a question of something similar. A player maybe reading a particular container (MP4 in this case) in a way that requires just enough CPU time, that it begins to choke itself. The jerkiness effect can be then attributed to whatever subprocess takes up CPU finishing, and player dumping all of the frames that were lagging behind very rapidly, after that the bad subprocess again kicks in, and the cycle keeps on going.</p>
  
  <p>In this possibility, the best option is still to try to upgrade the software. With the current multicore processors it would be difficult to test the need to upgrade the hardware without actually getting it, but maybe it is possible to look at the CPU load during the QuickTime Player useage and compare it to VLC. If you see 100% for any one core with QTP, that maybe indicative of this.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-19T13:35:23.590Z
Answers.Text: It's rather unlikely that avconv will do a different job for him. avconv is a fork of ffmpeg and ffmpeg is merging a lot of commits from the avconv project into ffmpeg, major bugs fixes like that would likely be present in ffmpeg.
Answers.UserDisplayName: timonsku
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-20T04:13:21.457Z
Answers.Text: @ProfessorSparkles I think that the fact that it worked here is sufficient ground to believe otherwise. I will wait to see what kaorukobo says.
Answers.UserDisplayName: v010dya
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-20T08:39:11.907Z
Answers.Text: @Volodya Thanks for your information. I added the report with trying avconv to my question.
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-20T12:47:27.197Z
Answers.Text: @kaorukobo What exactly do you mean by "with having its frame backward quiveringly repeatedly"? Does the output shake or does it in some way jump forward and back?
Answers.UserDisplayName: v010dya
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-21T04:03:47.790Z
Answers.Text: @Volodya I think your expression is right. Seeing is believing. I've upload the resulting Canon-00006.MTS.mp4 to http://www.filedropper.com/canon-00006mts  If you don't mind, please try playing that file with QuickTime Player (if you have Mac...) not VLC.
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-21T14:57:52.077Z
Answers.Text: @kaorukobo Hello. I have updated my answer, but it doesn't look promicing. I hope that some of the thoughts i have provided will help you to resolve the problem. You may try shooting with the same camera settings except for resolution. But unfortunately most cameras these days come with several presets, and it's not possible to just change the resolution like this.
Answers.UserDisplayName: v010dya
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-05T08:43:59.920Z
Answers.Text: Sorry, Volodya. I wanted try something about your comment, however I could not take the time after all. @Volodya
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-17T15:46:29.370Z
Answers.LastActivityDate: 2014-07-21T14:54:44.437Z
Answers.LastEditDate: 2014-07-21T14:54:44.437Z
Answers.UserDisplayName: v010dya
Answers.Body: <p>As per this ffmpeg bug</p>
  
  <p><a href="https://trac.ffmpeg.org/ticket/3393" rel="noreferrer">Interlaced H.264 packets are split causing MP4 STTS</a></p>
  
  <blockquote>
    <p>when remuxing a mpeg-ts containing interlaced H.264 into mp4, both
    fields of each video frame are split into seperate packets. Software
    such as Mediainfo uses the STTS to determine the frame rate. It will
    show as 50fps instead of 25fps</p>
  </blockquote>
  
  <p>The frame rate mismatch reported here seems to be a result of ffmpeg muxing interlaced MP4 streams according to the specification, as per which, each field is separated into one packet. And thus</p>
  
  <blockquote>
    <p>"software which uses the sample count in the MP4 file to determine the
    frame rate is simply wrong." <a href="https://trac.ffmpeg.org/ticket/3393#comment:7" rel="noreferrer">Comment 7</a></p>
  </blockquote>
  
  <p>This will not be patched as merging field pairs into one access unit violates the MPEG-4 specification, and hence so do any encoders which do the same.</p>
  
  <p>Note that the muxed output, such as the one below, <strong>plays</strong> fine for me in Potplayer and VLC.</p>
  
  <pre><code>    ffmpeg version N-76741-g8eadabf Copyright (c) 2000-2015 the FFmpeg developers
    built with gcc 5.2.0 (GCC)
  
  Input #0, mpegts, from '00007.MTS':
    Duration: 00:00:07.01, start: 1.033367, bitrate: 15935 kb/s
    Program 1 
      Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p, 1920x1080 [SAR 1:1 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, 5.1(side), fltp, 448 kb/s
      Stream #0:2[0x1200]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090), 1920x1080
  [mp4 @ 054cf020] Codec for stream 0 does not use global headers but container format requires global headers
  Output #0, mp4, to '00007.MTS.mp4':
    Metadata:
      encoder         : Lavf57.16.100
      Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc
      Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, 5.1(side), fltp, 128 kb/s
      Metadata:
        encoder         : Lavc57.15.100 aac
  Stream mapping:
    Stream #0:0 -&gt; #0:0 (copy)
    Stream #0:1 -&gt; #0:1 (ac3 (native) -&gt; aac (native))
  Press [q] to stop, [?] for help
  [mp4 @ 054cf020] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
  [mp4 @ 054cf020] pts has no value
      Last message repeated 209 times
  frame=  420 fps=0.0 q=-1.0 Lsize=   12478kB time=00:00:07.01 bitrate=14564.2kbits/s    
  video:12458kB audio:6kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.111239%
  [aac @ 052fd480] Qavg: 64863.176
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-18T11:20:17.640Z
Answers.LastActivityDate: 2015-12-18T11:27:32.073Z
Answers.LastEditDate: 2015-12-18T11:27:32.073Z
Answers.UserDisplayName: Gyan
Answers.Body: <p>You might want to try to enforce the original frame rate by using <code>-r 29.97</code>. FFmpeg is probably trying to adjust the framerate for some reason.
  Your syntax is otherwise correct and shouldn't produce that error.</p>
  
  <p>Regarding your third question. Simply not possible.
  You can omit frames when using codecs that encode frames individually but thats not the case with h264 but even with such a codec you still modify the video stream in some way.
  The same goes for increasing frame rate, you have to either add calculated frames or duplicate some frames.</p>
  
  <p>Edit: Regarding the additional info from the comment below. If you need to change the data written in the format header without writing a completely new file you probably want to do that in a hex editor. FFmpeg only has option to alter metadata which doesn't include the stream data.
  How and where to make your changes in the file depends on the container format.</p>
  
  <p>Another option would be to demux the container and remux the video and audio stream into a new container with your options specified. How much you can specifiy again depends on the container format. The tool <a href="http://www.videohelp.com/tools/MP4Box" rel="nofollow">MP4Box</a> might be of help with that in this case, you can specify a framerate when muxing raw video streams into a new mp4 using the following syntax:</p>
  
  <pre><code>MP4Box -add input.h264:fps=29.97 -new output.mp4
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-13T15:58:53.550Z
Answers.Text: Thanks. Regarding `-t 60` switch, it is an option to specify not a framerate but processing duration ( `$ ffmpeg -h|grep -- -t` -> `-t duration  record or transcode "duration" seconds of audio/video`)
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-13T16:07:52.200Z
Answers.Text: Oh right that was a different encoder, sorry for that error.
Answers.UserDisplayName: timonsku
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-13T16:15:17.073Z
Answers.Text: See my edit to the answer.
Answers.UserDisplayName: timonsku
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-13T16:32:47.600Z
Answers.Text: Thanks again. I edited my question to add the result by trying your advice. Unfortunately, the problem was still there..
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-13T16:35:21.737Z
Answers.Text: Regarding your response to my third question, it's all right for the case I'd like to change the video stream's  framerate, not just "value". However, in my case, `"set framerate/timebase values"` means just rewriting values put on container/codec-stream's header. Why? There are some cases to deal with: the case that some encoder (e.g. Apple Compressor's h264 transcoder) injects wrong timebase value (tbc) to the video stream, and the case such as this question that ffmpeg injects wrong framerate/timebase values, which are different to those of original video files.
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-14T14:37:29.913Z
Answers.Text: Thanks again. I previously tried using Hex editor, and soon gave up that method.. MP4Box sounds good. Installing and trying mp4box, it made a bit step forward. After more trial, I'll report the result.
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T03:01:33.573Z
Answers.Text: I added **5. Remux using MP4Box** at the end of my question.
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T13:37:04.157Z
Answers.Text: Could you try the tool Mediainfo instead of ffprobe and see what is says about the framerate?
  http://mediaarea.net/en/MediaInfo
Answers.UserDisplayName: timonsku
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-16T09:04:04.457Z
Answers.Text: A nice tool. I tried MediaInfo and added its report to my question. However, I could not find more useful information than ffmpeg.
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-16T09:10:20.273Z
Answers.Text: I tried another solution than ffmpeg. **[Free AVCHD to MOV](https://itunes.apple.com/us/app/free-avchd-to-mov/id675103877?mt=12)'s "rewrap to MOV"** feature worked well, even though it makes not MP4 but MOV. The software calls its own ffmpeg program internally, and I saw what options are passed to it. When I have some time, I would report about it.
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-16T12:20:37.387Z
Answers.Text: Very weird issue you have there. One thing you could try besides looking what commands this tool used internally is to omit the time constrain (´-t 60´). I'm somewhat believing that cutting h264 like that could cause problems without transcoding. FFmpeg could have just cut in the middle of some P or B frames that dont decode without an I frame which may have caused the video to corrupt depending on how a player would handle such a case.
Answers.UserDisplayName: timonsku
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-18T22:08:31.390Z
Answers.Text: Sorry for the delay. I agree your viewpoint and doubted that possibility. Although I didn't write about that in my question, the same issue appeared without the time cnostrain `-t 60`... But properly, I should inspect such issue by using a short source file recorded with the same camera.
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-20T09:06:06.640Z
Answers.Text: I added *7. Why "Free AVCHD to MOV" app work?* to my question.
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-13T14:47:52.080Z
Answers.LastActivityDate: 2014-07-13T16:53:25.533Z
Answers.LastEditDate: 2014-07-13T16:53:25.533Z
Answers.UserDisplayName: timonsku
Answers.Body: <p>I know this is an old question, but it just popped up again in the feed so it's new to me. (-:</p>
  
  <p>One thing I don't see mentioned is field order. This is an interlaced file, so that's a consideration. The OP mentions the frames "quivering back and forth" which is always a flag for incorrect field order. If the video is otherwise OK except for the 'quivering', try adding whatever ffmpeg needs to force "top field first", then the opposite if that's still wrong. I'm not familiar enough with ffmpeg details to give the exact flags for that.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-05T08:48:52.257Z
Answers.Text: I want to try running some ffmepg commands on your answer. However  my ffmpeg version 2.2.1 doesn't seem to have options that handle the field order . I tried `ffmpeg -h|egrep 'field|first'` but it shows nothing. Previous version (0.8.6) of ffmpeg had `-top` option which may handle it.
Answers.UserDisplayName: kaorukobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-05T11:26:45.363Z
Answers.Text: @kaorukobo The internet offers this: **-vf "fieldorder=bff"** or **=tff** where the **t** and **b** refer to top and bottom respectively. The **top=1 / 0** option is apparently used to change the order in which fields are read, not written. Again, I use ffmpeg / avconv only casually, so no guarantees.
Answers.UserDisplayName: Jim Mack
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-02T12:23:27.987Z
Answers.LastActivityDate: 2015-06-02T12:23:27.987Z
Answers.UserDisplayName: Jim Mack
Body: <p><em>Note: I posted same question to <a href="https://stackoverflow.com/questions/24720063/how-can-i-convert-mts-file-avchd-to-mp4-by-ffmpeg-without-re-encoding-h264-v">stackoverflow</a> a short time before, when I have not found this comunity yet. I repost this since the question is more suitable to this community.</em></p>
  
  <h1>1. What I tried</h1>
  
  <p>I have some <strong>.MTS (AVCHD format) files recoreded with my AVCHD camera</strong>. Its specification is as shown below:</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>Pay attention to the part of framerate/timebase: <strong>29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc</strong></p>
  
  <p>Now I’d like to <strong>convert this file to .mp4 file, without re-encoding H264 video stream</strong>, on the other hand, with <strong>transcoding its audio stream to AAC</strong>.
  So I tried the following command:</p>
  
  <p><code>ffmpeg -i 140612_Canon-00000.MTS -t 60 -y -vcodec copy -acodec libfaac -ab 128k 140612_Canon-00001.MTS.mp4
  </code></p>
  
  <h2>2. Result</h2>
  
  <p>and output file’s specification is as shown below:</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>Look at the part of framerate/timebase: <strong>59.94 fps, 59.94 tbr, 90k tbn, 59.94 tbc</strong>.
  Although ffmpeg just copied the video stream, <strong>framerate and timebase has been changed to twice value</strong>.</p>
  
  <p>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.</p>
  
  <h2>3. Question</h2>
  
  <ol>
  <li>How can I <strong>convert .MTS file (AVCHD) to .mp4 by ffmpeg without re-encoding H264 video stream correctly</strong>?</li>
  <li>How can I <strong>keep the original framerate/timebase values (fps/tbr/tbn/tbc)</strong> when I convert the container with <code>ffmpeg</code> and its <code>-vcodec copy</code> switch.</li>
  <li>How can I <strong>set framerate/timebase values (fps/tbr/tbn/tbc) by ffmpeg’s command line options</strong> without re-encoding a video stream.</li>
  </ol>
  
  <p>Any ideas?</p>
  
  <hr>
  
  <h2>4. Adding <code>-r 29.97</code> option</h2>
  
  <p>Professor Sparkles gave me an advice to add <code>-r 29.97</code>. I tried that:</p>
  
  <pre><code>ffmpeg -i 140612_Canon-00001.MTS -t 60 -r 29.97 -y -vcodec copy -acodec libfaac -ab 128k 140612_Canon-00001.MTS.mp4
  </code></pre>
  
  <p>However, the output file has still wrong framerate/timebase:</p>
  
  <pre><code>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, 11988 tbn, 59.94 tbc (default)
  </code></pre>
  
  <hr>
  
  <h2>5. Remux using MP4Box</h2>
  
  <p>I tried demux and remux using MP4Box, according to Professor Sparkles’s advice.</p>
  
  <pre><code>brew install mp4box
  
  ffmpeg -i 140612_Canon-00000.MTS -t 60 -y \
    -vcodec copy -an 140612_Canon-00000.MTS.h264
  
  ffmpeg -i 140612_Canon-00000.MTS -t 60 -y \
    -vn -acodec libfaac -ab 128k 140612_Canon-00000.MTS.aac
  
  mp4box -add 140612_Canon-00000.MTS.h264:fps=29.97 \
    -add 140612_Canon-00000.MTS.aac \
    -new 140612_Canon-00000.MTS.mp4
  </code></pre>
  
  <p>and output was:</p>
  
  <p>$ ffprobe 140612_Canon-00000.MTS.mp4 </p>
  
  <pre><code>Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '140612_Canon-00000.MTS.mp4':
  (snip)
    Duration: 00:02:00.22, start: 0.000000, bitrate: 2293 kb/s
      Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), 
            yuv420p, 1440x1080 [SAR 4:3 DAR 16:9], 2228 kb/s, 
            29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
      Metadata:
        creation_time   : 2014-07-14 00:38:23
        handler_name    : 140612_Canon-00000.MTS.h264:fps=29.97
         - Imported with GPAC 0.5.0-rev4065
  
      Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, 
            stereo, fltp, 125 kb/s (default)
  </code></pre>
  
  <p>It looks a bit step forward.
  Look at the part of framerate/timebase: <strong>29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc</strong>.
  Those are match to the original stream, <strong>except for <code>tbn</code></strong> (timebase value from container).</p>
  
  <p>However, when I play back the output file with Quicktime Player or VLC, the <strong>video is play back at the half speed</strong>. </p>
  
  <p>Although the original file has <code>90k tbn</code> (90000 ticks per second) and the new output file from MP4Box has <code>30k tbn</code> which is just one-third value of original one, the output file is play back at the half speed. </p>
  
  <p>I don't know the reason why.  But I think the rest issue is how I can adjust the <code>tbn</code> value.</p>
  
  <hr>
  
  <h1>5-b. MediaInfo's report on the output file</h1>
  
  <p>I also tried <a href="http://mediaarea.net/en/MediaInfo" rel="nofollow noreferrer">MediaInfo tool</a> on the output file generated by <strong>5. Remux using MP4Box</strong>. The output is here: <a href="https://gist.github.com/kaorukobo/c5ab9eaa413dff6cd26a" rel="nofollow noreferrer">https://gist.github.com/kaorukobo/c5ab9eaa413dff6cd26a</a></p>
  
  <hr>
  
  <h1>6. Trying avconv</h1>
  
  <p>Volodya reported <code>avconv</code> worked well. Also I prepared a short sample movie file (Canon-00006.MTS) recorded with the same camera. Okay, let's try:</p>
  
  <pre><code>brew install avconv
  avconv -i Canon-00006.MTS -c:a copy -c:v copy -y Canon-00006.MTS.mp4
  ffprobe Canon-00006.MTS.mp4
  </code></pre>
  
  <p>The output file's ffprobe information is here: <a href="https://gist.github.com/kaorukobo/5b53244ade2632ff1211" rel="nofollow noreferrer">https://gist.github.com/kaorukobo/5b53244ade2632ff1211</a>
  and its framerate/timebase information is as the following: <strong>59.94 fps, 59.94 tbr, 90k tbn, 59.94 tbc</strong></p>
  
  <p>The output file was <strong>played back well with VLC Player</strong> as Volodya reported. However, opening it with Quicktime Player X, the video was play back at the normal speed but with having its frame backward quiveringly repeatedly.</p>
  
  <hr>
  
  <h1>7. Why "Free AVCHD to MOV" app work?</h1>
  
  <p>As <a href="https://video.stackexchange.com/questions/12156/how-can-i-convert-mts-file-avchd-to-mp4-by-ffmpeg-without-re-encoding-h264-v#comment14521_12157">I mentioned in my previous comment</a>, <a href="https://itunes.apple.com/us/app/free-avchd-to-mov/id675103877?mt=12" rel="nofollow noreferrer">Free AVCHD to MOV</a> app's <strong>"rewrap to MOV"</strong> feature worked well, even though it makes not MP4 but MOV.</p>
  
  <p>The software calls its own ffmpeg (or avconv) program internally, and I saw what options are passed to it. It's as shown below:</p>
  
  <pre><code>/Applications/Free AVCHD to Mov.app/Contents/Resources/bin/com.geranium-soft.convert \
    -i /path/to/140710_Canon-00003.MTS \
    -map 0:0 -map 0:1 -c:a libfaac -vol 256 -b:a 128k -c:v copy \
    -sn -movflags faststart -threads 0 -pix_fmt yuv420p -y \
    /path/to/140710_Canon-00003.mov
  </code></pre>
  
  <p>I tried passing same options (Extractly same. I set the output container type to MOV and removed even <code>-t 60</code> switch.) to ffmpeg program and converting. But <strong>the result was same as reported so far</strong>.</p>
  
  <p>Anyway that great app resolved my issue on "How can I convert .MTS file (AVCHD) to .mp4 without re-encoding H264 video stream?", except at "to .mp4" and "by ffmpeg". But I'm still interested in why that app do well but ffmpeg don't.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-14T03:38:19.663Z
Comments.Text: What do you mean by "correctly"? Maybe remove that from the title. I would like to help but I have never used ffmpeg. I just use the adobe tools media encoder.
Comments.UserDisplayName: eLouai
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-14T14:11:51.733Z
Comments.Text: @eLouai All right, I fixed the title.
Comments.UserDisplayName: kaorukobo
Tags: <ffmpeg><avchd><h.264>
Title: How can I convert .MTS file (AVCHD) to .mp4 by ffmpeg without re-encoding H264 video stream?
UserDisplayName: kaorukobo
ThreadText: # How can I convert .MTS file (AVCHD) to .mp4 by ffmpeg without re-encoding H264 video stream?
  
  (Asked by: username_0 on 2014-07-13)
  
  *Note: I posted same question to [stackoverflow](https://stackoverflow.com/questions/24720063/how-can-i-convert-mts-file-avchd-to-mp4-by-ffmpeg-without-re-encoding-h264-v) a short time before, when I have not found this comunity yet. I repost this since the question is more suitable to this community.*
  
  # 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?
  
  ---
  
  ## 4. Adding `-r 29.97` option
  
  Professor Sparkles gave me an advice to add `-r 29.97`. I tried that:
  
  ```
  ffmpeg -i 140612_Canon-00001.MTS -t 60 -r 29.97 -y -vcodec copy -acodec libfaac -ab 128k 140612_Canon-00001.MTS.mp4
  
  ```
  
  However, the output file has still wrong framerate/timebase:
  
  ```
  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, 11988 tbn, 59.94 tbc (default)
  
  ```
  
  ---
  
  ## 5. Remux using MP4Box
  
  I tried demux and remux using MP4Box, according to Professor Sparkles’s advice.
  
  ```
  brew install mp4box
  
  ffmpeg -i 140612_Canon-00000.MTS -t 60 -y \
    -vcodec copy -an 140612_Canon-00000.MTS.h264
  
  ffmpeg -i 140612_Canon-00000.MTS -t 60 -y \
    -vn -acodec libfaac -ab 128k 140612_Canon-00000.MTS.aac
  
  mp4box -add 140612_Canon-00000.MTS.h264:fps=29.97 \
    -add 140612_Canon-00000.MTS.aac \
    -new 140612_Canon-00000.MTS.mp4
  
  ```
  
  and output was:
  
  $ ffprobe 140612\_Canon-00000.MTS.mp4
  
  ```
  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '140612_Canon-00000.MTS.mp4':
  (snip)
    Duration: 00:02:00.22, start: 0.000000, bitrate: 2293 kb/s
      Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), 
            yuv420p, 1440x1080 [SAR 4:3 DAR 16:9], 2228 kb/s, 
            29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
      Metadata:
        creation_time   : 2014-07-14 00:38:23
        handler_name    : 140612_Canon-00000.MTS.h264:fps=29.97
         - Imported with GPAC 0.5.0-rev4065
  
      Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, 
            stereo, fltp, 125 kb/s (default)
  
  ```
  
  It looks a bit step forward.
  Look at the part of framerate/timebase: **29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc**.
  Those are match to the original stream, **except for `tbn`** (timebase value from container).
  
  However, when I play back the output file with Quicktime Player or VLC, the **video is play back at the half speed**.
  
  Although the original file has `90k tbn` (90000 ticks per second) and the new output file from MP4Box has `30k tbn` which is just one-third value of original one, the output file is play back at the half speed.
  
  I don't know the reason why. But I think the rest issue is how I can adjust the `tbn` value.
  
  ---
  
  # 5-b. MediaInfo's report on the output file
  
  I also tried [MediaInfo tool](http://mediaarea.net/en/MediaInfo) on the output file generated by **5. Remux using MP4Box**. The output is here: <https://gist.github.com/username_0/c5ab9eaa413dff6cd26a>
  
  ---
  
  # 6. Trying avconv
  
  Volodya reported `avconv` worked well. Also I prepared a short sample movie file (Canon-00006.MTS) recorded with the same camera. Okay, let's try:
  
  ```
  brew install avconv
  avconv -i Canon-00006.MTS -c:a copy -c:v copy -y Canon-00006.MTS.mp4
  ffprobe Canon-00006.MTS.mp4
  
  ```
  
  The output file's ffprobe information is here: <https://gist.github.com/username_0/5b53244ade2632ff1211>
  and its framerate/timebase information is as the following: **59.94 fps, 59.94 tbr, 90k tbn, 59.94 tbc**
  
  The output file was **played back well with VLC Player** as Volodya reported. However, opening it with Quicktime Player X, the video was play back at the normal speed but with having its frame backward quiveringly repeatedly.
  
  ---
  
  # 7. Why "Free AVCHD to MOV" app work?
  
  As [I mentioned in my previous comment](https://video.stackexchange.com/questions/12156/how-can-i-convert-mts-file-avchd-to-mp4-by-ffmpeg-without-re-encoding-h264-v#comment14521_12157), [Free AVCHD to MOV](https://itunes.apple.com/us/app/free-avchd-to-mov/id675103877?mt=12) app's **"rewrap to MOV"** feature worked well, even though it makes not MP4 but MOV.
  
  The software calls its own ffmpeg (or avconv) program internally, and I saw what options are passed to it. It's as shown below:
  
  ```
  /Applications/Free AVCHD to Mov.app/Contents/Resources/bin/com.geranium-soft.convert \
    -i /path/to/140710_Canon-00003.MTS \
    -map 0:0 -map 0:1 -c:a libfaac -vol 256 -b:a 128k -c:v copy \
    -sn -movflags faststart -threads 0 -pix_fmt yuv420p -y \
    /path/to/140710_Canon-00003.mov
  
  ```
  
  I tried passing same options (Extractly same. I set the output container type to MOV and removed even `-t 60` switch.) to ffmpeg program and converting. But **the result was same as reported so far**.
  
  Anyway that great app resolved my issue on "How can I convert .MTS file (AVCHD) to .mp4 without re-encoding H264 video stream?", except at "to .mp4" and "by ffmpeg". But I'm still interested in why that app do well but ffmpeg don't.
  
  **Tags:** ffmpeg, avchd, h.264
  
  > **Comments:**
  > **username_1**: What do you mean by "correctly"? Maybe remove that from the title. I would like to help but I have never used ffmpeg. I just use the adobe tools media encoder.  
  > **username_0**: @username_1 All right, I fixed the title.  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_2 on 2014-07-17. Score: 9
  
  Seeing that in the text of your question you have started discussing other utilities, i will assume that you are not interested in sticking with ffmpeg, but rather in getting the job done.
  
  In my experience with libav and MTS i have had no problems with the framerate, the files get remuxed perfectly.
  
  I have just attempted the following with one of my files:
  
  ```
  avconv -i 00174.MTS -c:a copy -c:v copy 00174.mp4
  
  ```
  
  The resulting MP4 file played correctly with VLC.
  
  My file is progressive MTS, i don't have any interlaced laying around, but if need be i can do more checking with that.
  
  **Report about the file test**
  
  The topic starter was able to provide a file, that was remuxed from MTS to MP4 and did not play on that person's machine with QuickTime Player (version unknown). It did, however, play with that individual's VLC player.
  
  I do not have a Mac OS computer, but i have tried it with Ubuntu.
  I have played it on Ubuntu on VLC (2.0.8) and GNOME Videos (used to be called Totem) (3.8.2); both play perfectly.
  
  I then asked a friend of mine, who is on a Mac to play it. He is on Mavericks (10.9.4), and it played fine with QuickTime Player 10.3 (727.4).
  
  At this time it appears to be a problem with the particular player or a problem with configuration settings on the computer. And it is probably best to attempt to update to the newest version of QTP, possibly with first removing the current version and completely wiping the old configuration.
  
  **Another possibility**
  
  When i have had an old machine i have had some high bitrate files play incorrectly in some players, and it was container specific. For example, VLC would refuse to play MTS file, it would show a frame, and then show the next one only in a second and a half. GNOME Videos played it fine. But when remuxing it to MKV, both players played it reasonably well. This maybe a question of something similar. A player maybe reading a particular container (MP4 in this case) in a way that requires just enough CPU time, that it begins to choke itself. The jerkiness effect can be then attributed to whatever subprocess takes up CPU finishing, and player dumping all of the frames that were lagging behind very rapidly, after that the bad subprocess again kicks in, and the cycle keeps on going.
  
  In this possibility, the best option is still to try to upgrade the software. With the current multicore processors it would be difficult to test the need to upgrade the hardware without actually getting it, but maybe it is possible to look at the CPU load during the QuickTime Player useage and compare it to VLC. If you see 100% for any one core with QTP, that maybe indicative of this.
  
  > **Comments:**
  > **username_3**: It's rather unlikely that avconv will do a different job for him. avconv is a fork of ffmpeg and ffmpeg is merging a lot of commits from the avconv project into ffmpeg, major bugs fixes like that would likely be present in ffmpeg.  
  > **username_2**: @ProfessorSparkles I think that the fact that it worked here is sufficient ground to believe otherwise. I will wait to see what username_0 says.  
  > **username_0**: @Volodya Thanks for your information. I added the report with trying avconv to my question.  
  > **username_2**: @username_0 What exactly do you mean by "with having its frame backward quiveringly repeatedly"? Does the output shake or does it in some way jump forward and back?  
  > **username_0**: @Volodya I think your expression is right. Seeing is believing. I've upload the resulting Canon-00006.MTS.mp4 to http://www.filedropper.com/canon-00006mts  If you don't mind, please try playing that file with QuickTime Player (if you have Mac...) not VLC.  
  > **username_2**: @username_0 Hello. I have updated my answer, but it doesn't look promicing. I hope that some of the thoughts i have provided will help you to resolve the problem. You may try shooting with the same camera settings except for resolution. But unfortunately most cameras these days come with several presets, and it's not possible to just change the resolution like this.  
  > **username_0**: Sorry, Volodya. I wanted try something about your comment, however I could not take the time after all. @Volodya  
  
  ---
  
  ### Answer by username_4 on 2015-12-18. Score: 5
  
  As per this ffmpeg bug
  
  [Interlaced H.264 packets are split causing MP4 STTS](https://trac.ffmpeg.org/ticket/3393)
  
  > when remuxing a mpeg-ts containing interlaced H.264 into mp4, both
  > fields of each video frame are split into seperate packets. Software
  > such as Mediainfo uses the STTS to determine the frame rate. It will
  > show as 50fps instead of 25fps
  
  The frame rate mismatch reported here seems to be a result of ffmpeg muxing interlaced MP4 streams according to the specification, as per which, each field is separated into one packet. And thus
  
  > "software which uses the sample count in the MP4 file to determine the
  > frame rate is simply wrong." [Comment 7](https://trac.ffmpeg.org/ticket/3393#comment:7)
  
  This will not be patched as merging field pairs into one access unit violates the MPEG-4 specification, and hence so do any encoders which do the same.
  
  Note that the muxed output, such as the one below, **plays** fine for me in Potplayer and VLC.
  
  ```
      ffmpeg version N-76741-g8eadabf Copyright (c) 2000-2015 the FFmpeg developers
    built with gcc 5.2.0 (GCC)
  
  Input #0, mpegts, from '00007.MTS':
    Duration: 00:00:07.01, start: 1.033367, bitrate: 15935 kb/s
    Program 1 
      Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p, 1920x1080 [SAR 1:1 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, 5.1(side), fltp, 448 kb/s
      Stream #0:2[0x1200]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090), 1920x1080
  [mp4 @ 054cf020] Codec for stream 0 does not use global headers but container format requires global headers
  Output #0, mp4, to '00007.MTS.mp4':
    Metadata:
      encoder         : Lavf57.16.100
      Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc
      Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, 5.1(side), fltp, 128 kb/s
      Metadata:
        encoder         : Lavc57.15.100 aac
  Stream mapping:
    Stream #0:0 -> #0:0 (copy)
    Stream #0:1 -> #0:1 (ac3 (native) -> aac (native))
  Press [q] to stop, [?] for help
  [mp4 @ 054cf020] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
  [mp4 @ 054cf020] pts has no value
      Last message repeated 209 times
  frame=  420 fps=0.0 q=-1.0 Lsize=   12478kB time=00:00:07.01 bitrate=14564.2kbits/s    
  video:12458kB audio:6kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.111239%
  [aac @ 052fd480] Qavg: 64863.176
  
  ```
  
  
  ---
  
  ### Answer by username_3 on 2014-07-13. Score: 4
  
  You might want to try to enforce the original frame rate by using `-r 29.97`. FFmpeg is probably trying to adjust the framerate for some reason.
  Your syntax is otherwise correct and shouldn't produce that error.
  
  Regarding your third question. Simply not possible.
  You can omit frames when using codecs that encode frames individually but thats not the case with h264 but even with such a codec you still modify the video stream in some way.
  The same goes for increasing frame rate, you have to either add calculated frames or duplicate some frames.
  
  Edit: Regarding the additional info from the comment below. If you need to change the data written in the format header without writing a completely new file you probably want to do that in a hex editor. FFmpeg only has option to alter metadata which doesn't include the stream data.
  How and where to make your changes in the file depends on the container format.
  
  Another option would be to demux the container and remux the video and audio stream into a new container with your options specified. How much you can specifiy again depends on the container format. The tool [MP4Box](http://www.videohelp.com/tools/MP4Box) might be of help with that in this case, you can specify a framerate when muxing raw video streams into a new mp4 using the following syntax:
  
  ```
  MP4Box -add input.h264:fps=29.97 -new output.mp4
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks. Regarding `-t 60` switch, it is an option to specify not a framerate but processing duration ( `$ ffmpeg -h|grep -- -t` -> `-t duration  record or transcode "duration" seconds of audio/video`)  
  > **username_3**: Oh right that was a different encoder, sorry for that error.  
  > **username_3**: See my edit to the answer.  
  > **username_0**: Thanks again. I edited my question to add the result by trying your advice. Unfortunately, the problem was still there..  
  > **username_0**: Regarding your response to my third question, it's all right for the case I'd like to change the video stream's  framerate, not just "value". However, in my case, `"set framerate/timebase values"` means just rewriting values put on container/codec-stream's header. Why? There are some cases to deal with: the case that some encoder (e.g. Apple Compressor's h264 transcoder) injects wrong timebase value (tbc) to the video stream, and the case such as this question that ffmpeg injects wrong framerate/timebase values, which are different to those of original video files.  
  > **username_0**: Thanks again. I previously tried using Hex editor, and soon gave up that method.. MP4Box sounds good. Installing and trying mp4box, it made a bit step forward. After more trial, I'll report the result.  
  > **username_0**: I added **5. Remux using MP4Box** at the end of my question.  
  > **username_3**: Could you try the tool Mediainfo instead of ffprobe and see what is says about the framerate? http://mediaarea.net/en/MediaInfo  
  > **username_0**: A nice tool. I tried MediaInfo and added its report to my question. However, I could not find more useful information than ffmpeg.  
  > **username_0**: I tried another solution than ffmpeg. **[Free AVCHD to MOV](https://itunes.apple.com/us/app/free-avchd-to-mov/id675103877?mt=12)'s "rewrap to MOV"** feature worked well, even though it makes not MP4 but MOV. The software calls its own ffmpeg program internally, and I saw what options are passed to it. When I have some time, I would report about it.  
  > **username_3**: Very weird issue you have there. One thing you could try besides looking what commands this tool used internally is to omit the time constrain (´-t 60´). I'm somewhat believing that cutting h264 like that could cause problems without transcoding. FFmpeg could have just cut in the middle of some P or B frames that dont decode without an I frame which may have caused the video to corrupt depending on how a player would handle such a case.  
  > **username_0**: Sorry for the delay. I agree your viewpoint and doubted that possibility. Although I didn't write about that in my question, the same issue appeared without the time cnostrain `-t 60`... But properly, I should inspect such issue by using a short source file recorded with the same camera.  
  > **username_0**: I added *7. Why "Free AVCHD to MOV" app work?* to my question.  
  
  ---
  
  ### Answer by username_5 on 2015-06-02. Score: 2
  
  I know this is an old question, but it just popped up again in the feed so it's new to me. (-:
  
  One thing I don't see mentioned is field order. This is an interlaced file, so that's a consideration. The OP mentions the frames "quivering back and forth" which is always a flag for incorrect field order. If the video is otherwise OK except for the 'quivering', try adding whatever ffmpeg needs to force "top field first", then the opposite if that's still wrong. I'm not familiar enough with ffmpeg details to give the exact flags for that.
  
  > **Comments:**
  > **username_0**: I want to try running some ffmepg commands on your answer. However  my ffmpeg version 2.2.1 doesn't seem to have options that handle the field order . I tried `ffmpeg -h|egrep 'field|first'` but it shows nothing. Previous version (0.8.6) of ffmpeg had `-top` option which may handle it.  
  > **username_5**: @username_0 The internet offers this: **-vf "fieldorder=bff"** or **=tff** where the **t** and **b** refer to top and bottom respectively. The **top=1 / 0** option is apparently used to change the order in which fields are read, not written. Again, I use ffmpeg / avconv only casually, so no guarantees.  
  
  ---
  
  