0


基于SRS的WebRTC环境搭建

系列文章目录

第一篇 基于 SRS 的 WebRTC 环境搭建


文章目录

第一篇 基于 SRS 的 WebRTC 环境搭建

前言

在音视频领域,WebRTC 是一个关键的技术,开源SRS和ZLMediaKit中都含有这一块的代码,将环境搭建跑起来,然后结合抓包调试分析源码,对于想要深入学习 WebRTC 的人来说,实际运行 Demo 并分析代码是非常重要的。这种实践可以帮助你更好地理解 WebRTC 的工作原理、解决实际问题并获得自己的见解,废话不说,直接行动。


一、环境

ubuntu18.04

NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

二、构建步骤

构建SRS环境官网文档上写得比较详细了,但是配置文件方面官网文档上有一些内容没改过来,导致我在初次搭建webrtc拉流播放时,就花了不少时间,这里主要是将其分散的内容整合在一起,方便大家快速搭建。
官网地址:http://ossrs.net/lts/zh-cn/docs/v6/doc/getting-started-build

1.下载源码

git clone -b develop https://gitee.com/ossrs/srs.git

iot@iot:~/learn$ git clone -b develop https://gitee.com/ossrs/srs.git
Cloning into 'srs'...
remote: Enumerating objects:84858, done.
remote: Total 84858(delta 0), reused 0(delta 0), pack-reused 84858
Receiving objects:100%(84858/84858),236.65 MiB |3.53 MiB/s, done.
Resolving deltas:100%(66036/66036), done.

2.编译

编译,注意需要切换到srs/trunk目录:

cd srs/trunk
./configure
make

make完成后可以看到下面结果:

make[1]: Leaving directory '/home/iot/learn/srs/trunk'
The build summary:+------------------------------------------------------------------------------------
     For SRS benchmark, gperf, gprof and valgrind, please read:
          https://www.jianshu.com/p/6d4a89359352+------------------------------------------------------------------------------------|The main server usage:./objs/srs -c conf/srs.conf, start the srs server
     |     About HLS, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/delivery-hls|     About DVR, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/dvr|     About SSL, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/rtmp-handshake|     About transcoding, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/ffmpeg|     About ingester, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/ingest|     About http-callback, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/http-callback|     Aoubt http-server, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/http-server|     About http-api, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/http-api|     About stream-caster, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/streamer|(Disabled) About VALGRIND, please read https://github.com/ossrs/state-threads/issues/2+------------------------------------------------------------------------------------
binaries, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/install
You can:./objs/srs -c conf/srs.conf
                  to start the srs server, with config conf/srs.conf.

3.修改配置文件

将配置文件rtc.conf 中rtmp_to_rtc 默认不启用改成启用,方便后面推流测试,否则会推流不成功。
vi ./conf/rtc.conf
在这里插入图片描述

4.启动服务器

./objs/srs -c conf/rtc.conf

5.服务端推流

再打开一个终端,编写推流脚本 vi file_to_rtmp.sh,这里杨老师比较贴心,下载源码里自带了测试视频,我们只需要编写就行。

#!/bin/bash
ffmpeg -re -i ./doc/source.flv -c copy -f flv rtmp://localhost/live/livestream

给脚本增加可执行权限
chmod 777 file_to_rtmp.sh

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

6.web端播放测试

打开windows下谷歌浏览器,打开网网址http://192.168.110.57:8080/players/rtc_player.html,这里ip根据自己的IP进行更改,直接点播放器右边播放按钮就可以成功播放出画面。

在这里插入图片描述

总结

以上就是今天要讲的内容,本文介绍了基于SRS 源码搭建WebRTC 环境的过程,包括源码编译,配置文件修改,服务运行,推流,测试完整的过程,希望给想要搭建和学习webrtc的人员减少一些踩坑时间,增加学习的乐趣和成功感。

标签: webrtc 学习

本文转载自: https://blog.csdn.net/wel_006/article/details/142099051
版权归原作者 程序员阿灿 所有, 如有侵权,请联系我们删除。

“基于SRS的WebRTC环境搭建”的评论:

还没有评论