我使用 ffmpeg + nginx/rtmp 将视频从 ip cam 重新流式传输到网页。我使用的命令是:
ffmpeg -rtsp_transport tcp -use_wallclock_as_timestamps 1 -i rtsp://admin:[email protected]/ -f flv -c:v copy -c:a copy rtmp://hls.mydomain.com/show/120
然后我使用这个 URL 在 chrome 中观看它:
http://hls.mydomain.com:8080/hls/120.m3u8
问题是 Chrome 中的视频非常不流畅,只能持续几分钟就会停止。
在重新流式传输服务器上,我看到 ffmpeg 自动退出,没有任何错误输出:
ffmpeg version 4.1.6-1~deb10u1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
configuration: --prefix=/usr --extra-version='1~deb10u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Input #0, rtsp, from 'rtsp://admin:[email protected]/':
Metadata:
title : SDP Descrption
comment : SDP Description
Duration: N/A, start: 1604569309.322911, bitrate: N/A
Stream #0:0: Video: h264 (Baseline), yuvj420p(pc, bt709, progressive), 1920x1080, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1: Audio: aac (LC), 48000 Hz, mono, fltp
Output #0, flv, to 'rtmp://hls.mydomain.com/show/120':
Metadata:
title : SDP Descrption
comment : SDP Description
encoder : Lavf58.20.100
Stream #0:0: Video: h264 (Baseline) ([7][0][0][0] / 0x0007), yuvj420p(pc, bt709, progressive), 1920x1080, q=2-31, 25 fps, 25 tbr, 1k tbn, 90k tbc
Stream #0:1: Audio: aac (LC) ([10][0][0][0] / 0x000A), 48000 Hz, mono, fltp
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[rtsp @ 0x5559c1d26940] CSeq 6 expected, 0 received.0:16.73 bitrate=2725.1kbits/s speed= 1.1x
[rtsp @ 0x5559c1d26940] CSeq 6 expected, 0 received.0:21.50 bitrate=2447.1kbits/s speed=1.08x
Last message repeated 1 times
[rtsp @ 0x5559c1d26940] CSeq 6 expected, 0 received.0:35.10 bitrate=2191.8kbits/s speed=1.05x
Last message repeated 1 times
[rtsp @ 0x5559c1d26940] CSeq 6 expected, 0 received.0:39.04 bitrate=2180.5kbits/s speed=1.04x
Last message repeated 2 times
[flv @ 0x5559c1d30440] Failed to update header with correct duration.406.8kbits/s speed=1.03x
[flv @ 0x5559c1d30440] Failed to update header with correct filesize.
frame= 1009 fps= 17 q=-1.0 Lsize= 17912kB time=00:01:00.28 bitrate=2434.0kbits/s speed=1.02x
video:17401kB audio:459kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.288416%
我确认 ffmpeg 的退出代码为 0。流媒体和服务在两个独立的 Debian Linux 服务器上进行。
非常感谢您的帮助。另外,我想知道重新流式传输 H265 视频的命令(例如参数)。TIA。