1 简介
Janus 是一个开源的,通过 C 语言实现了对 WebRTC 支持的 Gateway;Janus 自身实现得很简单,提供插件机制来支持不同的业务逻辑,配合官方自带插件就可以用来实现高效的 Media Server 服务。

本文主要介绍如何在 Ubuntu 16.04 下搭建起 janus 服务器,实现 janus 官方 Demo 浏览器与 Android APP Demo(janus-gateway-android)之间的音视频通话。

音视频高级开发技术交流+720209036

浏览器打开音视频采集的话需要 HTTPS 加密访问!

效果图如下:

Ubuntu 下 Janus Server 搭建笔记
Janus 官网:https://janus.conf.meetecho.com/index.html

参考文档:https://github.com/meetecho/janus-gateway

2 下载和编译 Janus
编译运行 Janus Server 需要依赖较多的一些第三方库,而这些依赖库在 Ubuntu 下主要通过 aptitude 进行安装,首先通过安装 aptitude:

sudo apt-get install aptitude
2.1 命令安装依赖
Ubuntu 下通过 aptitude 批量安装依赖工具包,这里建议 Ubuntu 镜像源(/etc/apt/source.list)不要为了追求速度而改用了国内的某些镜像源,如 网易 163,这可能会导致某些工具包下载失败,建议依然使用官方自带的镜像源。

批量安装命令:

sudo aptitude install libmicrohttpd-dev libjansson-dev libnice-dev
libssl1.0.1-dev libsrtp-dev libsofia-sip-ua-dev libglib2.3.4-dev
libopus-dev libogg-dev libcurl4-openssl-dev pkg-config gengetopt
libtool automake

sudo apt install cmake
sudo aptitude install libconfig-dev
sudo aptitude install libssl-dev
sudo aptitude install doxygen graphviz

ffmpeg库 支持–enable-post-processing

sudo aptitude install libavcodec-dev libavformat-dev libswscale-dev libavutil-dev
如果出现某个工具包下载失败,请修改镜像源为官方地址,并执行已下命令

sudo apt-get update && sudo apt-get upgrade
以更新镜像源,完成后重新安装。

附录:卸载命令

apt-get remove 会删除软件包而保留软件的配置文件
apt-get purge 会同时清除软件包和软件的配置文件
查找包命令

查找软件包
apt-cache search 软件包名
显示软件包的详细信息
apt-cache show 软件包名
音视频高级开发学习资料扫码+qun获取

Ubuntu 下 Janus Server 搭建笔记
2.2 源码安装依赖
2.2.1 安装 WebSocket
janus 支持 WebSocket 是可选项,如果不安装,编译 janus 时,默认不支持 WebSocket 的链接请求,而 Android APP Demo 是通过 WebSocket 与 janus 进行通信的,因为我们希望 Android APP Demo 能与浏览器(HTTP)进行视频通话,所以就必须要在编译 janus 时支持 WebSocket。

依次执行以下命令,分别进行下载,编译,安装:

git clone https://github.com/warmcat/libwebsockets.git
cd libwebsockets
git branch -a 查看选择最新的稳定版本,目前的是remotes/origin/v3.2-stable
git checkout v3.2-stable 切换到最新稳定版本
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" …
make && sudo make install
安装成功后,再编译 janus 时,janus 默认会增加对 WebSocket 的集成,或者通过增加编译参数 --enable-websockets 打开 WebSocket 开关,或 --disable-websockets 关闭 WebSocket 开关。

2.2.2 安装 libsrtp
Janus 需要至少 version 1.5 以上的 libsrtp,如果系统中已经安装了 libsrtp,则首先卸载后,手动安装新版本,这里我们安装 libsrtp 2.2,依次执行以下命令:

wget https://github.com/cisco/libsrtp/archive/v2.2.0.tar.gz
tar xfv v2.2.0.tar.gz
cd libsrtp-2.2.0
./configure --prefix=/usr --enable-openssl
make shared_library && sudo make install

2.2.3 安装libusrsctp
libusrsctp支持–enable-data-channels

git clone https://github.com/Kurento/libusrsctp.git
cd libusrsctp
./bootstrap
./configure
make
sudo make install
2.2.4 安装libmicrohttpd
libmicrohttpd支持–enable-rest

wget https://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.71.tar.gz
tar zxf libmicrohttpd-0.9.71.tar.gz
cd libmicrohttpd-0.9.71/
./configure
make
sudo make install
2.3 编译 Janus
通过 Git 下载 Janus 源码,并编译安装:

git clone https://github.com/meetecho/janus-gateway.git
git tag 查看当前的 tag,选择最新稳定的版本v0.10.4
git checkout v0.10.4
sh autogen.sh
./configure --prefix=/opt/janus --enable-websockets --enable-post-processing --enable-docs --enable-rest --enable-data-channels
make
sudo make install
make install的时候,将janus安装到 /opt/janus路径,插件的so库在/opt/janus/lib/janus/plugins

configure 执行成功后,会输出 janus 所支持的 协议及插件,如下:

ompiler: gcc
libsrtp version: 2.x
SSL/crypto library: OpenSSL
DTLS set-timeout: not available
Mutex implementation: GMutex (native futex on Linux)
DataChannels support: yes
Recordings post-processor: yes
TURN REST API client: yes
Doxygen documentation: yes
Transports:
REST (HTTP/HTTPS): yes
WebSockets: yes
RabbitMQ: no
MQTT: no
Unix Sockets: yes
Nanomsg: no
Plugins:
Echo Test: yes
Streaming: yes
Video Call: yes
SIP Gateway: yes
NoSIP (RTP Bridge): yes
Audio Bridge: yes
Video Room: yes
Voice Mail: yes
Record&Play: yes
Text Room: yes
Lua Interpreter: no
Duktape Interpreter: no
Event handlers:
Sample event handler: yes
WebSocket ev. handler: yes
RabbitMQ event handler:no
MQTT event handler: no
Nanomsg event handler: no
GELF event handler: yes
External loggers:
JSON file logger: no
JavaScript modules: no
3 配置和运行janus
3.1 配置nginx
安装nginx,主要用来提供web访问。

生成证书
mkdir -p ~/cert
cd ~/cert

CA私钥

openssl genrsa -out key.pem 2048

自签名证书

openssl req -new -x509 -key key.pem -out cert.pem -days 1095
安装nginx
#下载nginx 1.15.8版本
wget http://nginx.org/download/nginx-1.15.8.tar.gz
tar xvzf nginx-1.15.8.tar.gz
cd nginx-1.15.8/

配置,一定要支持https

./configure --with-http_ssl_module

编译

make

#安装
sudo make install
修改nginx配置文件
/usr/local/nginx/conf/nginx.conf

指向janus所在目录/opt/janus/share/janus/demos

HTTPS server

#
server {listen       443 ssl;server_name  localhost;# 配置相应的keyssl_certificate      /home/ubuntu/cert/cert.pem;ssl_certificate_key  /home/ubuntu/cert/key.pem;ssl_session_cache    shared:SSL:1m;ssl_session_timeout  5m;ssl_ciphers  HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers  on;# 指向janus demo所在目录location / {root   /opt/janus/share/janus/demos;index  index.html index.htm;}
}

启动nginx

sudo /usr/local/nginx/sbin/nginx

然后通过

https://111.229.231.225/

可以访问到界面,但此时还不能正常通话。

Ubuntu 下 Janus Server 搭建笔记
3.2 安装和启动coturn
sudo apt-get install libssl-dev
sudo apt-get install libevent-dev

#git clone https://github.com/coturn/coturn
#cd coturn

提供另一种安装方式turnserver是coturn的升级版本

wget http://coturn.net/turnserver/v4.5.0.7/turnserver-4.5.0.7.tar.gz
tar xfz turnserver-4.5.0.7.tar.gz
cd turnserver-4.5.0.7

./configure
make
sudo make install
启动

sudo nohup turnserver -L 0.0.0.0 --min-port 30000 --max-port 60000 -a -u lqf:123456 -v -f -r nort.gov &
需要在安全组开放端口:

TCP/UDP 3478

UDP 30000-60000

3.3 配置janus的jcfg文件
janus配置

janus安装目录在/opt/janus

./bin

./etc

./include

./lib

./share

可执行文件

janus配置文件

janus头文件

janus库

存放脚本或者文档,web demo也在这里

配置Video room
我们先配置video room

需要配置的文件为(目录/opt/janus/etc/janus):

并开通8088,8089;8188,8989

要先把.sample后缀的文件拷贝成jcfg后缀

进到对应的目录

cd /opt/janus/etc/janus

拷贝文件

sudo cp janus.jcfg.sample janus.jcfg
sudo cp janus.transport.http.jcfg.sample janus.transport.http.jcfg
sudo cp janus.transport.websockets.jcfg.sample janus.transport.websockets.jcfg
sudo cp janus.plugin.videoroom.jcfg.sample janus.plugin.videoroom.jcfg
sudo cp janus.transport.pfunix.jcfg.sample janus.transport.pfunix.jcfg
sudo cp janus.plugin.streaming.jcfg.sample janus.plugin.streaming.jcfg
sudo cp janus.plugin.recordplay.jcfg.sample janus.plugin.recordplay.jcfg
sudo cp janus.plugin.voicemail.jcfg.sample janus.plugin.voicemail.jcfg
sudo cp janus.plugin.sip.jcfg.sample janus.plugin.sip.jcfg
sudo cp janus.plugin.nosip.jcfg.sample janus.plugin.nosip.jcfg
sudo cp janus.plugin.textroom.jcfg.sample janus.plugin.textroom.jcfg
sudo cp janus.plugin.echotest.jcfg.sample janus.plugin.echotest.jcfg

配置janus.jcfg

大概237行

stun_server = “111.229.231.225”
stun_port = 3478
nice_debug = false

#大概274行

credentials to authenticate…

    turn_server = "111.229.231.225"turn_port = 3478turn_type = "udp"turn_user = "lqf"turn_pwd = "123456"

配置janus.transport.http.jcfg
general: {
#events = true # Whether to notify event handlers about transport events (default=true)
json = “indented” # Whether the JSON messages should be indented (default),
# plain (no indentation) or compact (no indentation and no spaces)
base_path = “/janus” # Base path to bind to in the web server (plain HTTP only)
threads = “unlimited” # unlimited=thread per connection, number=thread pool
http = true # Whether to enable the plain HTTP interface
port = 8088 # Web server HTTP port
#interface = “eth0” # Whether we should bind this server to a specific interface only
#ip = “192.168.0.1” # Whether we should bind this server to a specific IP address (v4 or v6) only
https = true # Whether to enable HTTPS (default=false)
secure_port = 8089 # Web server HTTPS port, if enabled
#secure_interface = “eth0” # Whether we should bind this server to a specific interface only
#secure_ip = “192.168.0.1” # Whether we should bind this server to a specific IP address (v4 or v6) only
#acl = “127.,192.168.0.” # Only allow requests coming from this comma separated list of addresses
}

certificates: {
cert_pem = “/home/ubuntu/cert/cert.pem”
cert_key = “/home/ubuntu/cert/key.pem”
#cert_pwd = “secretpassphrase”
#ciphers = “PFS:-VERS-TLS1.0:-VERS-TLS1.1:-3DES-CBC:-ARCFOUR-128”
}

配置janus.transport.websockets.jcfg

general: {
#events = true # Whether to notify event handlers about transport events (default=true)
json = “indented” # Whether the JSON messages should be indented (default),
# plain (no indentation) or compact (no indentation and no spaces)
#pingpong_trigger = 30 # After how many seconds of idle, a PING should be sent
#pingpong_timeout = 10 # After how many seconds of not getting a PONG, a timeout should be detected

    ws = true                                               # Whether to enable the WebSockets APIws_port = 8188                                  # WebSockets server port#ws_interface = "eth0"                  # Whether we should bind this server to a specific interface only#ws_ip = "192.168.0.1"                  # Whether we should bind this server to a specific IP address onlywss = true                                              # Whether to enable secure WebSocketswss_port = 8989                         # WebSockets server secure port, if enabled#wss_interface = "eth0"                 # Whether we should bind this server to a specific interface only#wss_ip = "192.168.0.1"                 # Whether we should bind this server to a specific IP address only#ws_logging = "err,warn"                # libwebsockets debugging level as a comma separated list of things# to debug, supported values: err, warn, notice, info, debug, parser,# header, ext, client, latency, user, count (plus 'none' and 'all')#ws_acl = "127.,192.168.0."             # Only allow requests coming from this comma separated list of addresses

}

certificates: {
cert_pem = “/home/ubuntu/cert/cert.pem”
cert_key = “/home/ubuntu/cert/key.pem”
#cert_pwd = “secretpassphrase”
}

3.4 修改网页默认支持的wss协议

修改 /opt/janus/share/janus/demos/videoroomtest.js文件

原来为(在45行处)

var server = null;
if(window.location.protocol === ‘http:’)
server = “http://” + window.location.hostname + “:8088/janus”;
else
server = “https://” + window.location.hostname + “:8089/janus”;
将默认的https协议改为wss

var server = “wss://” + window.location.hostname + “:8989”;

3.5 运行 Janus

WebSocket 的ws端口号为 8188和8989,记住这个端口号,在 Android APP Demo 中会使用到!

启动 Janus:

/opt/janus/bin/janus --debug-level=5 --log-file=$HOME/janus-log
根据需要可以选择是否加上后面两个启动参数。

webscoket 一定要启动ws和wss(安全的ws,类比http-https)。

3.6 云服务器端口开放

3.7 测试web和web的通话

https://111.229.231.225/videoroomtest.html

开两个同样的网页,然后点击start,输入名字则开始进行音视频通话测试。

4 视频通话联调测试

我们使用 PC 下的 浏览器 与 Android APP Demo 进行联调。

4.1 启动 Web Demo

这样外部便可以通过 https://111.229.231.225进行访问了,进入首页后,找到 videoRoom,Start

4.2 启动 Android APP Demo

4.2.1 下载源码

git clone https://github.com/pcgpcgpcg/janus-gateway-android.git

4.2.2 修改信令地址

janus-gateway-android 支持两个 Demo 测试:EchoTest 和 VideoRoom,默认情况下会启用 EchoTest,这个 Demo 仅仅是连接服务器后,将数据再发回本地进行本地测试,我们要改为与房间内的其它用户(浏览器)进行视频通话,则需要启用另外一个测试用例 VideoRoom,按照如下方式修改代码:
APP Demo 是通过 WebSocket 连接 Janus Server,所以修改 VideoRoomTest.java 中 roomUrl地址为我们启动的 Janus 服务器 WebSocket 地址,IP 为 janus server 地址,端口默认为 8188:
然后,搜索39.106.100.180,替换为自己的IP。

比如

4.2.3 修改build.gradle

加上

maven{ url’http://maven.aliyun.com/nexus/content/groups/public/’ }
maven { url ‘http://developer.huawei.com/repo/’ }
jcenter { url ‘http://maven.aliyun.com/nexus/content/repositories/jcenter’ }
否则下载不了部分组件。

4.2.4 编译安装

通过 Android studio 进行编译安装到 Android 机。

安装好后的

4.3 联调测试

Janus Server 默认会开启两个视频房间:1234 和 5678,分别使用 VP8 和 VP9 视频编码器,所以我们通过 Brower 和 Android APP Demo 进行联调测试时,暂不需要设置房间 ID。

效果图:
附录
linux – 如何组合音频和视频mjr文件以生成.
我正在使用janus-gateway在网络浏览器中录制.录制完成后,会生成两个文件,一个是音频,另一个是视频.两者都有格式mjr.如何将这两个文件组合在一起创建单个文件?

最佳答案

我正在处理同样的需要.

如果您执行了默认的janus-gateway安装,则只会错过以下步骤:

在你下载git源的文件夹上运行它:

./configure --enable-post-processing
然后

make
(sudo) make install
然后为要将其转换为音频/视频格式的每个文件运行此命令:

./janus-pp-rec /opt/janus/share/janus/recordings/video.mjr /opt/janus/share/janus/recordings/video.webm
./janus-pp-rec /opt/janus/share/janus/recordings/audio.mjr /opt/janus/share/janus/recordings/audio.opus
如果你没有安装ffmpeg运行这个(我在Ubuntu上,在其他发行版上ffmpeg可能已经在apt-get存储库中)

sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
sudo apt-get update
sudo apt-get install ffmpeg
然后最终将音频与视频合并:

(sudo) ffmpeg -i audio.opus -i video.webm -c:v copy -c:a opus -strict experimental mergedoutput.webm
从那里你可以构建一个shell脚本来自动转换cron上的所有mjr文件

Ubuntu 下 Janus Server 搭建笔记相关推荐

  1. raspberry ubuntu 修改源为清华_Ubuntu 下 Janus Server 搭建笔记

    1 Ubuntu 下 Janus Server 搭建笔记 QQ交流群 782508536 FFmpeg/WebRTC/RTMP音视频流媒体高级开发 https://ke.qq.com/course/4 ...

  2. 用Ubuntu和RStudio Server搭建一个R语言的云平台

    前一段介绍过利用Windows系统的Ubuntu子系统搭建数据科学平台,此番来介绍下除了jupyter之外的另外一个数据科学神器:RStudio Server.同时基于Ubuntu和RStudio S ...

  3. Ubuntu 12.04 Server 搭建DNS服务器

    这边简单介绍一下,在Ubuntu 12.04 Server 搭建简单的DNS 服务器 #apt-get -y install bind9 bind9utils 这里我以 hasee.com 域名为例 ...

  4. 简单易行的用windows系统虚拟苹果mac操作系统 mac下android环境搭建笔记(android studio)

    作者:韩梦飞沙 QQ:313134555 ios模拟器电脑版中文版(iPadian)下载 - 『精品软件区』 - 吾爱破解论坛 - LCG - LSG |安卓破解|病毒分析|破解软件|www.52po ...

  5. windows下ssh server搭建方法

    windows下ssh server搭建方法 –网络工程师 陆华兴 微信.手机:18912948909 因项目需求需要搭建ssh server,linux下openssh自带ssh server,wi ...

  6. 非域环境下搭建文件服务器,非域环境下SQL Server搭建Mirror(镜像)的详细步骤...

    原标题:非域环境下SQL Server搭建Mirror(镜像)的详细步骤 1.测试验证环境 服务器角色 机器名 IP SQL Server Ver 主体服务器 WIN-TestDB4O 172.83. ...

  7. Ubuntu下使用valet搭建laravel生产环境

    Ubuntu下使用valet搭建laravel生产环境 1.安装系统所需软件 更新软件列表 sudo apt update 2.更新软件 echo y | sudo apt upgrade 如果觉得时 ...

  8. ubuntu下用docker搭建sslocal

    ubuntu下用docker搭建sslocal 服务器环境 运行sslocal docker容器 服务器环境 阿里云 docker 运行sslocal docker容器 docker run -d \ ...

  9. Ubuntu下各种服务搭建及操作技巧

    Ubuntu下搭建TFTP 1.安装软件包 sudo apt-get install tftpd tftp xinetd 2.建立配置文件 在/etc/xinetd.d/下建立一个配置文件tftp s ...

最新文章

  1. 概要设计实例_多核片上系统(SoC)架构的嵌入式DSP软件设计
  2. php 转义反绡线,wordpress标题中横线“-”被转义的问题
  3. HTML去掉列表前面的符号!
  4. 两对光纤收发器用网线连接_为什么现在的人不喜欢用网线,反而更爱用光纤来传输呢?涨知识了...
  5. 全球首发|阿里云正式推出云数据库Redis6.0版本
  6. php点击弹出文字代码,js实现鼠标点击页面弹出自定义文字效果
  7. Sharepoint学习笔记—ECM系列—找不到Content Type Publishing链接
  8. 选型宝访谈:如何用好移动报销云平台,解放全员工作效率?
  9. 群晖系统安装相关文件分享
  10. 基于Window Server 2016R2 + AD帐号 + Radius无线网络认证
  11. 图像处理中的白化处理
  12. 手把手教你:基于深度学习的滚动轴承故障诊断
  13. 烂泥:关于安装LiveZilla,MySql数据库的问题
  14. Pandas常用函数大合集
  15. 永不服输的Java之路---重学Java (第一章)
  16. python程序设计入门书籍推荐_python刚刚入门,接下来这几本python的书会让你成为别人眼里的大神!...
  17. 胆结石饮食有什么禁忌?
  18. 阿里云推出“通达云OA”办公系统 基于钉钉的移动OA应用
  19. MybatisPlus相关
  20. DJI M210+manifold 2C配置

热门文章

  1. 使用JFreeChart做成柱状图写入word的总结
  2. OTT营销之风正盛,商家到底该怎么投?
  3. linux查看内存条pn,实验:使用GDB查看结构体在内存中的存储方式
  4. 六个月离职空档期获得足够时间反思自我+常见Netty面试题详解
  5. 刷qcn工具|大部分机型qcn文件集合|亲测有效
  6. 基于java springboot新闻发布微信小程序源码(毕设)
  7. 创客机器人比赛简讯_德州经济技术开发区举办首届中小学生创客比赛
  8. 跨国企业在中国 | 德国sto涂料入驻天猫;史密斯和华丰在四川开新工厂
  9. android版本怎么升级8.0,安卓怎么升级8.0版本_安卓升级8.0版本方法_一聚教程网
  10. 微信小程序开发实战(Npm包)