Kurento KMS 流媒体服务器 webRTC转rtmp http flv

webRTC ==(通过nodejs指定的sdp,这个sdp写的要与webrtc源一致)==》 RTP ==》RTMP

各种推流方法:https://www.cnblogs.com/bigben0123/p/14188475.html

整个启动流程:

1,启动kurento服务:

~/kms/kms-omni-build$ ./bin/kms-build-run.sh
若以前启动了,先停止
sudo service kurento-media-server  stop

2,启动虚拟摄像头。用抓取桌面录屏,输出到虚拟摄像头

sudo depmod -a
sudo modprobe v4l2loopback
ffmpeg -f x11grab -r 15 -s 1280x720 -i :0.0+0,0 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0

无限循环推流:-stream_loop -1  无限次; 0是不循环;

ffmpeg -re  -stream_loop -1  -i ./doc/source.200kbps.768x320.flv  -f v4l2 /dev/video0

 

3,启动nodejs 服务,http 端口在8000

~/dev/kurento-rtmp$ npm start

3.1 如果nodejs不推流,自己推:

gst-launch-1.5 -em \
  rtpbin name=rtpbin latency=5 \
  udpsrc port=5003 caps="application/x-rtp,media=(string)audio,clock-rate=(int)48000,encoding-name=(string)OPUS" ! rtpbin.recv_rtp_sink_0 \
    rtpbin.  ! rtpopusdepay ! opusdec !  audioconvert ! audioresample ! voaacenc ! aacparse ! mux. \
  udpsrc port=5004 caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264" ! rtpbin.recv_rtp_sink_1 \
    rtpbin.  ! rtph264depay ! h264parse ! mux. \
  flvmux name=mux streamable=true ! rtmpsink sync=false location=rtmp://192.168.16.133/live/55000

 

4,访问 https://localhost:8443/ ,网页start启动webrtc。

5,打开网址播放:https://ossrs.net/players/srs_player.html

在srs播放器中url中输入:

http://192.168.16.133:8000/live/55000.flv 

或者是rmtp地址 

rtmp://192.168.16.133/live/55000

 kurento c源码修改后,生效:

1,重新执行 

       ./bin/kms-build-run.sh

2,页面https://localhost:8443/#,执行stop,然后再start

3,看播放地址,数字+2. 比如:http://192.168.16.133:8000/live/55004.flv

 


 

具体方法见如下介绍: 

流媒体服务介绍https://blog.csdn.net/qq_28880087/article/details/106604113 

KMS 流媒体服务器源码安装(https://doc-kurento.readthedocs.io/en/latest/dev/dev_guide.html)

 Kurento是一个底层平台取搭建WebRTC应用。需要自己管理 STUN/TURN servers, networking, scalability, etc. 新手建议用OpenVidu 是基于Kurento的开源应用.

官方示例:https://doc-kurento.readthedocs.io/en/latest/user/tutorials.html

支持java,browser js,nodejs。

 

1,官方只支持 Long-Term Support (LTS)Ubuntu: Ubuntu 16.04 (Xenial) and Ubuntu 18.04 (Bionic) (64-bits only).

18.04的源:https://blog.csdn.net/qq_40584960/article/details/82950511

题外话:

ubuntu的更新注意选择自己的版本,比如19.10的话得是eoan

ubuntu源站:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/ 

#163源
deb http://mirrors.163.com/ubuntu/ eoan main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ eoan-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ eoan-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ eoan-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ eoan-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ eoan main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ eoan-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ eoan-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ eoan-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ eoan-backports main restricted universe multiverse
View Code

 

Install required tools

This command will install the basic set of tools that are needed for the next steps:

sudo apt-get update && sudo apt-get install --no-install-recommends --yes \
    build-essential \
    ca-certificates \
    cmake \
    git \
    gnupg

Add Kurento repository

Run these commands to add the Kurento repository to your system configuration:

# Import the Kurento repository signing key
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5AFA7A83

# Get Ubuntu version definitions
source /etc/upstream-release/lsb-release 2>/dev/null || source /etc/lsb-release

# Add the repository to Apt
sudo tee "/etc/apt/sources.list.d/kurento.list" >/dev/null <<EOF
# Kurento Media Server - Nightly packages
deb [arch=amd64] http://ubuntu.openvidu.io/dev $DISTRIB_CODENAME kms6
EOF

sudo apt-get update

Install build dependencies

Run:更新编译依赖包,包括jdk等

sudo apt-get update && sudo apt-get install --no-install-recommends --yes \
    kurento-media-server-dev

Download KMS source code

Run:

git clone https://github.com/Kurento/kms-omni-build.git
cd kms-omni-build
git submodule update --init --recursive
git submodule update --remote

Note

--recursive and --remote are not used together, because each individual submodule may have their own submodules that might be expected to check out some specific commit, and we don’t want to update those.

OPTIONAL: Change to the master branch of each submodule, if you will be working with the latest version of the code:

REF=master
git checkout "$REF" || true
git submodule foreach "git checkout $REF || true"

You can also set REF to any other branch or tag, such as REF=6.12.0. This will bring the code to the state it had in that version release.

Install build dependencies 这个步骤原文档在下载源码前面执行。需要在这里再次运行一次!编译就没问题。

Run:更新编译依赖包,包括jdk等

sudo apt-get update && sudo apt-get install --no-install-recommends --yes \
    kurento-media-server-dev

Build and run KMS 编译并运行

Make sure your current directory is already kms-omni-build, then run this command:

export MAKEFLAGS="-j$(nproc)"
./bin/kms-build-run.sh

By default, the script kms-build-run.sh will set up the environment and settings to make a Debug build of KMS. You can inspect that script to learn about all the other options it offers, including builds for AddressSanitizer, selection between GCC and Clang compilers, and other modes.

You can set the logging level of specific categories by exporting the environment variable GST_DEBUG before running this script (see Debug Logging).

手动启动/停止

sudo service kurento-media-server start

sudo service kurento-media-server stop

1
缺软件:
sudo apt install pkg-config

2.
gedit ./bin/kms-build-run.sh 450行

# System limits: Set maximum open file descriptors
# Maximum limit value allowed by Ubuntu: 2^20 = 1048576
ulimit -n 1048576

报错ulimit没有权限。

3.

启动时无法开启端口:端口占用了,查看sudo netstat -atunp | more

0:00:00.163066989 2905 0x558b6ba5df50 ERROR KurentoWebSocketTransport WebSocketTransport.cpp:156:initWebSocket: WebSocket error: cannot listen on IPv6 port 8888 (Underlying Transport Error), will try IPv4
0:00:00.163147556 2905 0x558b6ba5df50 ERROR KurentoWebSocketTransport WebSocketTransport.cpp:166:initWebSocket: WebSocket error: cannot listen on IPv4 port 8888 (Underlying Transport Error)

 

 


 

构建发行包:

参考:https://doc-kurento.readthedocs.io/en/latest/dev/dev_guide.html#debian-packages

sudo apt install devscripts

或者 ./bin/.sh --release

 Arguments
#/ ---------
#/
#/ --build-only
#/
#/   Only build the source code, without actually running KMS.
#/
#/   Optional. Default: Disabled.
#/
#/ --release
#/
#/   Build in Release mode with debugging symbols.
#/
#/   If this option is not given, CMake will be configured for a Debug build.
#/
#/   Optional. Default: Disabled.
#/
#/ --gdb
#/
#/   Run KMS in a GDB session. Useful to set break points and get backtraces.
#/
#/   Optional. Default: Disabled.
#/
#/ --clang
#/
#/   Build (and run, in case of using a Sanitizer) with Clang C/C++ compiler.
#/
#/   Note: You are still in charge of providing the desired version of Clang in
#/   `/usr/bin/clang` for C; `/usr/bin/clang++` for C++.
#/   For this, either create symlinks manually, or have a look into the
#/   Debian/Ubuntu alternatives system (`update-alternatives`).
#/
#/   Optional. Default: Disabled. When disabled, the compiler will be GCC.
#/
#/ --verbose
#/
#/   Tell CMake to generate verbose Makefiles, that will print every build
#/   command as they get executed by `make`.
#/
#/   Optional. Default: Disabled.
#/
#/ --valgrind-memcheck
#/
#/   Build and run with Valgrind's Memcheck memory error detector.
#/   Valgrind should be available in the PATH.
#/
#/   See:
#/   * Memcheck manual: http://valgrind.org/docs/manual/mc-manual.html
#/
#/   Optional. Default: Disabled.
#/   Implies '--release'.
#/
#/ --valgrind-massif
#/
#/   Build and run with Valgrind's Massif heap profiler.
#/   Valgrind should be available in the PATH.
#/
#/   Massif gathers profiling information, which then can be loaded with
#/   the `ms_print` tool to present it in a readable way.
#/
#/   For example:
#/
#/       ms_print valgrind-massif-13522.out >valgrind-massif-13522.out.txt
#/
#/   See:
#/   * Massif manual: http://valgrind.org/docs/manual/ms-manual.html
#/
#/   Optional. Default: Disabled.
#/   Implies '--release'.
#/
#/ --valgrind-callgrind
#/
#/   Build and run with Valgrind's Callgrind performance profiler.
#/   Valgrind should be available in the PATH.
#/
#/   Callgrind gathers profiling information, which then can be loaded with
#/   the `KCachegrind` tool to visualize and interpret it.
#/
#/   See:
#/   * Callgrind manual: http://valgrind.org/docs/manual/cl-manual.html
#/
#/   Optional. Default: Disabled.
#/   Implies '--release'.
#/
#/ --address-sanitizer
#/
#/   Build and run with the instrumentation provided by the compiler's
#/   AddressSanitizer and LeakSanitizer (available in GCC and Clang).
#/
#/   See:
#/   * https://clang.llvm.org/docs/AddressSanitizer.html
#/   * https://clang.llvm.org/docs/LeakSanitizer.html
#/
#/   Optional. Default: Disabled.
#/   Implies '--release'.
#/
#/ --thread-sanitizer
#/
#/   Build and run with the instrumentation provided by the compiler's
#/   ThreadSanitizer (available in GCC and Clang).
#/
#/   See: https://clang.llvm.org/docs/ThreadSanitizer.html
#/
#/   NOTE: A recent version of GCC is required for ThreadSanitizer to work;
#/   GCC 5, 6 and 7 have been tested and don't work; GCC 8 and 9 do.
#/   On top of that, there's the issue of having some false positives due
#/   to the custom thread-synchronization routines from GLib (like GMutex),
#/   which TSAN doesn't understand and ends up considering as race conditions.
#/
#/   The official solution is to recompile GLib with TSAN instrumentation.
#/
#/   Optional. Default: Disabled.
#/   Implies '--release'.
#/
#/ --undefined-sanitizer
#/
#/   Build and run with the compiler's UndefinedBehaviorSanitizer, an
#/   undefined behavior detector (available in GCC and Clang).
#/
#/   See:
#/   * https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
#/
#/   Optional. Default: Disabled.
#/   Implies '--release'.
View Code

 


 

搭建编译环境:

docker安装:https://blog.csdn.net/a346492443/article/details/106355273/

docker权限问题:

sudo groupadd docker     #添加docker用户组
sudo gpasswd -a $USER docker     #将登陆用户加入到docker用户组中
newgrp docker     #更新用户组
docker ps    #测试docker命令是否可以使用sudo正常使用
View Code

kms拉取docker和启动

docker pull kurento/kurento-media-server:latest

docker run -d --name kms --network host \
    kurento/kurento-media-server:latest

获取log:
docker logs --follow kms >"kms-$(date '+%Y%m%dT%H%M%S').log" 2>&1
View Code

 

构建包,kurento由不同的包组成应用,如kms-core,kms-element等:

--install-kurento将自动安装依赖包
git clone https://github.com/Kurento/adm-scripts.git
git clone https://github.com/Kurento/kms-core.git
cd kms-core/
../adm-scripts/kurento-buildpackage.sh \
    --install-kurento 6.12.0 \
    --apt-add-repo

1) 通过kms-omni-build 全下载编译构建 nightly版本的kms-elements部分:

To build kms-elements from within kms-omni-build (sadly a limitation in the underlying tool git-buildpackage forces us to make this differentiation when using kms-omni-build to develop Kurento):

git clone https://github.com/Kurento/kms-omni-build.git
cd kms-omni-build/
git submodule update --init --recursive
git submodule update --remote
docker run --rm \
    --mount type=bind,src="$PWD",dst=/hostdir \
    kurento/kurento-buildpackage:xenial \
    --install-kurento nightly \
    --srcdir kms-elements

2)通过docker的image构建 kms模块:kurento-buildpackage Docker image

构建环境都搭好在docker中了,只要将外部的源码映射入docker即可。

可以创建不同包对不同Ubuntu版本。

使用kurento-buildpackage Docker image,出了隐射源码目录到 /hostdir其他操作和本地编译一样。

比如构建kms-core development branch against Kurento 6.12.0, for Ubuntu 16.04 (Xenial) systems. 

git clone https://github.com/Kurento/kms-core.git
cd kms-core/
docker run --rm \
    --mount type=bind,src="$PWD",dst=/hostdir \
    kurento/kurento-buildpackage:xenial \
        --install-kurento 6.12.0 \
        --apt-add-repo

 

 构建参数说明:

kurento-buildpackage.sh
$ adm-scripts/kurento-buildpackage.sh --help

Package creation tool for Kurento projects.

This shell script is used to build all Kurento Media Server modules, and
generate Debian/Ubuntu package files from them. It will automatically
install all required dependencies with `apt-get`, then build the project.

The script must be called from within a Git repository.


Arguments
---------

--install-kurento <KurentoVersion>

  Install dependencies that are required to build the package, using the
  Kurento package repository for those packages that need it.

  <KurentoVersion> indicates which Kurento repo must be used to download
  packages from. E.g.: "6.8.0". If "dev" or "nightly" is given, the
  Kurento nightly packages will be used instead.

  Typically, you will provide an actual version number when also using
  the '--release' flag, and just use "nightly" otherwise. In this mode,
  `apt-get` will download and install all required packages from the
  Kurento repository for Ubuntu.

  This argument is useful for end users, or external developers which may
  want to build a specific component of Kurento without having to build
  all the dependencies.

  Optional. Default: Disabled.
  See also: '--install-files'.

--install-files [FilesDir]

  Install specific dependency files that are required to build the package.

  [FilesDir] is optional, it sets a directory where all '.deb' files
  are located with required dependencies.

  This argument is useful during incremental builds where dependencies have
  been built previously but are still not available to download with
  `apt-get`, maybe as a product of previous jobs in a CI pipeline.

  '--install-files' can be used together with '--install-kurento'. If none
  of the '--install-*' arguments are provided, all non-system dependencies
  are expected to be already installed.

  Optional. Default: Disabled.
  See also: '--install-kurento'.

--srcdir <SrcDir>

  Specifies in which sub-directory the script should work. If not specified,
  all operations will be done in the current directory where the script has
  been called.

  The <SrcDir> MUST contain a 'debian/' directory with all Debian files,
  which are used to define how to build the project and generate packages.

  This argument is useful for Git projects that contain submodules. Running
  directly from a submodule directory might cause some problems if the
  command `git-buildpackage` is not able to identify the submodule as a
  proper Git repository.

  Optional. Default: Current working directory.

--dstdir <DstDir>

  Specifies where the resulting Debian package files ('*.deb') should be
  placed after the build finishes.

  Optional. Default: Current working directory.

--allow-dirty

  Allows building packages from a working directory where there are
  unstaged and/or uncommited source code changes. If this option is not
  given, the working directory must be clean.

  NOTE: This tells `dpkg-buildpackage` to skip calling `dpkg-source` and
  build a Binary-only package. It makes easier creating a test package, but
  in the long run the objective is to create oficially valid packages which
  comply with Debian/Ubuntu's policies, so this option should not be used
  for final release builds.

  Optional. Default: Disabled.

--release

  Build packages intended for Release. If this option is not given, packages
  are built as nightly snapshots.

  Optional. Default: Disabled.

--timestamp <Timestamp>

  Apply the provided timestamp instead of using the date and time this
  script is being run.

  <Timestamp> must be a decimal number. Ideally, it represents some date
  and time when the build was done. It can also be any arbitrary number.

  Optional. Default: Current date and time, as given by the command
  `date --utc +%Y%m%d%H%M%S`.


Dependency tree
---------------

* git-buildpackage
  - Python 3 (pip, setuptools, wheel)
  - debuild (package 'devscripts')
    - dpkg-buildpackage (package 'dpkg-dev')
    - lintian
  - git
    - openssh-client (for Git SSH access)
* lsb-release
* mk-build-deps (package 'devscripts')
  - equivs
* nproc (package 'coreutils')
* realpath (package 'coreutils')


Dependency install
------------------

apt-get update && apt-get install --yes \
  python3 python3-pip python3-setuptools python3-wheel \
  devscripts \
  dpkg-dev \
  lintian \
  git \
  openssh-client \
  lsb-release \
  equivs \
  coreutils
pip3 install --upgrade gbp
View Code

参考链接:

一个go语言实现的rtmp,具有可插拔特性。http://docs.monibuca.com/

https://www.oschina.net/project/tag/111/streaming

Delivery HTTP FLV Stream

webrtc笔记(5): 基于kurento media server的多人视频聊天示例

flyhelloword的博客_CSDN博客-Linux,Kurento,笔记领域博主

Kurento- Kurento Java Tutorial - kurento-magic-mirror Could not Run Successfully, Why?_flyhelloword的博客-CSDN博客 编译执行

从源安装kurento详解

Kurento 源码解析系列(3)- RtpEndpoint端点初始化解析

Kurento 源码解析系列(4)- RtpEndpoint端点c层代码的调用处理

kurento代码分析(一)C++与C的交互

Kurento模块开发指南之一:模块开发简介

gstream 开发

GStreamer基础教程01——Hello World

 

gcc -Wall $(pkg-config --cflags --libs gstreamer-1.5) hello.c -o hello 
./hello 

 

FFmpeg情景分析 1. FFmpeg转码框架解析

“视频”通常都是一种三层数据封装结构:

        编码图像和声音形成的裸视频流(如H.264, VP8, 等)和音频流(mp3, AAC等);

        用容器格式将这些裸流封装形成文件(FLV,rmvb, mkv等)或流(mpeg2-TS等);

        再利用传输协议(如RTSP, RTMP, HTTP, UDP等)将数据通过 互联网,电视线路或无线网络等传输到用户端(电视机,PC,移动设备等)以收看。

 

流媒体


 

webrtc的开源实现,搭建本地的流媒体服务器,进行rtsp视频流转发,如果可以再叠加一些机器视觉的内容。本篇内容主要解决如何在本地虚拟服务器unbuntu搭建kurento-media-server。

kurentu-media-server是什么?这是一个基于webrtc协议的开源实现。类似其他的开源项目可以参考https://yq.aliyun.com/articles/611978。每个项目都有各自的特点。通过kurentu-media-server逐步切入webrtc,搭建自己的流媒体服务器,关于kurentu与rtsp请戳这里https://www.kurento.org/tags/rtsp

网上教程很多,推荐一个个人感觉很好的https://blog.csdn.net/hyl999/article/details/100176218

官网环境提供了可供测试的java demo。https://github.com/Kurento/kurento-tutorial-java。如何搭建测试环境,可以参考这里https://blog.csdn.net/llhswwha/article/details/102896066

另外一种测试方法在这里https://github.com/lulop-k/kurento-rtsp2webrtc。这个是基于js的前端项目。与人通过这个项目,接入了海康摄像头,感兴趣可以戳这里https://blog.csdn.net/Beihangxiaobao/article/details/89450250。关于与摄像头的详细交互逻辑,原理可以参考这里https://blog.csdn.net/biaobro/article/details/66968518https://blog.csdn.net/qq_32523587/article/details/89041326。这里还有一个关于公网打洞穿透的案例,没试过https://blog.csdn.net/zsj777/article/details/81784256

关于延迟,这里有一篇完美解决了延迟的问题。https://www.cnblogs.com/lanqie/p/8510634.html


  •  rtmp服务 HTTP-FLV

mugennsou/http-flv http-flv/README_CN.md at master · mugennsou/http-flv (github.com)

nginx-http-flv-module/README.CN.md at master · winshining/nginx-http-flv-module (github.com)

下载docker镜像:
docker pull mugennsou/nginx-http-flv

运行流媒体服务器:
docker run --rm -it -p 80:80 -p 1935:1935 mugennsou/nginx-http-flv

往指定的服务器推流
ffmpeg -re -i ~/Videos/b.mp4  -c copy -f flv  rtmp://127.0.0.1/demo/stream-1

访问
 http://127.0.0.1

Ubuntu安装ffmpeg: sudo apt-get install ffmpeg

 

srs流媒体服务器

推流:

RTMP使用Frame,即帧级别对象。
RTC使用RTP,即包级别对象,Video Frame可能会包含多个RTP packet。
RTMP转RTC,使用Bridger,这样使RTMP和RTC的逻辑相对独立。
RTC下行NACK和PLI都支持,上行NACK还未支持,能跑通了。

详细改动可以参考:c768a8c...3cb797d

 

https://blog.csdn.net/lixiang987654321/article/details/108714690

webRTC推流 视频教学:https://www.bilibili.com/video/av800024876/

SRS文档:

https://github.com/ossrs/srs/tree/4.0release
https://github.com/ossrs/srs/wiki/v4_CN_Home

源码编译:

国内:
1,
源码克隆
git clone https://gitee.com/winlinvip/srs.oschina.git srs &&
cd srs/trunk && git remote set-url origin https://github.com/ossrs/srs.git && git pull
2,
转到最新4.0开发版,因要使用webRTC
git checkout 4.0release

3,–rtc=on 默认
./configure --with-hls --with-ssl --with-http-server --with-http-callback --with-http-api --with-ingest --with-stream-caster && make 

 

成功后显示:

Generate Makefile
Configure ok! 

Configure summary:
     --x86-x64 --with-hls --with-ssl --with-http-server --with-http-callback --with-http-api --with-ingest --with-stream-caster
     --prefix=/usr/local/srs --hls=on --hds=off --dvr=on --ssl=on --https=on --ssl-1-0=off --sys-ssl=off --transcode=on --ingest=on --stat=on --http-callback=on --http-server=on --stream-caster=on --http-api=on --utest=off --srt=off --rtc=on --simulator=off --gb28181=off --cxx11=off --cxx14=off --ffmpeg-fit=on --nasm=off --srtp-nasm=off --sendmmsg=off --clean=on --gperf=off --gmc=off --gmd=off --gmp=off --gcp=off --gprof=off --log-trace --cc=gcc --cxx=g++ --ar=ar --ld=ld --randlib=randlib
HLS is enabled.
Experiment: StreamCaster is enabled.
Warning: HDS is disabled.
Warning: SRT is disabled.
Experiment: RTC is enabled. https://github.com/ossrs/srs/issues/307
Experiment: HTTPS is enabled. https://github.com/ossrs/srs/issues/1657
DVR is enabled.
RTMP complex handshake is enabled
The transcoding is enabled
The ingesting is enabled.
The http-callback is enabled
Embeded HTTP server for HTTP-FLV/HLS is enabled.
The HTTP API is enabled
Note: The utests are disabled.
Note: The gperf(tcmalloc) is disabled.
Note: The gmc(gperf memory check) is disabled.
Note: The gmd(gperf memory defense) is disabled.
Note: The gmp(gperf memory profile) is disabled.
Note: The gcp(gperf cpu profile) is disabled.
Note: The gprof(GNU profile tool) is disabled.
Note: The valgrind is disabled.
Enable module: modules/hls-ingester
Enable module: modules/mp4-parser
Do full cleanup, you can disable it by: --clean=off
You can clean each some components, see make help

You can run 3rdparty applications:
" python ./research/api-server/server.py 8085  " to start the api-server

You can build SRS:
" make " to build the srs(simple rtmp server).
" make help " to get the usage of make
View Code
make _default
make[1]: Entering directory '/home/zhibin/dev/srs/trunk'
Build the srs(simple rtmp server) over ST(state-threads)
make -f objs/Makefile srs
make[2]: Entering directory '/home/zhibin/dev/srs/trunk'
make[2]: Nothing to be done for 'srs'.
make[2]: Leaving directory '/home/zhibin/dev/srs/trunk'
Ignore utest for it's disabled.
Build the srs_hls_ingester over SRS
make -f objs/Makefile srs_hls_ingester
make[2]: Entering directory '/home/zhibin/dev/srs/trunk'
make[2]: Nothing to be done for 'srs_hls_ingester'.
make[2]: Leaving directory '/home/zhibin/dev/srs/trunk'
Build the srs_mp4_parser over SRS
make -f objs/Makefile srs_mp4_parser
make[2]: Entering directory '/home/zhibin/dev/srs/trunk'
make[2]: Nothing to be done for 'srs_mp4_parser'.
make[2]: Leaving directory '/home/zhibin/dev/srs/trunk'
The build summary:
     +------------------------------------------------------------------------------------
     For SRS benchmark, gperf, gprof and valgrind, please read:
          http://blog.csdn.net/win_lin/article/details/53503869
     +------------------------------------------------------------------------------------
     |The main server usage: ./objs/srs -c conf/srs.conf, start the srs server
     |     About HLS, please read https://github.com/ossrs/srs/wiki/v2_CN_DeliveryHLS
     |     About DVR, please read https://github.com/ossrs/srs/wiki/v3_CN_DVR
     |     About SSL, please read https://github.com/ossrs/srs/wiki/v1_CN_RTMPHandshake
     |     About transcoding, please read https://github.com/ossrs/srs/wiki/v3_CN_FFMPEG
     |     About ingester, please read https://github.com/ossrs/srs/wiki/v1_CN_Ingest
     |     About http-callback, please read https://github.com/ossrs/srs/wiki/v3_CN_HTTPCallback
     |     Aoubt http-server, please read https://github.com/ossrs/srs/wiki/v2_CN_HTTPServer
     |     About http-api, please read https://github.com/ossrs/srs/wiki/v3_CN_HTTPApi
     |     About stream-caster, please read https://github.com/ossrs/srs/wiki/v2_CN_Streamer
     |     (Disabled) About VALGRIND, please read https://github.com/ossrs/state-threads/issues/2
     +------------------------------------------------------------------------------------
binaries, please read https://github.com/ossrs/srs/wiki/v2_CN_Build
You can:
      ./objs/srs -c conf/srs.conf
                  to start the srs server, with config conf/srs.conf.
make[1]: Leaving directory '/home/zhibin/dev/srs/trunk'
View Code

运行 输出webRTC(参考:https://github.com/ossrs/srs/issues/307):

 ./objs/srs -c conf/rtc.conf 
[2020-12-14 16:57:41.108][Trace][38868][34doo9ww] XCORE-SRS/4.0.56(Leo)
[2020-12-14 16:57:41.108][Trace][38868][34doo9ww] config parse complete
[2020-12-14 16:57:41.108][Trace][38868][34doo9ww] you can check log by: tail -f ./objs/srs.log (@see https://github.com/ossrs/srs/wiki/v1_CN_SrsLog)
[2020-12-14 16:57:41.108][Trace][38868][34doo9ww] please check SRS by: ./etc/init.d/srs status

用FFMPEG或OBS推送RTMP流到服务器:

  用rtmp来传输flv流:

ffmpeg -re -i doc/source.200kbps.768x320.flv -c copy \
    -f flv -y rtmp://192.168.1.3/live/livestream

obs的界面设置,后面的串流密钥a.flv是要接到url就可以观看了。

播放器中url写: http://localhost:8000/live/a.flv

 flv播放器h5源码:

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>    
        <script src="https://cdn.bootcss.com/flv.js/1.4.0/flv.min.js"></script>
        <video id="videoElement" style="width: 80%;" controls="controls"></video>
        <script>
            if (flvjs.isSupported()) {
                var videoElement = document.getElementById('videoElement');
                var flvPlayer = flvjs.createPlayer({
                    type: 'flv',
                    url:'http://localhost:8000/live/a.flv' 
                });
                flvPlayer.attachMediaElement(videoElement);
                flvPlayer.load();
                flvPlayer.play();
            }
        </script>
    </body>
</html>
View Code
成功时显示:
推摄像头通过rtmp推流
ffmpeg -f dshow -i video="HD Camera":audio="麦克风阵列 (Realtek(R) Audio)" -vcodec libx264 -x264opts "bframes=0"  -r 25 -g 25 -preset:v ultrafast -tune:v zerolatency -codec:a aac -ac 2 -ar 44100 -f flv rtmp://192.168.50.150:1935/live/1 
View Code

webRTC推流:https://ossrs.net/players/srs_player.html 这个页面都有包括播放,推流。 

推流拉流工具ffmpeg,obs界面 方法:https://cloud.tencent.com/developer/article/1505068

sudo add-apt-repository ppa:obsproject/obs-studio
sudo apt update
sudo apt install obs-studio

 

可播放的流地址:

  • rtmp://127.0.0.1/live/livestream
  • webrtc://127.0.0.1/live/livestream
  • http flv地址是:  http://192.168.16.133:8080/live/livestream.flv
  • 对于http flv需要在conf/rtc.conf中添加 http remux:
  • vhost __defaultVhost__ {
        rtc {
            enabled     on;
            bframe      discard;
        }
        http_remux {
            enabled     on;
            mount       [vhost]/[app]/[stream].flv;
        }
    }
    View Code

     

播放验证,用网页的播放器直接播放:https://ossrs.net/players/srs_player.html 输入网址即可播放 webrtc rtmp等

 


 go实现的webrtc。

开源的monibuca,简洁和可插拔,架构不错:http://docs.monibuca.com/

首先我们知道,Rtmp是一种客户端到服务端的技术,Peer to Server。WebRTC是一种客户端到客户端的技术,Peer to Peer。

Rtmp通过一个TCP连接,向服务端发送或接收连接信息,媒体数据。

WebRTC先使用ICE技术连接STUN/TURN,得到自己的连接信息。再绑定音视频设备获取媒体信息,拼装为SDP信令。两个客户端通过任意方式交换信令,建立客户端直接的连接,再使用RTP发送和接收媒体数据。

如果一个服务端实现了WebRTC客户端的能力,那么它也可以被认为是一个Peer,与用户浏览器的WebRTC客户端创建连接,获得客户端推送过来的媒体数据,就完成了Peer to Server的转换。

需要定义信令交换的方式,web编程当然最简单的就是WebSocket了,定义了一个URL格式
wss://serverip:port/live/stream.rtc 
这种格式和RTMP,HTTP-FLV等相互通用。必须是wss,因为现在的浏览器对webrtc访问摄像头,测试用localhost可以不用ssl。信令交换后,客户端创建了和服务端的udp连接,并源源不断的发送H.264+Opus的rtp包。目前客户端能使用的视频编码是vp8,vp9,h264,音频有PCMA,Opus,不会有AAC,因此我们还需要定义flv封装Opus。Opus和AAC类似,我们定义id为13。这样实现rtmp播放客户端的时候,加入opus解码能力和flv负载opus的能力,就可以播放啦。服务端将Opus直接转码为AAC todo。

webRTC不是localhost时需要https,可以做个代理实现

https://github.com/ossrs/go-oryx/tree/develop/httpx-static

文档都在上面的链接中,做为代理的命令:

go get github.com/ossrs/go-oryx/httpx-static &&
cd $GOPATH/src/github.com/ossrs/go-oryx/httpx-static &&
openssl genrsa -out server.key 2048 &&
subj="/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=me.org" &&
openssl req -new -x509 -key server.key -out server.crt -days 365 -subj $subj &&
$GOPATH/bin/httpx-static -https 8443 -root `pwd`/html -proxy http://ossrs.net:1985/api/v1

windows上启动,https端口在8443

set PATH=%gopath%\bin;E:\dev\TASSL-1.1.1b-master\apps;%PATH%;
cd C:\Users\zhibin\go\src\github.com\ossrs\go-oryx\httpx-static

rem openssl genrsa -out server.key 2048
rem openssl req -new -x509 -key server.key -out server.crt -days 365 -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=me.org"
rem httpx-static -t 8088 -s 8443 -r ./html -p http://localhost:8081 -d 192.168.50.206 -k server.key -c server.crt

 

WebRTC 研究系列 二、打通webrtc与rtmp

pion/webrtc  go语言的。

https://github.com/pion/example-webrtc-applications/tree/master/twitch 一个利用ffmpeg转发到rtmp的示例

 


 

WebRTC video stream broadcast
with conversion to RTMP

WebRTC broadcast with republishing as RTMP

WebRTC as RTMP republishing

商用的:

1,http://bashell.nodemedia.cn/archives/webrtc-research-series-2-get-through-webrtc-and-rtmp.html

WebRTC推流--ShowDoc (nodemedia.cn) 

2,https://flashphoner.com/webrtc-as-rtmp-re-publishing/


 

带你吃透RTMP

SRS 代码分析 https://blog.csdn.net/ManagerUser/article/details/73840130/

srs部署/webrtc拉流

webrtc 资源

WebRTC for the Curious

posted @ 2020-12-10 11:52  Bigben  阅读(4161)  评论(0编辑  收藏  举报