-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
migrate_v4_EN_webrtc
https://github.com/ossrs/srs/issues/307
There are some config for WebRTC:
- full.conf: Section
rtc_server
and vhostrtc.vhost.srs.com
is about WebRTC. - rtc.conf: WebRTC to WebRTC clients.
- rtmp2rtc.conf: Covert RTMP to WebRTC.
- rtc2rtmp.conf: Covert WebRTC to RTMP.
The play will definitely fail if the CANDIDATE
of config is not correct,
because it's the RTP server address(IP
and port) in SDP, the IP
is CANDIDATE
:
type: answer, sdp: v=0
a=candidate:0 1 udp 2130706431 192.168.3.6 8000 typ host generation 0
So the CANDIDATE
is 192.168.3.6
here, which is the IP of server.
We could config it by:
- Use plaintext IP directly, such as
candidate 192.168.3.6;
- Use command
ifconfig
to retrieve IP of network interface, pass it by ENV, such ascandidate $CANDIDATE;
- Try to read the intranet IP from network interface, for example,
candidate *;
- Read from query string of stream URL, such as
webrtc://192.168.3.6/live/livestream?eip=192.168.3.6
Use command ifconfig
to retrieve the IP:
# For macOS
CANDIDATE=$(ifconfig en0 inet| grep 'inet '|awk '{print $2}')
# For CentOS
CANDIDATE=$(ifconfig eth0|grep 'inet '|awk '{print $2}')
# Directly set ip.
CANDIDATE="192.168.3.10"
Pass it to SRS by ENV:
env CANDIDATE="192.168.3.10" \
./objs/srs -c conf/rtc.conf
For example, to run SRS in docker, and setup the CANDIDATE:
export CANDIDATE="192.168.3.10"
docker run --rm --env CANDIDATE=$CANDIDATE \
-p 1935:1935 -p 8080:8080 -p 1985:1985 -p 8000:8000/udp \
ossrs/srs:4 \
objs/srs -c conf/rtc.conf
Note:About the usage of srs-docker, please read srs-docker.
Online demo URL:
The streams for SRS usage:
- VLC(RTMP): rtmp://localhost/live/livestream
- H5(HTTP-FLV): http://localhost:8080/live/livestream.flv
- H5(HLS): http://localhost:8080/live/livestream.m3u8
- H5(WebRTC): webrtc://localhost/live/livestream
About the API for WebRTC, please read publish and play.
Please use conf/rtmp2rtc.conf
as config.
export CANDIDATE="192.168.1.10"
docker run --rm --env CANDIDATE=$CANDIDATE \
-p 1935:1935 -p 8080:8080 -p 1985:1985 -p 8000:8000/udp \
ossrs/srs:4 \
objs/srs -c conf/rtmp2rtc.conf
Note: Please set CANDIDATE as the ip of server, please read CANDIDATE.
Use FFmpeg docker to push to localhost:
docker run --rm --network=host ossrs/srs:encoder ffmpeg -re -i ./doc/source.flv \
-c copy -f flv rtmp://localhost/live/livestream
Play the stream in browser:
Please use conf/rtc.conf
as config.
export CANDIDATE="192.168.1.10"
docker run --rm --env CANDIDATE=$CANDIDATE \
-p 1935:1935 -p 8080:8080 -p 1985:1985 -p 8000:8000/udp \
ossrs/srs:4 \
objs/srs -c conf/rtc.conf
Note: Please set CANDIDATE as the ip of server, please read CANDIDATE.
Play the stream in browser:
- Publish by WebRTC:webrtc://localhost/live/show
- Play by WebRTC:webrtc://localhost/live/show
Remark: Note that if not localhost, the WebRTC publisher should be HTTPS page.
Please use conf/rtc2rtmp.conf
as config.
export CANDIDATE="192.168.1.10"
docker run --rm --env CANDIDATE=$CANDIDATE \
-p 1935:1935 -p 8080:8080 -p 1985:1985 -p 8000:8000/udp \
ossrs/srs:4 \
objs/srs -c conf/rtc2rtmp.conf
Note: Please set CANDIDATE as the ip of server, please read CANDIDATE.
The streams:
- Publish by WebRTC:webrtc://localhost/live/show
- Play by WebRTC:webrtc://localhost/live/show
- HTTP-FLV:http://localhost:8080/live/show.flv
- RTMP by VLC:rtmp://localhost/live/show
Please use conf/rtc.conf
as config.
export CANDIDATE="192.168.1.10"
docker run --rm --env CANDIDATE=$CANDIDATE \
-p 1935:1935 -p 8080:8080 -p 1985:1985 -p 8000:8000/udp \
ossrs/srs:4 \
objs/srs -c conf/rtc.conf
Note: Please set CANDIDATE as the ip of server, please read CANDIDATE.
Then startup the signaling, please read usage:
docker run --rm -p 1989:1989 ossrs/signaling:1
Use HTTPS proxy httpx-static as api gateway:
export CANDIDATE="192.168.1.10"
docker run --rm -p 80:80 -p 443:443 ossrs/httpx:1 \
./bin/httpx-static -http 80 -https 443 -ssk ./etc/server.key -ssc ./etc/server.crt \
-proxy http://$CANDIDATE:1989/sig -proxy http://$CANDIDATE:1985/rtc \
-proxy http://$CANDIDATE:8080/
To open http://localhost/demos/one2one.html?autostart=true
Or by the IP https://192.168.3.6/demos/one2one.html?autostart=true
Note: For self-sign certificate, please type
thisisunsafe
to accept it.
Please follow SFU: One to One, and open the bellow demo pages.
To open http://localhost/demos/room.html?autostart=true
Or by the IP https://192.168.3.6/demos/room.html?autostart=true
Note: For self-sign certificate, please type
thisisunsafe
to accept it.
Please follow SFU: One to One, and please convert RTC to RTMP, for FFmpeg to mix the streams.
export CANDIDATE="192.168.1.10"
docker run --rm --env CANDIDATE=$CANDIDATE \
-p 1935:1935 -p 8080:8080 -p 1985:1985 -p 8000:8000/udp \
ossrs/srs:4 \
objs/srs -c conf/rtc2rtmp.conf
If use FFmpeg to mix streams, there is a FFmpeg CLI on the demo page, for example:
ffmpeg -f flv -i rtmp://192.168.3.6/live/alice -f flv -i rtmp://192.168.3.6/live/314d0336 \
-filter_complex "[1:v]scale=w=96:h=72[ckout];[0:v][ckout]overlay=x=W-w-10:y=H-h-10[out]" -map "[out]" \
-c:v libx264 -profile:v high -preset medium \
-filter_complex amix -c:a aac \
-f flv rtmp://192.168.3.6/live/merge
Input:
- rtmp://192.168.3.6/live/alice
- rtmp://192.168.3.6/live/314d0336
Output:
- rtmp://192.168.3.6/live/merge
Winlin 2020.02
Welcome to SRS wiki!
Please select your language:
Please select your language:
Please select your language:
Please select your language:
Please select your language: