10

I have large MPEG-TS file that I am converting to MP4 using the below command. If I seek to the same time in the video in both the MP4 and the TS file, the MP4 will be a few frames behind the TS file. This get progressively worse the further into the video I seek.

c:\>ffmpeg -y -r 30 -i full-ts.ts -c:v copy -r 30 -an full.mp4
ffmpeg version N-69040-gb23a866 Copyright (c) 2000-2015 the FFmpeg developers
  built on Jan 12 2015 22:02:37 with gcc 4.9.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinge
r --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-
libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
  libavutil      54. 16.100 / 54. 16.100
  libavcodec     56. 20.100 / 56. 20.100
  libavformat    56. 18.101 / 56. 18.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5.  7.100 /  5.  7.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mpegts, from 'full-ts.ts':
  Duration: 00:11:25.75, start: 1.424000, bitrate: 3407 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 90k tbn, 60 tbc
    Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 125 kb/s
Output #0, mp4, to 'full.mp4':
  Metadata:
    encoder         : Lavf56.18.101
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 30 fps, 30 tbr, 15360 tbn, 30 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=20419 fps=0.0 q=-1.0 Lsize=  251660kB time=00:11:25.59 bitrate=3007.0kbits/s
video:251446kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.084929%

I'm confused why the TBN is so large in the output stream. I've tried -copyts, -copytb, all the -vsynch options, but I cannot get seek times to match up on the MP4. Also, the MP4 shows a frame rate of 29.78, whereas the TS file is solid 30/1 using ffprobe.

ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=avg_frame_rate full.mp4
streams_stream_0_avg_frame_rate="5227264/175529"

ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=avg_frame_rate full-ts.ts
programs_program_0_streams_stream_0_avg_frame_rate="30/1"
streams_stream_0_avg_frame_rate="30/1" 

Any idea how I can get the seeking on the both containers to show the same frame? Please help!

  • 1
    What happens if you remove the input -r 30? What is the reason for that anyway? Also, you enable stream copy mode with -c:v copy which means the output -r 30 is ignored. – llogan Apr 3 '15 at 23:34
  • @LordNeckbeard - it changes a few things in the output, but I still have the seeking issue. See log @ gist.github.com/andypryor/3b1f123b4c8d6ed3975c , Thank for explaining the -r 30 is not needed, I misunderstood its use, thought I could force mp4 frame rate. – Andy Apr 5 '15 at 2:54
  • 1
    As I understand it, mp4 doesn't store a framerate anywhere, just times between individual frames. So ffprobe looks at the frame times of the first few frames, and assumes the rest of the video is the same. I don't have any ideas to actually solve your problem, though. Except maybe try something other than ffmpeg, like MP4Box. Or even mkvmerge to a .mkv, to see if that works any differently. (and maybe try ffmpeg muxing to something other than mp4. ffmpeg's mp4 muxer might not be perfect.) – Peter Cordes Apr 12 '15 at 2:30
  • The standard video frame rate is 29.97, if you convert to 30fps you will eventually see drift: filmdoctor.net/2010/06/drop-frame-vs-non-drop-frame – screaming drills Sep 15 '15 at 4:19
  • tbn of the output stream is too small 15k. it should be 90k. Seems like discarding of the audio stream is the source of the problem. – incBrain Apr 7 '16 at 0:08
3

As per a comment here, removing the -r flag ought to do this properly. You have another -r flag for the input, also. Remove both of them, and it should properly copy the stream as it is into a new container; you may need to remove that -an (disable audio) switch, too. I'm not sure on that:

ffmpeg -y -i full-ts.ts -c:v copy full.mp4

If that fails, also per a comment here, you could try a different output container format.

protected by Community Apr 10 '17 at 14:27

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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