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
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'.
搭建編譯環境:
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正常使用
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
構建包,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
參考鏈接:
一個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 源碼解析系列(3)- RtpEndpoint端點初始化解析
Kurento 源碼解析系列(4)- RtpEndpoint端點c層代碼的調用處理
kurento代碼分析(一)C++與C的交互
Kurento模塊開發指南之一:模塊開發簡介
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/66968518。https://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
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

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'
運行 輸出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>
成功時顯示:

推攝像頭通過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
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; } }
播放驗證,用網頁的播放器直接播放: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
商用的:
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/