一、获取RTSP流
海康监控摄像头/硬盘录像机的RTSP地址格式如下。
rtsp://[username]:[password]@[ip]:[port]/[codec]/[channel]/[subtype]/av_stream
格式说明:
- username: 用户名。例如admin。
- password: 密码。例如12345。
- ip: 为设备IP。例如 192.0.0.64。
- port: 端口号默认为554,若为默认可不填写。
- codec:有h264、MPEG-4、mpeg4这几种。
- channel: 通道号,起始为1。例如通道1,则为ch1。
- subtype: 码流类型,主码流为main,辅码流为sub。
例如,请求海康摄像机通道1的主子码流,Url如下
主码流:
rtsp://admin:[email protected]:554/h264/ch1/main/av_stream
子码流:
rtsp://admin:[email protected]/h264/ch1/sub/av_stream
二、实时转m3u8
利用ffmpeg 工具对视频流进行转换。转换命令如下。
ffmpeg -i rtsp://admin:[email protected]:554/h264/ch1/main/av_stream -strict -2 -c:v libx264 -c:a aac -f hls -hls_list_size 3 -hls_time 3 -hls_wrap 5 D:\video\ts2\test.m3u8
即可在D:\video\ts2\test.m3u8目录中实时动态生成。
以上 ffmpeg 的命令解释如下:
<