Biraj B Choudhury
Biraj B Choudhury

Reputation: 684

While transcoding to mpegts ffmpeg creates the first frame after 1.48 seconds delay

I have transcoded a file to mpegts using the following command

 ./ffmpeg -y -i big_buck_bunny_720p_5mb.mp4  -vcodec libx264  -x264opts "keyint=48:min-keyint=48:no_scenecut" -r 23.976 -c:a copy  -f mpegts test.mpegts

When I run ffprobe on it -

./ffprobe  -i  test.mpegts  -select_streams v -show_frames -of csv

I see that the first frame starts at 1.48 seconds why is this so ?

Input #0, mpegts, from 'test.mpegts':
  Duration: 00:00:29.61, start: 1.483422, bitrate: 1964 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc
    Stream #0:1[0x101](und): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, 5.1, fltp, 406 kb/s
frame,video,0,1,133508,1.483422,133508,1.483422,133508,1.483422,3753,0.041700,564,112008,1280,720,yuv420p,1:1,I,0,0,0,0,0
frame,video,0,0,137262,1.525133,137262,1.525133,137262,1.525133,3753,0.041700,125584,1110,1280,720,yuv420p,1:1,B,2,0,0,0,0

After some research I added "muxdelay 0" to my command

./ffmpeg -y -i big_buck_bunny_720p_5mb.mp4  -vcodec libx264  -x264opts "keyint=48:min-keyint=48:no_scenecut" -r 23.976 -c:a copy  -muxdelay 0 -f mpegts test.mpegts

And now I get the following in ffprobe

Input #0, mpegts, from 'test.mpegts':
  Duration: 00:00:29.61, start: 0.083422, bitrate: 1987 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc
    Stream #0:1[0x101](und): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, 5.1, fltp, 406 kb/s
frame,video,0,1,7508,0.083422,7508,0.083422,7508,0.083422,3753,0.041700,564,112008,1280,720,yuv420p,1:1,I,0,0,0,0,0
frame,video,0,0,11262,0.125133,11262,0.125133,11262,0.125133,3753,0.041700,125584,1110,1280,720,yuv420p,1:1,B,2,0,0,0,0

Can anybody help me understand what is this muxdelay that is contributing to 1.4 seconds of delay and what is contributing to the remaining 0.08 seconds of delay.

The first frame is at 0.000 when the output is mp4 so this is something particular to mpegts.

Upvotes: 1

Views: 1632

Answers (1)

user498529
user498529

Reputation: 146

I had exactly the same problem. It seems that the 0.08 offset is the result of an option called avoid_negative_ts. The default value is "auto", and for mpegts this equals to "make_non_negative" value. By using the "disabled" value the offset vanished.

Reference:

  1. https://www.ffmpeg.org/ffmpeg-formats.html#toc-Format-Options
  2. avoid_negative_ts auto value for mpegts: https://github.com/FFmpeg/FFmpeg/blob/fa8308d3d4f27d6fb38ac2069887a7b259f1c6ab/libavformat/mux.c#L468
  3. offset calculation: https://github.com/FFmpeg/FFmpeg/blob/fa8308d3d4f27d6fb38ac2069887a7b259f1c6ab/libavformat/mux.c#L694

Upvotes: 2

Related Questions