转码为mpegts时,ffmpeg会在1.48秒延迟后创建第一帧

时间:2017-06-15 11:08:34

标签: ffmpeg

我已使用以下命令将文件转码为mpegts

 ./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

当我运行ffprobe时 -

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

我看到第一帧开始于1.48秒,为什么会这样呢?

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

经过一番研究后,我将“muxdelay 0”添加到我的命令

./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

现在我在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

任何人都可以帮助我理解这个muxdelay是什么导致了1.4秒的延迟以及导致剩余的0.08秒延迟的原因。

当输出为mp4时,第一帧为0.000,所以这是mpegts特有的。

1 个答案:

答案 0 :(得分:0)

我有完全相同的问题。 似乎0.08偏移量是一个名为avoid_negative_ts的选项的结果。默认值为“auto”,对于mpegts,这等于“make_non_negative”值。通过使用“禁用”值,偏移消失了。

参考:

  1. https://www.ffmpeg.org/ffmpeg-formats.html#toc-Format-Options
  2. avoid_negative_ts mpegts的自动值:https://github.com/FFmpeg/FFmpeg/blob/fa8308d3d4f27d6fb38ac2069887a7b259f1c6ab/libavformat/mux.c#L468
  3. 抵消计算:https://github.com/FFmpeg/FFmpeg/blob/fa8308d3d4f27d6fb38ac2069887a7b259f1c6ab/libavformat/mux.c#L694