推流命令,设置超时参数(网友提供四种解决超时的参数-stimeoutdemux设置在编解码器上; -rw_timeout; -listen_timeout, -timeout)
-
xiongmai相机推向ZLMediaServer
-
注意,将参数放在前面
-stimeout 5000000 # 有效 ffmpeg -stimeout 5000000 -i "rtsp://192.168.0.93:554/user=admin&password=&channel=0&stream=1.sdp?real_stream" -c copy -f rtsp rtsp://192.168.0.41:554/live/93 # 有效 指定tcp传输 ffmpeg -stimeout 5000000 -i "rtsp://192.168.0.93:554/user=admin&password=&channel=0&stream=1.sdp?real_stream" -c copy -f rtsp -rtsp_transport tcp rtsp://192.168.0.41:554/live/93 # 有效 指定udp传输 ffmpeg -stimeout 5000000 -i "rtsp://192.168.0.93:554/user=admin&password=&channel=0&stream=1.sdp?real_stream" -c copy -f rtsp -rtsp_transport udp rtsp://192.168.0.41:554/live/93 -
推荐的成熟用法,包括将输入输出流超时设置, 输出流形式指定
//eg ffmpeg -stimeout 5000000 -i "rtsp://192.168.0.90:554/user=admin&password=&channel=0&stream=1.sdp?real_stream" -c copy -f rtsp -rtsp_transport tcp -stimeout 5000000 rtsp://192.168.0.41:554/live/90 // 推流模板,以流式套接字推流, 如果首次推流成功, 后某一时刻掉线, 则不会接收到掉线反馈, 客户端持续推流. 这种情况必须确保服务端持续在线 // static const std::string CMD_TEMPLATE{R"(ffmpeg -stimeout TIME_OUT -i "rtsp://IP_SRC:554/user=admin&password=&channel=0&stream=1.sdp?real_stream" -c copy -f rtsp -rtsp_transport udp -stimeout TIME_OUT rtsp://IP_DST:554/live/ID/IP_SRC)"}; // 指定tcp形式,即使连接中断客户端能得到连接状态, 继而停止推流 static const std::string CMD_TEMPLATE{R"(ffmpeg -stimeout TIME_OUT -i "rtsp://IP_SRC:554/user=admin&password=&channel=0&stream=1.sdp?real_stream" -c copy -f rtsp -rtsp_transport tcp -stimeout TIME_OUT rtsp://IP_DST:554/live/ID/IP_SRC)"}; -
可用的推荐用法,xiongmai相机从
rtsp取流转rtmp推向ZLMediaServerffmpeg -stimeout TIME_OUT -i "rtsp://IP_SRC:554/user=admin&password=&channel=0&stream=1.sdp?real_stream" -c copy -flvflags no_duration_filesize -f flv -stimeout TIME_OUT rtmp://192.168.0.41/live/GROUP/IP_SRC -
http和rtmprtsp格式播放ZLMediaKit的视频流# http ffplay "http://192.168.0.41:80/live/zhima/192.168.0.85.flv" # rtmp rtmp://192.168.0.41:1935/live/zhima/192.168.0.85 # rtsp rtsp://192.168.0.41:554/live/zhima/192.168.0.85 -
http-mp4播放视频流ffplay "http://192.168.0.57:80/live/92.live.mp4" -
网友建议的后几个参数
-rw_timeout;-listen_timeout,-timeout似乎是设置IO Context, 服务端改用的参数;Unable to open RTSP for listening rtsp://192.168.0.67:554/user=admin&password=&channel=0&stream=1.sdp?real_stream: Unknown error -
随着开发深入,注意要点:
- 注意,要点相机的主辅码流的区分可能一个是hevc, 另一个是h264:
# xiongmai 相机的主码流 stream=0.sdp # xiongmai 相机的辅码流 stream=1.sdp总结哈报错,这个是雄迈相机的主码流
hevc以-c copy编码器拷贝(hevc)的方式向ZLMediaServer推流,用ffplay播放该视频流时报错:可能原因(ZLMedia本身是支持hevc的)是:1. 手上这个ffmpeg不支持libx265; 2 播放端解析不出来[flv @ 00000262e8332640] If you want to help, upload a sample of this file to https://streams.videolan.org/upload/ and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org) [flv @ 00000262e8332640] Video codec (c) is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.经过验证,实际
ffmpeg支持h265推流,下面则是该命令行,实际报以上错的原因是flv播放器一般只支持H264和AAC编码,该编码格式可能不被播放器支持:H265, 可以选用http-mp4(ZLMediaServer提供http-mp4)ffmpeg -stimeout 5000000 -i "rtsp://192.168.0.15:554/user=admin&password=&channel=0&stream=0.sdp?real_stream" -vcodec hevc -f rtsp -rtsp_transport tcp -stimeout 5000000 rtsp://192.168.0.57:554/live/92ffmpeg命令行指定h264编码
-vcodec libx264
推流的反馈信息
C:\Users\zhouqinan>ffmpeg -i "rtsp://192.168.0.93:554/user=admin&password=&channel=0&stream=1.sdp?real_stream" -c copy -f rtsp -rtsp_transport udp rtsp://192.168.0.41:554/live/stream3
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.1 (GCC) 20200726
configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, rtsp, from 'rtsp://192.168.0.93:554/user=admin&password=&channel=0&stream=1.sdp?real_stream':
Metadata:
title : RTSP Session
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 704x576, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
Output #0, rtsp, to 'rtsp://192.168.0.41:554/live/stream3':
Metadata:
title : RTSP Session
encoder : Lavf58.45.100
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 704x576, q=2-31, 25 fps, 25 tbr, 90k tbn, 25 tbc
Stream #0:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[rtsp @ 0000028b22694180] Non-monotonous DTS in output stream 0:0; previous: 21600, current: 3600; changing to 21601. This may result in incorrect timestamps in the output file.
[rtsp @ 0000028b22694180] Non-monotonous DTS in output stream 0:0; previous: 21601, current: 7200; changing to 21602. This may result in incorrect timestamps in the output file.
[rtsp @ 0000028b22694180] Non-monotonous DTS in output stream 0:0; previous: 21602, current: 10800; changing to 21603. This may result in incorrect timestamps in the output file.
[rtsp @ 0000028b22694180] Non-monotonous DTS in output stream 0:0; previous: 21603, current: 14400; changing to 21604. This may result in incorrect timestamps in the output file.
[rtsp @ 0000028b22694180] Non-monotonous DTS in output stream 0:0; previous: 21604, current: 18000; changing to 21605. This may result in incorrect timestamps in the output file.
[rtsp @ 0000028b22694180] Non-monotonous DTS in output stream 0:0; previous: 21605, current: 21600; changing to 21606. This may result in incorrect timestamps in the output file.
frame= 114 fps= 34 q=-1.0 Lsize=N/A time=00:00:04.56 bitrate=N/A speed=1.38x
video:151kB audio:36kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Exiting normally, received signal 2.
- xiongmai相机推向
linux版的 nginx-flv-serverffmpeg -i "rtsp://192.168.0.90:554/user=admin&password=&channel=0&stream=1.sdp?real_stream" -c copy -flvflags no_duration_filesize -f flv rtmp://www.z-coding.com.cn/live/zhimakeji192.168.0.90 - 从
nginx以http形式读取取视频流http://www.z-coding.com.cn:8088/live?app=live&stream=zhimakeji192.168.0.90 - 测试用的html,在线调用
flv.js<!DOCTYPE html> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>flv.js demo</title> <style> .mainContainer { display: block; width: 1024px; margin-left: auto; margin-right: auto; } .urlInput { display: block; width: 100%; margin-left: auto; margin-right: auto; margin-top: 8px; margin-bottom: 8px; } .centeredVideo { display: block; width: 100%; height: 576px; margin-left: auto; margin-right: auto; margin-bottom: auto; } .controls { display: block; width: 100%; text-align: left; margin-left: auto; margin-right: auto; } </style> </head> <body> <div class="mainContainer"> <video id="videoElement" class="centeredVideo" controls autoplay width="1024" height="576">Your browser is too old which doesn't support HTML5 video.</video> </div> <br> <div class="controls"> <!--<button onclick="flv_load()">加载</button>--> <button onclick="flv_start()">开始</button> <button onclick="flv_pause()">暂停</button> <button onclick="flv_destroy()">停止</button> <input style="width:100px" type="text" name="seekpoint" /> <button onclick="flv_seekto()">跳转</button> </div> <script src="https://cdn.bootcdn.net/ajax/libs/flv.js/1.5.0/flv.js"></script> <script> var player = document.getElementById('videoElement'); if (flvjs.isSupported()) { var flvPlayer = flvjs.createPlayer({ type: 'flv', url: 'http://192.168.0.41:80/live/zhima/192.168.0.85.flv' }); flvPlayer.attachMediaElement(videoElement); flvPlayer.load(); //加载 } function flv_start() { player.play(); } function flv_pause() { player.pause(); } function flv_destroy() { player.pause(); player.unload(); player.detachMediaElement(); player.destroy(); player = null; } function flv_seekto() { player.currentTime = parseFloat(document.getElementsByName('seekpoint')[0].value); } </script> </body> </html>
有用的ffmpeg命令行
参考:ffmpeg基础使用 - 简书 (jianshu.com)
ffmpeg -stimeout 3000000 -i "rtsp://192.168.0.12:554/user=admin&password=&channel=0&stream=0.sdp?real_stream" -r 1 -q:v 2 -f image2 pic-%03d.jpeg
- -q:v表示存储jpeg的图像质量,一般2是高质量
- -r 表示每一秒几帧
- y 覆盖文件方式
ffmpeg -stimeout 3000000 -i "rtsp://192.168.0.12:554/user=admin&password=&channel=0&stream=0.sdp?real_stream" -q:v 2 -y -f image2 test.jpg
ffmpeg -i input.mp4 -ss 00:00:20 -t 10 -r 1 -q:v 2 -f image2 pic-%03d.jpeg
- -ss 设置开始的时间
- -t 表示持续的时间