运行 FFMPEG 将摄像机 RTSP 流(重新)传输到 RTMPS 时,会出现巨大的延迟。使用 RTMP 运行相同的命令可以正常工作,没有任何延迟。
以下是我们测试中使用的命令。请注意,使用 RTMPS 时速度会显著下降:
C:\Users\user\Downloads\ffmpeg-master-latest-win64-gpl\ffmpeg-master-latest-win64-gpl\bin>ffmpeg -hide_banner -rtsp_flags prefer_tcp -i "rtsp://user:[email protected]/cam/realmonitor?channel=1&subtype=1" -codec copy -fflags nobuffer -preset ultrafast -tune zerolatency -muxpreload 3.5 -f flv "rtmp://xxxxxxxxxx.eastus.cloudapp.azure.com:3388/WebRTCAppEE/teststream1"
Input #0, rtsp, from 'rtsp://user:[email protected]/cam/realmonitor?channel=1&subtype=1':
Metadata:
title : Media Server
Duration: N/A, start: 0.040000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuvj420p(pc, smpte170m, progressive), 704x480 [SAR 40:33 DAR 16:9], 30 fps, 100 tbr, 90k tbn
Output #0, flv, to 'rtmp://xxxxxxxxxxxx.eastus.cloudapp.azure.com:3388/WebRTCAppEE/teststream1':
Metadata:
title : Media Server
encoder : Lavf60.5.100
Stream #0:0: Video: h264 (Main) ([7][0][0][0] / 0x0007), yuvj420p(pc, smpte170m, progressive), 704x480 [SAR 40:33 DAR 16:9], q=2-31, 30 fps, 100 tbr, 1k tbn
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[flv @ 000002091d30d540] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[flv @ 000002091d30d540] Failed to update header with correct duration.4.9kbits/s speed=1.04x
[flv @ 000002091d30d540] Failed to update header with correct filesize.
[out#0/flv @ 000002091d2f76c0] video:2289kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.906316%
frame= 1045 fps= 31 q=-1.0 Lsize= 2309kB time=00:00:34.76 bitrate= 544.2kbits/s **speed=1.04x**
使用 RTMPS:
C:\Users\user\Downloads\ffmpeg-master-latest-win64-gpl\ffmpeg-master-latest-win64-gpl\bin>ffmpeg -hide_banner -rtsp_flags prefer_tcp -i "rtsp://user:[email protected]/cam/realmonitor?channel=1&subtype=1" -codec copy -fflags nobuffer -preset ultrafast -tune zerolatency -muxpreload 3.5 -f flv "rtmps://xxxxxxxxxx.eastus.cloudapp.azure.com:3389/WebRTCAppEE/teststream1"
Input #0, rtsp, from 'rtsp://user:[email protected]/cam/realmonitor?channel=1&subtype=1':
Metadata:
title : Media Server
Duration: N/A, start: 0.040000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuvj420p(pc, smpte170m, progressive), 704x480 [SAR 40:33 DAR 16:9], 30 fps, 100 tbr, 90k tbn
Output #0, flv, to 'rtmps://xxxxxxxxxxxx.eastus.cloudapp.azure.com:3389/WebRTCAppEE/teststream1':
Metadata:
title : Media Server
encoder : Lavf60.5.100
Stream #0:0: Video: h264 (Main) ([7][0][0][0] / 0x0007), yuvj420p(pc, smpte170m, progressive), 704x480 [SAR 40:33 DAR 16:9], q=2-31, 30 fps, 100 tbr, 1k tbn
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[flv @ 000001a39c1ad480] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[rtsp @ 000001a39a61a000] CSeq 7 expected, 6 received.26.54 bitrate= 276.6kbits/s **speed=0.386x**
[flv @ 000001a39c1ad480] Failed to update header with correct duration.6.9kbits/s **speed=0.601x**
[flv @ 000001a39c1ad480] Failed to update header with correct filesize.
[out#0/flv @ 000001a39c1572c0] video:1176kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.737466%
frame= 427 fps=5.0 q=-1.0 Lsize= 1184kB time=00:00:48.82 bitrate= 198.7kbits/s **speed=0.576x**