【问题标题】:FFMPEG wrapping live h264 to mp4 container delayFFMPEG 将实时 h264 包装到 mp4 容器延迟
【发布时间】:2021-08-03 06:13:10
【问题描述】:

很抱歉,如果有人问过这个问题,但我找不到答案。

我正在尝试将实时原始 h264 流包装到碎片化的 MP4 容器中。这按预期工作,有一个问题,我在输入和输出之间有 5-10 秒的延迟。基本上在收到第一个输入的 5-10 秒后开始输出。

这是我的命令:

ffmpeg -r 30 -f h264 -i tcp://127.0.0.1:1234 -c:v copy -an -f mp4 -movflags separate_moof+empty_moov+default_base_moof -tune zerolatency -tcp_nodelay true -frag_duration 33000 -max_muxing_queue_size 1 tcp://127.0.0.1:1235

我玩过 fflags、analyticaluration 以及我在文档中可以找到的所有内容,但没有任何乐趣。

输入流正在接收 NALU 单元,我可以看到它在实际开始输出之前接收了大量的单元。一旦启动它就可以完美运行,但输出视频总是比输入视频慢 5-10 秒。

收到一堆 NALU 单元后,我看到 ffmpeg 输出以下内容:

2021-08-02 23:46:22.071 24626-11173/app.example.com I/ffmpeg-kit: Input #0, h264, from 'tcp://127.0.0.1:8105':
2021-08-02 23:46:22.071 24626-11173/app.example.com I/ffmpeg-kit:   Duration: 
2021-08-02 23:46:22.071 24626-11173/app.example.com I/ffmpeg-kit: N/A
2021-08-02 23:46:22.071 24626-11173/app.example.com I/ffmpeg-kit: , bitrate: 
2021-08-02 23:46:22.071 24626-11173/app.example.com I/ffmpeg-kit: N/A
2021-08-02 23:46:22.071 24626-11173/app.example.com I/ffmpeg-kit:   Stream #0:0
2021-08-02 23:46:22.071 24626-11173/app.example.com I/ffmpeg-kit: : Video: h264, yuv420p(tv, smpte170m/bt470bg/smpte170m, progressive), 1280x720
2021-08-02 23:46:22.071 24626-11173/app.example.com I/ffmpeg-kit: , 
2021-08-02 23:46:22.072 24626-11173/app.example.com I/ffmpeg-kit: 30 fps, 
2021-08-02 23:46:22.072 24626-11173/app.example.com I/ffmpeg-kit: 30 tbr, 
2021-08-02 23:46:22.072 24626-11173/app.example.com I/ffmpeg-kit: 1200k tbn, 
2021-08-02 23:46:22.072 24626-11173/app.example.com I/ffmpeg-kit: 60 tbc
2021-08-02 23:46:22.079 24626-11173/app.example.com I/ffmpeg-kit: Output #0, mp4, to 'tcp://127.0.0.1:8104':
2021-08-02 23:46:22.079 24626-11173/app.example.com I/ffmpeg-kit:   Metadata:
2021-08-02 23:46:22.079 24626-11173/app.example.com I/ffmpeg-kit:     encoder         : 
2021-08-02 23:46:22.079 24626-11173/app.example.com I/ffmpeg-kit: Lavf58.67.100
2021-08-02 23:46:22.079 24626-11173/app.example.com I/ffmpeg-kit:   Stream #0:0
2021-08-02 23:46:22.079 24626-11173/app.example.com I/ffmpeg-kit: : Video: h264 (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m, progressive), 1280x720, q=2-31
2021-08-02 23:46:22.080 24626-11173/app.example.com I/ffmpeg-kit: , 
2021-08-02 23:46:22.080 24626-11173/app.example.com I/ffmpeg-kit: 30 fps, 
2021-08-02 23:46:22.080 24626-11173/app.example.com I/ffmpeg-kit: 30 tbr, 
2021-08-02 23:46:22.080 24626-11173/app.example.com I/ffmpeg-kit: 15360 tbn, 
2021-08-02 23:46:22.080 24626-11173/app.example.com I/ffmpeg-kit: 30 tbc
2021-08-02 23:46:22.080 24626-11173/app.example.com I/ffmpeg-kit: Stream mapping:
2021-08-02 23:46:22.080 24626-11173/app.example.com I/ffmpeg-kit:   Stream #0:0 -> #0:0
2021-08-02 23:46:22.080 24626-11173/app.example.com I/ffmpeg-kit:  (copy)
2021-08-02 23:46:22.080 24626-11173/app.example.com I/ffmpeg-kit: Press [q] to stop, [?] for help

这是一个 Android 包装器,但如果我从命令行在笔记本电脑上运行命令,也会发生同样的情况。

我缺少什么,我需要这是实时/即时复用...

感谢您的帮助。

【问题讨论】:

    标签: ffmpeg


    【解决方案1】:

    我在发布问题后不久就发现了问题.....

    使用-probesize 512 解决了这个问题。

    为什么是 512?

    我的 SDP+SSP 大约是 270 字节,所以为了安全起见,我使用了稍高的值。减小探针尺寸使一切正常。

    在输入条目之前拥有该选项也很重要,因此 ffmpeg 知道应该将其应用于该选项。

    【讨论】:

      猜你喜欢
      • 2014-02-11
      • 2012-05-09
      • 2020-06-13
      • 2016-10-04
      • 2012-04-26
      • 1970-01-01
      • 2019-06-08
      • 2017-07-23
      • 1970-01-01
      相关资源
      最近更新 更多