基于SRS 实现RTSP接入与WebRTC播放测试

系列文章目录

`
第一篇 基于SRS 的 WebRTC 环境搭建
第二篇 基于SRS 实现RTSP接入与WebRTC播放



前言

在安防领域,大多数摄像头是RTSP,SRS本身是不支持RTSP,那么基于SRS有没有什么方案让其支持RTSP接入,并基于SRS中已经实现的WebRTC的功能,使得网页端能够低延迟的播放RTSP流呢,上一篇《基于SRS 的 WebRTC 环境搭建》中已经介绍和演示了SRS可以实现RTMP的接入和WebRtc播放,可以通过ffmpeg 将RTSP流转化成RTMP流,就可以无缝对接了,本文就带着大家实操验证下。


一、基础方案

方案如下:

IP Camera --RTSP--> FFmpeg --RTMP--> Media Server --WebRTC--> Browser
                                    (SRS Gateway)

二、实验步骤

1.模拟相机RTSP流

我这里用live555 点播文件构建一个rtsp流,模拟摄像机出来的rtsp流,身边有相机可以直接用相机的rtsp码流测试。

iot@iot:/usr/local/bin$ ls
cjpeg               MPEG2TransportStreamIndexer  testAMRAudioStreamer            testMKVSplitter                       testMPEG1or2VideoReceiver          testOggStreamer         vobStreamer
djpeg               openRTSP                     testDVVideoStreamer             testMKVStreamer                       testMPEG1or2VideoStreamer          testOnDemandRTSPServer  wrjpgcom
jpegtran            playSIP                      testH264VideoStreamer           testMP3Receiver                       testMPEG2TransportReceiver         testRelay
live555HLSProxy     rdjpgcom                     testH264VideoToHLSSegments      testMP3Streamer                       testMPEG2TransportStreamer         testReplicator
live555MediaServer  registerRTSPStream           testH264VideoToTransportStream  testMPEG1or2AudioVideoStreamer        testMPEG2TransportStreamSplitter   testRTSPClient
live555ProxyServer  sapWatch                     testH265VideoStreamer           testMPEG1or2ProgramToTransportStream  testMPEG2TransportStreamTrickPlay  testWAVAudioStreamer
mikeyParse          test.264                     testH265VideoToTransportStream  testMPEG1or2Splitter                  testMPEG4VideoStreamer             tjbench

iot@iot:/usr/local/bin$ ./testOnDemandRTSPServer 

"mpeg4ESVideoTest" stream, from the file "test.m4e"
Play this stream using the URL "rtsp://192.168.110.57:8554/mpeg4ESVideoTest"

"h264ESVideoTest" stream, from the file "test.264"
Play this stream using the URL "rtsp://192.168.110.57:8554/h264ESVideoTest"

"h265ESVideoTest" stream, from the file "test.265"
Play this stream using the URL "rtsp://192.168.110.57:8554/h265ESVideoTest"

"mpeg1or2AudioVideoTest" stream, from the file "test.mpg"
Play this stream using the URL "rtsp://192.168.110.57:8554/mpeg1or2AudioVideoTest"

"mpeg1or2ESVideoTest" stream, from the file "testv.mpg"
Play this stream using the URL "rtsp://192.168.110.57:8554/mpeg1or2ESVideoTest"

"mp3AudioTest" stream, from the file "test.mp3"
Play this stream using the URL "rtsp://192.168.110.57:8554/mp3AudioTest"

"wavAudioTest" stream, from the file "test.wav"
Play this stream using the URL "rtsp://192.168.110.57:8554/wavAudioTest"

2.测试RTSP流

点播目录下有个test.264的文件,PotPlayer (也可以用vlc或ffplay等代替)测试rtsp 流画面如下:
在这里插入图片描述

3.编写协议转换推流脚本

vi rtsp_to_rtmp.sh

#!/bin/bash
ffmpeg -i "rtsp://192.168.110.57:8554/h264ESVideoTest" -vcodec copy -acodec copy -f flv rtmp://192.168.110.57/live/livestream

chmod 777 rtsp_to_rtmp.sh

3.推流测试

确保srs服务器已经在运行,通过ps -ef | grep srs 可查看

iot@iot:~/srs/srs/trunk$ ps -ef | grep srs
root      88465      1  0 Sep10 ?        00:00:00 sudo ./objs/srs -c conf/rtc.conf
root      88466  88465  0 Sep10 ?        00:07:25 ./objs/srs -c conf/rtc.conf
iot       92007  91296  0 07:35 pts/1    00:00:00 grep --color=auto srs

运行脚本 ./rtsp_to_rtmp.sh 进行推流。
在这里插入图片描述

4.web端播放测试

打开浏览器,用SRS自带RTC播放器看到播放画面如下,这里细节可以参考我的上一篇博文《基于SRS 的 WebRTC 环境搭建》。
在这里插入图片描述


总结

以上就是今天要讲的内容,在上一篇SRS的WebRTC环境的基础上,更进一步,进行了RTSP接入与WebRTC播放测试的实验,希望对大家SRS怎样接入RTSP的方案有一定的了解和帮助。

你好,我是阿灿,慢慢理解世界,慢慢更新自己,每天进步一点点,成为更好的自己。

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值