FFMPEG 间歇性失败读取实时 RTMP 流
FFMPEG intermittent failures reading live RTMP stream
命令
我正在尝试读取实时 RTMP 流并使用以下命令将结果保存到文件中:
ffmpeg -re -rtmp_live live -y -i "rtmp://<server>/<app>/<stream>" -c copy -f flv /tmp/dump.flv
我 运行 这个命令然后在 10-15 秒后我终止进程并检查 /tmp/dump.flv
。我正在尝试这样做是为了流诊断目的(确定实时流的编码、比特率、分辨率、像素格式和关键帧间隔)
此命令大约有 25-50% 的时间有效。当它工作时,FFMPEG 需要大约 5 秒来连接到流,然后它开始将数据转储到磁盘。终止进程后,我可以在 /tmp/dump.flv
中找到几兆字节的视频数据,可以使用 ffprobe
.
进行探测
当命令失败时,它会进入两种失败状态之一:
失败状态 1
stderr 充满了关于 "missing picture in access unit with size X" 的一系列消息,输出文件 /tmp/dump.flv
已创建但包含 0 个字节
ffmpeg version 3.4.4-1~16.04.york0 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
configuration: --prefix=/usr --extra-version='1~16.04.york0' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
[NULL @ 0x55b72d568920] pps_id 381 out of range
[AVBSFContext @ 0x55b72d5692c0] Invalid NAL unit 0, skipping.
Last message repeated 1 times
[h264 @ 0x55b72d568920] Invalid NAL unit 0, skipping.
Last message repeated 1 times
[h264 @ 0x55b72d568920] no frame!
[h264 @ 0x55b72d568920] missing picture in access unit with size 2200
[AVBSFContext @ 0x55b72d5692c0] Invalid NAL unit 0, skipping.
Last message repeated 2 times
[h264 @ 0x55b72d568920] Invalid NAL unit 0, skipping.
Last message repeated 2 times
[h264 @ 0x55b72d568920] no frame!
[h264 @ 0x55b72d568920] missing picture in access unit with size 3171
[AVBSFContext @ 0x55b72d5692c0] Invalid NAL unit 0, skipping.
[h264 @ 0x55b72d568920] Invalid NAL unit 0, skipping.
[h264 @ 0x55b72d568920] no frame!
[NULL @ 0x55b72d568920] missing picture in access unit with size 80572
[h264 @ 0x55b72d568920] missing picture in access unit with size 1560
[h264 @ 0x55b72d568920] missing picture in access unit with size 2608
[h264 @ 0x55b72d568920] non-existing PPS 0 referenced
[h264 @ 0x55b72d568920] missing picture in access unit with size 2734
[h264 @ 0x55b72d568920] missing picture in access unit with size 2885
[h264 @ 0x55b72d568920] missing picture in access unit with size 77739
[h264 @ 0x55b72d568920] non-existing PPS 254 referenced
[h264 @ 0x55b72d568920] missing picture in access unit with size 3360
[h264 @ 0x55b72d568920] missing picture in access unit with size 2804
[h264 @ 0x55b72d568920] missing picture in access unit with size 3051
[h264 @ 0x55b72d568920] missing picture in access unit with size 3067
[h264 @ 0x55b72d568920] missing picture in access unit with size 77693
[h264 @ 0x55b72d568920] non-existing PPS 0 referenced
[h264 @ 0x55b72d568920] missing picture in access unit with size 2421
[h264 @ 0x55b72d568920] missing picture in access unit with size 2779
[h264 @ 0x55b72d568920] missing picture in access unit with size 2442
[h264 @ 0x55b72d568920] missing picture in access unit with size 2678
[h264 @ 0x55b72d568920] missing picture in access unit with size 76877
[h264 @ 0x55b72d568920] sps_id 15 out of range
[h264 @ 0x55b72d568920] missing picture in access unit with size 1342
[h264 @ 0x55b72d568920] missing picture in access unit with size 2412
[h264 @ 0x55b72d568920] missing picture in access unit with size 2238
[h264 @ 0x55b72d568920] missing picture in access unit with size 3550
[h264 @ 0x55b72d568920] missing picture in access unit with size 3075
...
(after hitting Ctrl+C:)
Input #0, flv, from 'rtmp://<server>/<app>/<stream>':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Duration: 00:00:00.00, start: 5285.919000, bitrate: N/A
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 1920x1080, 2543 kb/s, 24 fps, 24 tbr, 1k tbn, 48 tbc
Output #0, flv, to '/tmp/dump.flv':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Stream #0:0: Video: h264 (Constrained Baseline) ([7][0][0][0] / 0x0007), yuv420p, 1920x1080, q=2-31, 2543 kb/s, 24 fps, 24 tbr, 1k tbn, 1k tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 0 fps=0.0 q=-1.0 Lsize= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Exiting normally, received signal 2.
失败状态 2
显示消息 "No start code is found.",FFMPEG 在不到半秒后立即终止。发生这种情况时,文件 /tmp/dump.flv
不会创建。
ffmpeg version 3.4.4-1~16.04.york0 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
configuration: --prefix=/usr --extra-version='1~16.04.york0' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
[NULL @ 0x56274b0be920] missing picture in access unit with size 3710
[AVBSFContext @ 0x56274b0bf2c0] No start code is found.
rtmp://<server>/<app>/<stream>: could not find codec parameters
Input #0, flv, from 'rtmp://<server>/<app>/<stream>':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Duration: 00:00:00.00, start: 0.000000, bitrate: N/A
Stream #0:0: Video: h264, none, 2543 kb/s, 24 fps, 1k tbn
Output #0, flv, to '/tmp/dump.flv':
Output file #0 does not contain any stream
我试过的
- 添加或删除
-re
以尝试将输入帧速率限制为源帧速率
- 添加或删除
-rtmp_live live
- 添加或删除
-timeout 5
(或任何其他超时值)
- 使用 RTMP URL 参数(例如
-i "rtmp://<server>/<app>/<stream> live=1 timeout=5"
)
有谁知道为什么此命令的成功如此断断续续,或者我如何才能获得更一致的结果?
替代可接受的解决方案
我使用 ffmpeg
将流转储到临时文件的唯一原因是因为我计划对该文件执行多项测试(目前至少有两项 - 一项用于获取编码,另一个获取关键帧间隔)。通过下载流,我减少了带宽使用并减少了 运行 时间。然而,放弃 ffmpeg
并直接在 RTMP URL 上使用 ffprobe
是完全可以接受的。
请注意,我确实尝试过此操作,但我得到了与 ffprobe
相同的两个失败状态
我在为我的 RTMP 服务器使用 Red5 v5.0.1 时遇到了这些错误。更新到 Red5 v5.2.0 解决了这些问题。这只是他们服务器中的一个错误。不知道哪里出了问题,但现在好多了。
命令
我正在尝试读取实时 RTMP 流并使用以下命令将结果保存到文件中:
ffmpeg -re -rtmp_live live -y -i "rtmp://<server>/<app>/<stream>" -c copy -f flv /tmp/dump.flv
我 运行 这个命令然后在 10-15 秒后我终止进程并检查 /tmp/dump.flv
。我正在尝试这样做是为了流诊断目的(确定实时流的编码、比特率、分辨率、像素格式和关键帧间隔)
此命令大约有 25-50% 的时间有效。当它工作时,FFMPEG 需要大约 5 秒来连接到流,然后它开始将数据转储到磁盘。终止进程后,我可以在 /tmp/dump.flv
中找到几兆字节的视频数据,可以使用 ffprobe
.
当命令失败时,它会进入两种失败状态之一:
失败状态 1
stderr 充满了关于 "missing picture in access unit with size X" 的一系列消息,输出文件 /tmp/dump.flv
已创建但包含 0 个字节
ffmpeg version 3.4.4-1~16.04.york0 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
configuration: --prefix=/usr --extra-version='1~16.04.york0' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
[NULL @ 0x55b72d568920] pps_id 381 out of range
[AVBSFContext @ 0x55b72d5692c0] Invalid NAL unit 0, skipping.
Last message repeated 1 times
[h264 @ 0x55b72d568920] Invalid NAL unit 0, skipping.
Last message repeated 1 times
[h264 @ 0x55b72d568920] no frame!
[h264 @ 0x55b72d568920] missing picture in access unit with size 2200
[AVBSFContext @ 0x55b72d5692c0] Invalid NAL unit 0, skipping.
Last message repeated 2 times
[h264 @ 0x55b72d568920] Invalid NAL unit 0, skipping.
Last message repeated 2 times
[h264 @ 0x55b72d568920] no frame!
[h264 @ 0x55b72d568920] missing picture in access unit with size 3171
[AVBSFContext @ 0x55b72d5692c0] Invalid NAL unit 0, skipping.
[h264 @ 0x55b72d568920] Invalid NAL unit 0, skipping.
[h264 @ 0x55b72d568920] no frame!
[NULL @ 0x55b72d568920] missing picture in access unit with size 80572
[h264 @ 0x55b72d568920] missing picture in access unit with size 1560
[h264 @ 0x55b72d568920] missing picture in access unit with size 2608
[h264 @ 0x55b72d568920] non-existing PPS 0 referenced
[h264 @ 0x55b72d568920] missing picture in access unit with size 2734
[h264 @ 0x55b72d568920] missing picture in access unit with size 2885
[h264 @ 0x55b72d568920] missing picture in access unit with size 77739
[h264 @ 0x55b72d568920] non-existing PPS 254 referenced
[h264 @ 0x55b72d568920] missing picture in access unit with size 3360
[h264 @ 0x55b72d568920] missing picture in access unit with size 2804
[h264 @ 0x55b72d568920] missing picture in access unit with size 3051
[h264 @ 0x55b72d568920] missing picture in access unit with size 3067
[h264 @ 0x55b72d568920] missing picture in access unit with size 77693
[h264 @ 0x55b72d568920] non-existing PPS 0 referenced
[h264 @ 0x55b72d568920] missing picture in access unit with size 2421
[h264 @ 0x55b72d568920] missing picture in access unit with size 2779
[h264 @ 0x55b72d568920] missing picture in access unit with size 2442
[h264 @ 0x55b72d568920] missing picture in access unit with size 2678
[h264 @ 0x55b72d568920] missing picture in access unit with size 76877
[h264 @ 0x55b72d568920] sps_id 15 out of range
[h264 @ 0x55b72d568920] missing picture in access unit with size 1342
[h264 @ 0x55b72d568920] missing picture in access unit with size 2412
[h264 @ 0x55b72d568920] missing picture in access unit with size 2238
[h264 @ 0x55b72d568920] missing picture in access unit with size 3550
[h264 @ 0x55b72d568920] missing picture in access unit with size 3075
...
(after hitting Ctrl+C:)
Input #0, flv, from 'rtmp://<server>/<app>/<stream>':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Duration: 00:00:00.00, start: 5285.919000, bitrate: N/A
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 1920x1080, 2543 kb/s, 24 fps, 24 tbr, 1k tbn, 48 tbc
Output #0, flv, to '/tmp/dump.flv':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Stream #0:0: Video: h264 (Constrained Baseline) ([7][0][0][0] / 0x0007), yuv420p, 1920x1080, q=2-31, 2543 kb/s, 24 fps, 24 tbr, 1k tbn, 1k tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 0 fps=0.0 q=-1.0 Lsize= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Exiting normally, received signal 2.
失败状态 2
显示消息 "No start code is found.",FFMPEG 在不到半秒后立即终止。发生这种情况时,文件 /tmp/dump.flv
不会创建。
ffmpeg version 3.4.4-1~16.04.york0 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
configuration: --prefix=/usr --extra-version='1~16.04.york0' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
[NULL @ 0x56274b0be920] missing picture in access unit with size 3710
[AVBSFContext @ 0x56274b0bf2c0] No start code is found.
rtmp://<server>/<app>/<stream>: could not find codec parameters
Input #0, flv, from 'rtmp://<server>/<app>/<stream>':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Duration: 00:00:00.00, start: 0.000000, bitrate: N/A
Stream #0:0: Video: h264, none, 2543 kb/s, 24 fps, 1k tbn
Output #0, flv, to '/tmp/dump.flv':
Output file #0 does not contain any stream
我试过的
- 添加或删除
-re
以尝试将输入帧速率限制为源帧速率 - 添加或删除
-rtmp_live live
- 添加或删除
-timeout 5
(或任何其他超时值) - 使用 RTMP URL 参数(例如
-i "rtmp://<server>/<app>/<stream> live=1 timeout=5"
)
有谁知道为什么此命令的成功如此断断续续,或者我如何才能获得更一致的结果?
替代可接受的解决方案
我使用 ffmpeg
将流转储到临时文件的唯一原因是因为我计划对该文件执行多项测试(目前至少有两项 - 一项用于获取编码,另一个获取关键帧间隔)。通过下载流,我减少了带宽使用并减少了 运行 时间。然而,放弃 ffmpeg
并直接在 RTMP URL 上使用 ffprobe
是完全可以接受的。
请注意,我确实尝试过此操作,但我得到了与 ffprobe
我在为我的 RTMP 服务器使用 Red5 v5.0.1 时遇到了这些错误。更新到 Red5 v5.2.0 解决了这些问题。这只是他们服务器中的一个错误。不知道哪里出了问题,但现在好多了。