To prepare software
Linux
- Docker
- nginx-rtmp
Windows
- OBS
- PotPlayer
Docker nginx-rtmp is an image that encapsulates nginx-rtmp-module and FFmPEG
Hub.docker.com/r/alfg/ngin…
Set up a streaming media server
Write the docker – compose. Yml
version: '3.1'
services:
nginx-rtmp-test:
restart: always
image: alfg/nginx-rtmp
container_name: nginx-rtmp-test
ports:
- 1935: 1935
- 8080: 80
volumes:
- ./conf/nginx.conf:/etc/nginx/nginx.conf
- ./html:/usr/share/nginx/html
- ./log:/var/log/nginx
Copy the code
Write nginx. Conf
# user specifies the user and group to run nginx (the first parameter is the user and the second parameter is the group, only the user). # worker_processes 1 worker_processes 1 # set the maximum number of worker_connections to 1024; } #RTMP service (key) RTMP {server{#RTMP service port listen 1935; # // the default port for RTMP is chunk_size 4000; Application HLS {# HLS = live on; # // Open live stream HLS on; // open HLS hls_path/TMP/HLS; The types {} module maps the file extension to the response MIME type include mime.types; Default_type application/octet-stream; # enable/disable sendFile () sendFile on # 65s timeout keepalive_timeout 65; # etag etag on; # expires 7D; Server {# listen 8080; Localhost server_name localhost; location /hls { # Serve HLS fragments types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root /tmp; add_header Cache-Control no-cache; }}}Copy the code
Start the Nginx streaming server
docker-compose up -d
Copy the code
Checking startup Status
netstat -ntpl | grep 1935
Copy the code
Push streams with OBS (RTMP streams)
Open the Settings
Add the push stream address to the Settings
Service: Select Custom
Server: RTMP :// own server IP :1935/stream
Stream key: fill it in, equivalent to room number
Adding a Media Source
Began pushing flow
Using player pull streams (RTMP streams)
Here you use the PotPlayer to pull the video
Set the pull flow address
Pull flow address format: http://localhost:8080/live/$STREAM_NAME.m3u8
So we pull flow address: 47, XXX, XXX. 62:8080 / live/alanle…
Video can also be played using the RTMP protocol address
The format of the pull flow address is http://localhost:1935/$STREAM_NAME
So we pull flow address: 47, XXX, XXX. 62:1935 / alanlee
Play the video
After setting up the streaming address, the video can play in a few seconds.
You can also play videos from this page
www.ossrs.net/players/srs…
The process of setting up live streaming media server has been completed here. The following is an alternative to pushing the HLS stream.
Push stream with OBS (HLS stream)
This is done using RTMP. In nginx configuration, we also configured HLS for streaming. The push stream mode is basically the same as RTMP mode, except that the push stream address is slightly changed.
Add the push stream address to the Settings
Service: Select Custom
Server: RTMP :// Own server IP :1935/ HLS
Stream key: fill it in, equivalent to room number
Once set up, start pushing the stream
Using player pull stream (HLS stream)
Set the pull flow address
Play the video
After setting up the streaming address, the video can play in a few seconds.