我有一个安全摄像头流RTSP,我希望将其重新传输到RTMP摄取服务器。现在我使用我的笔记本电脑作为ffmpeg代理,但最终我会使用覆盆子pi或类似的东西(便宜/小)
这是我使用的命令(非常简单):
ffmpeg -i rtsp://@10.0.0.16:554/1/h264major -c:v libx264 -c:a none -f flv rtmp://output/camera_stream
这可以工作但是一两分钟之后流就会死掉。这是输出:
ffmpeg version N-90057-g7c82e0f Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.6) 20160609
configuration: --prefix=/home/sbarnett/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/sbarnett/ffmpeg_build/include --extra-ldflags=-L/home/sbarnett/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/sbarnett/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libspeex --enable-nonfree
libavutil 56. 7.101 / 56. 7.101
libavcodec 58. 11.101 / 58. 11.101
libavformat 58. 9.100 / 58. 9.100
libavdevice 58. 1.100 / 58. 1.100
libavfilter 7. 12.100 / 7. 12.100
libswscale 5. 0.101 / 5. 0.101
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.100
Input #0, rtsp, from 'rtsp://@10.0.0.16:554/1/h264major':
Metadata:
title : h264major
comment : h264major
Duration: N/A, start: 0.360000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 720x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x38843c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x38843c0] profile High, level 3.0
[libx264 @ 0x38843c0] 264 - core 155 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://output/camera_stream':
Metadata:
title : h264major
comment : h264major
encoder : Lavf58.9.100
Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuvj420p(pc), 720x480, q=-1--1, 25 fps, 1k tbn, 25 tbc
Metadata:
encoder : Lavc58.11.101 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Past duration 0.999992 too large
Last message repeated 29 times
[rtsp @ 0x3847600] max delay reached. need to consume packet
[rtsp @ 0x3847600] RTP: missed 48 packets
Past duration 0.999992 too large
Last message repeated 4 times
frame= 44 fps=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A dup=0 drop=5 speed= 0x
frame= 57 fps= 54 q=28.0 size= 43kB time=00:00:00.16 bitrate=2186.4kbits/s dup=0 drop=5 speed=0.153x
... (lots of similar messages) ...
frame= 1163 fps= 26 q=28.0 size= 1341kB time=00:00:44.84 bitrate= 245.0kbits/s dup=0 drop=5 speed=0.99x
frame= 1177 fps= 26 q=28.0 size= 1353kB time=00:00:45.40 bitrate= 244.2kbits/s dup=0 drop=5 speed=0.99x
[rtsp @ 0x3847600] max delay reached. need to consume packet
[rtsp @ 0x3847600] RTP: missed 2 packets
frame= 1190 fps= 26 q=28.0 size= 1370kB time=00:00:45.92 bitrate= 244.4kbits/s dup=0 drop=5 speed=0.99x
[h264 @ 0x38c08c0] Increasing reorder buffer to 1
frame= 1201 fps= 26 q=28.0 size= 1381kB time=00:00:46.36 bitrate= 244.0kbits/s dup=0 drop=5 speed=0.989x
frame= 1214 fps= 26 q=28.0 size= 1393kB time=00:00:46.88 bitrate= 243.4kbits/s dup=0 drop=5 speed=0.989x
... (lots of similar messages) ...
frame= 1761 fps= 25 q=28.0 size= 2030kB time=00:01:08.80 bitrate= 241.7kbits/s dup=0 drop=5 speed=0.993x
frame= 1774 fps= 25 q=28.0 size= 2041kB time=00:01:09.32 bitrate= 241.2kbits/s dup=0 drop=5 speed=0.993x
[flv @ 0x3884900] Failed to update header with correct duration.
[flv @ 0x3884900] Failed to update header with correct filesize.
frame= 1782 fps= 25 q=-1.0 Lsize= 2127kB time=00:01:11.64 bitrate= 243.2kbits/s dup=0 drop=5 speed=1.02x
video:2092kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.679417%
[libx264 @ 0x38843c0] frame I:8 Avg QP:16.89 size: 42446
[libx264 @ 0x38843c0] frame P:1672 Avg QP:19.54 size: 1065
[libx264 @ 0x38843c0] frame B:102 Avg QP:23.00 size: 205
[libx264 @ 0x38843c0] consecutive B-frames: 92.4% 0.0% 0.0% 7.6%
[libx264 @ 0x38843c0] mb I I16..4: 12.9% 36.2% 50.9%
[libx264 @ 0x38843c0] mb P I16..4: 0.2% 0.2% 0.0% P16..4: 16.7% 0.7% 1.0% 0.0% 0.0% skip:81.1%
[libx264 @ 0x38843c0] mb B I16..4: 0.1% 0.1% 0.0% B16..8: 11.7% 0.1% 0.0% direct: 1.5% skip:86.5% L0:62.2% L1:35.3% BI: 2.5%
[libx264 @ 0x38843c0] 8x8 transform intra:40.8% inter:47.4%
[libx264 @ 0x38843c0] coded y,uvDC,uvAC intra: 46.5% 53.0% 17.2% inter: 3.9% 8.7% 0.0%
[libx264 @ 0x38843c0] i16 v,h,dc,p: 21% 56% 8% 15%
[libx264 @ 0x38843c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 33% 31% 1% 2% 3% 2% 2% 3%
[libx264 @ 0x38843c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 39% 9% 3% 3% 4% 5% 3% 8%
[libx264 @ 0x38843c0] i8c dc,h,v,p: 43% 33% 21% 3%
[libx264 @ 0x38843c0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x38843c0] ref P L0: 88.0% 1.4% 6.6% 4.0%
[libx264 @ 0x38843c0] ref B L0: 99.4% 0.5% 0.1%
[libx264 @ 0x38843c0] ref B L1: 99.4% 0.6%
[libx264 @ 0x38843c0] kb/s:238.73
相机相当便宜(来自中国)所以很可能我从它那里得到了不好的数据,或者它一次只能斩断几秒钟。理想情况下,我需要ffmpeg来处理这个问题(忽略不良数据,等待好数据恢复编码所需的时间)
使用ffplay
签出RTSP流,我得到如下输出:
$> ffplay -i rtsp://@10.0.0.16:554/1/h264major
ffplay version N-90057-g7c82e0f Copyright (c) 2003-2018 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.6) 20160609
configuration: --prefix=/home/sbarnett/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/sbarnett/ffmpeg_build/include --extra-ldflags=-L/home/sbarnett/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/sbarnett/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libspeex --enable-nonfree
libavutil 56. 7.101 / 56. 7.101
libavcodec 58. 11.101 / 58. 11.101
libavformat 58. 9.100 / 58. 9.100
libavdevice 58. 1.100 / 58. 1.100
libavfilter 7. 12.100 / 7. 12.100
libswscale 5. 0.101 / 5. 0.101
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.100
Input #0, rtsp, from 'rtsp://@10.0.0.16:554/1/h264major':0B f=0/0
Metadata:
title : h264major
comment : h264major
Duration: N/A, start: 0.320000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 720x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
[swscaler @ 0x7f6bbc093180] deprecated pixel format used, make sure you did set range correctly
[rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
[rtsp @ 0x7f6bc0000940] RTP: missed 2 packets
[h264 @ 0x7f6bc0041080] error while decoding MB 44 28, bytestream -37
[h264 @ 0x7f6bc0041080] concealing 95 DC, 95 AC, 95 MV errors in I frame
[rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
[rtsp @ 0x7f6bc0000940] RTP: missed 1 packets
[h264 @ 0x7f6bc0041080] error while decoding MB 43 29, bytestream -49
[h264 @ 0x7f6bc0041080] concealing 51 DC, 51 AC, 51 MV errors in I frame
[rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
[rtsp @ 0x7f6bc0000940] RTP: missed 2 packets
[h264 @ 0x7f6bc0041080] Increasing reorder buffer to 1
[rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
[rtsp @ 0x7f6bc0000940] RTP: missed 3 packets
[h264 @ 0x7f6bc02c3600] error while decoding MB 27 29, bytestream -24
[h264 @ 0x7f6bc02c3600] concealing 67 DC, 67 AC, 67 MV errors in I frame
[rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
[rtsp @ 0x7f6bc0000940] RTP: missed 2 packets
[rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
[rtsp @ 0x7f6bc0000940] RTP: missed 42 packets
[rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
[rtsp @ 0x7f6bc0000940] RTP: missed 2 packets
然后最终视频冻结了。它是第一次在大约5分钟后冻结,但我无法明确地说明它是否会在44个数据包被丢弃之后冻结,或者它是否随后随机冻结。所以我第二次专注地凝视...... 持续21分钟。然后我厌倦了它没有冻结,转向宠爱我的猫,当我回头看了15秒后它被冻结了。我认为只有在没有人看到它时它才会破裂。
我可以肯定地说:
M-V
将徘徊在 0(-0.01
和+0.01
之间的任何地方)M-V
开始倒数到负数而不会停止 - 尽管速度低于每秒-1
aq
为0KB
而vq
为正数(我认为是30KB
左右?)vq
也是0KB
这是一款非常便宜的相机,如果你呼吸它就会熄灭电源,所以在这段时间内相机可能会暂时脱机 - 但我不喜欢ffmpeg等待超时并在再次看到相机时恢复流式传输。