6

I'm using ffmpeg to transcode video to .ts format, and I am getting unexpected start times in the output file.

To simplify things, I've started with a nice simple AVI file (no audio):

ffmpeg -i in.avi 
...
Input #0, avi, from 'in.avi':
  Metadata:
    encoder         : Lavf55.25.100
  Duration: 00:00:05.00, start: 0.000000, bitrate: 448 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 480x270 [SAR 1:1 DAR 16:9], 24 tbr, 24 tbn, 24 tbc

Duration=5s, startTime=0s, as expected.

However, if I transcode to .ts file, with no customisation:

ffmpeg -i in.avi -y out.ts
...
Input #0, avi, from 'in.avi':
  Metadata:
    encoder         : Lavf55.25.100
  Duration: 00:00:05.00, start: 0.000000, bitrate: 448 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 480x270 [SAR 1:1 DAR 16:9], 24 tbr, 24 tbn, 24 tbc
Output #0, mpegts, to 'out.ts':
  Metadata:
    encoder         : Lavf55.25.100
    Stream #0:0: Video: mpeg2video, yuv420p, 480x270 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 24 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 -> mpeg2video)
Press [q] to stop, [?] for help
frame=  120 fps=0.0 q=31.0 Lsize=     315kB time=00:00:04.95 bitrate= 519.9kbits/s dup=1 drop=0    
video:277kB audio:0kB subtitle:0 global headers:0kB muxing overhead 13.491544%

Then I get a very odd parameters (Duration=4:96s, startTime=1.441667):

ffmpeg -i out.ts
...
Input #0, mpegts, from 'out.ts':
  Duration: 00:00:04.96, start: 1.441667, bitrate: 519 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 480x270 [SAR 1:1 DAR 16:9], max. 104857 kb/s, 24 fps, 24 tbr, 90k tbn, 48 tbc

Now, I can just about understand why the transcode might lose a couple of frames, which explains the duration, but I can't see why the start time should be any different to the AVI file's start time.

I have tried transcoding to .mp4, .webm and .mov, and in each case we get the 'correct' start time of 0.0s. Can anybody help explain why .ts files behave differently?

Thanks in advance!

(ffmpeg version information:)

ffmpeg version N-60031-ga459891 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jan 21 2014 05:31:54 with gcc 4.6 (Debian 4.6.3-1)
  configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
  libavutil      52. 63.100 / 52. 63.100
  libavcodec     55. 48.102 / 55. 48.102
  libavformat    55. 25.100 / 55. 25.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  1.100 /  4.  1.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
geekydel
  • 183
  • 1
  • 6

1 Answers1

6

When muxing to mpegts ffmpeg applies a default delay to the resulting timestamp. I assume this is to deal with live situations where it's important to make sure the resulting video has an accurate timestamp.

The default delay is 0.7 seconds (which you can see in ffmpeg_opt.c) but in the case of mpegts it gets multiplied by 2. Why? I'm not entirely sure. I've traced this back to a commit almost 8 years ago related to adding support for VBR muxing, but I haven't been able to determine what the underlying reason was.

In any case, what you most likely want to do is set the mux delay to 0 by adding -muxdelay 0 to the command line. This way you'll get the same start time in your .ts files as you get in your .mp4, .webm or .mov files.

Cosmin Stejerean
  • 1,348
  • 9
  • 9