Background of 0.

SRS is a simple and efficient real-time video server that supports multiple formats such as RTMP/. SRS service is used for work, this article is my study notes in the process of learning.

1. Knowledge

To set up streaming media services, there are basically three steps:

  • 1. Start streaming media service (SRS)
  • 2, start push stream, that is, streaming media video, video and audio materials source
  • 3, play streaming media, that is, the client, through the player or browser to watch the video.

What does THE SRS streaming service do? A: Video input and distribution. That is, one hand receives the video stream, the other hand distributes the video stream to the client. Further from this, the transmission and decoding of video.

Example 2.

(1) to start the SRS

docker run --rm -p 1935:1935 -p 1985:1985 -p 8080:8080 ossrs/srs:3
Copy the code

(2) Start pushing the flow

The following example is a ffmpeg push flow example, push the flow after the url is RTMP: / / localhost/live/livestream

docker run --rm --network=host ossrs/srs:encoder ffmpeg -re -i ./doc/source.200kbps.768x320.flv \
  -c copy -f flv -y rtmp://localhost/live/livestream
Copy the code

Of course, you can also use OBS software to push streams, as described later in this article.

(3) Check the video

It can be played in two ways:

  • 1) Client mode, using VLC player, URL address is RTMP,
  • 2) Play FLV format movies in the browser.

VLC client plays

VLC is an open source streaming media player that can be downloaded from the Web.

Open VLC and enter the following stream address to play

rtmp://localhost/live/livestream
Copy the code

SRS can also be played in the browser to support Flv format playback. The url format: http://localhost:8080/live/livestream.flv

For example, I wrote a front-end demo using React, which uses flv.js to play Flv media streams. Code examples:

import React, { PureComponent } from 'react';
import Reflv from '@/Reflv/index';

export class MyDemo extends PureComponent {

  constructor(props) {
    super(props);
    this.state = {
        "Video_URL": 'http://localhost:8080/live/livestream.flv'
      }
  }

  componentDidMount() {
  }

  render() {
    return (
      <Reflv url={this.state.Video_URL} type="flv"/>
    )
  }
}
Copy the code

3. Use OBS software to push the stream

The previous section provided an example of pushing streams by file. Here is an example of pushing streams by OBS software. First you need an OBS software.

OBS streaming software: Free and open source software for video recording and live streaming.

Download obsproject.com/

Steps:

  • 1. Start SRS service: see above
  • 2. OBS push flow

(1) Add a video capture device

image.png

(2) Click Settings to configure a push stream address.

image.png

(3) Click “Start stream pushing” button to start stream pushing.

image.png

  • 3, play stream: add text

4. Some information

My Demo address: github.com/vir56k/demo…

The SRS’s brief introduction:

SRS is a simple and efficient real-time video server that supports RTMP/WebRTC/HLS/HTTP-FLV/SRT/GB28181.

  • Main address: ossrs.net/releases/
  • WIKI documentation: gitee.com/winlinvip/s…
  • Warehouse address: github.com/ossrs/srs/t…

4. Reference

Gitee.com/winlinvip/s…