• 1 RTMP push flow
    • 1.1 obs
      • 1.1.1 OBS Capture Camera
    • 1.2 ffmpeg
      • 1.2.1 FFMPEG reads file push
  • 2 RTSP stream
    • 2.1 ffmpeg
      • 2.1.1 FFMPEG reads files and pushes streams
  • 3 RTMP flow
    • 3.1 VLC
    • 3.2 ffmpeg
      • 3.2.1 FFMPEG Pull flow save files
    • 3.3 ffplay
    • 3.4 MPV
    • 3.5 RTMP Playback Page provided by SRS (Based on Adobe Flash technology)
  • 4 http-flvandhttps-flvPull flow
  • 5 HLS(m3u8+ts)Pull flow
    • 5.1 Safari
    • 5.2 VLC, FFMPEG, FFplay
  • 6 http-tsPull flow
  • 7 RTSP stream
  • 8 Test file download

(Use of other clients and other streaming protocol formats will be added later.)

Examples of stream addresses:

agreement address Protocol Default port
The RTMP push flow RTMP: / / 127.0.0.1:1935 / live/test110 1935
Push RTSP stream rtsp://localhost:5544/live/test110 554
RTMP pull flow RTMP: / / 127.0.0.1:1935 / live/test110 1935
HTTP – FLV flow http://127.0.0.1:8080/live/test110.flv 80
HTTPS – FLV flow https://127.0.0.1:4433/live/test110.flv 443
HTTP – ts stream http://127.0.0.1:8082/live/test110.ts 80
RTSP pull flow rtsp://localhost:5544/live/test110 554
HLS(M3U8 + TS) Live pull stream http://127.0.0.1:8081/hls/test110/playlist.m3u8 80
HLS(M3U8 + TS) Recording playback http://127.0.0.1:8081/hls/test110/record.m3u8 80

Note that if you use the default port, the address can be omitted in the port, such as http://127.0.0.1:8080/live/test110.flv into http://127.0.0.1/live/test110.flv

1 RTMP push flow

1.1 obs

Download the binary installation package of the operating system from obsproject.com/ and install it.

This article uses obS 25.0.8 for MacOS as the demo, as well as obS versions for other systems.

1.1.1 OBS Capture Camera
  1. Open OBS and click the Settings button in the lower right corner
  2. In the window that pops up, click the push flow button on the left
  3. The push flow details page appears on the right:
    • Leave the service drop-down box alone, keep it custom…
    • The serverEnter a value in the input boxRTMP: / / 127.0.0.1:1935 / live
    • Streaming keyEnter a value in the input boxtest110
      • Tips, by default, the stream key does not display the input characters in clear text. If you are afraid of output, you can click the display button on the right
  4. Click the confirm button in the lower right corner to complete the setting
  5. Go back to the main screen and click on the lower right corner to start streaming
  6. The status bar at the bottom showsLIVE, FPS, KB /s, indicating the stream pushing duration, frame rate and bit rate respectively, indicating that the stream pushing is successful

Obs not only collects the camera as the input stream, but also collects desktop, audio and video files. It also provides many parameters that can be configured on a graphical interface.

1.2 ffmpeg

1.2.1 FFMPEG reads file push

(See how to install FFMPEG at the end of the article)

If the audio in the FLV or MP4 file is in AAC format and the video is in H264 or H265 format, then ffMPEG does not need to re-encode the audio and video.

$Ffmpeg - re - stream_loop - 1 - I demo. FLV - c: a copy - c: v copy - f FLV RTMP: / / 127.0.0.1:1935 / live/test110
Copy the code

Some description of the parameters:

  • -reIt is pushed according to the bit rate of the mid-tone video stream of the file. If it is not added, the transmission speed is not controlled and the transmission speed is sent to the server at one time, which does not meet the characteristics of live broadcast
  • -stream_loop -1Represents the number of times that the file continues to be pushed through the file header after the file ends.- 1For infinite loop
  • -iRepresents the input file
  • -c:a copyIndicates that the audio encoding format is unchanged
  • -c:v copyIndicates that the video encoding format remains unchanged
  • -f flvThe push RTMP stream needs to be in the formatflv
  • Finally, the RTMP stream address

For an MP4 file, change demo. FLV to the mp4 file name, such as demo.mp4

The above is a more common situation.

In another case, the audio and video encoding format in the file is not supported by the streaming media server, then FFMPEG needs to be re-encoded:

$Ffmpeg - re - I demo. FLV - c: a aac - c: v h264 -f FLV RTMP: / / 127.0.0.1:1935 / live/test110
Copy the code

In the command, -c:a aAC indicates that audio is encoded using AAC, and -c:v h264 indicates that video is encoded using H264.

2 RTSP stream

2.2 ffmpeg

2.2.1 FFMPEG reads file push
ffmpeg -re -stream_loop -1 -i demo.flv -acodec copy -vcodec copy -f rtsp rtsp://localhost:5544/live/test110
Copy the code

In addition, RTSP also supports RTP over TCP to push streams. The corresponding ffmpeg command is as follows:

ffmpeg -re -stream_loop -1 -i demo.flv -acodec copy -vcodec copy -rtsp_transport tcp -f rtsp rtsp://localhost:5544/live/test110
Copy the code

For the meanings of parameters, see 1.2.1

3 RTMP flow

Original is not easy to reproduce, please indicate the article from the open source streaming media server Lal, Github: github.com/q191201771/… Official document: pengrl.com/lal

3.1 VLC

Download the binary installation package of the corresponding OPERATING system from www.videolan.org/vlc/ and install it.

This article uses VLC 3.0.8 for MacOS as the demo, other systems and OBS versions are similar.

  1. Open the VLC
  2. Click File on the bottom menu bar and then Open Network…
  3. In the popup windowURLEnter in the input boxRTMP: / / 127.0.0.1:1935 / live/test110
  4. Click the confirm button in the lower right corner to complete the setting
  5. The live stream starts

3.2 ffmpeg

3.2.1 FFMPEG Pull flow save files

How to install FFMPEG see end of article

$Ffmpeg -i RTMP: / / 127.0.0.1:1935 / live/test110 - c copy test110. FLV
Copy the code

3.3 ffplay

Ffplay is a player that comes with ffMPEG projects

$Ffplay RTMP: / / 127.0.0.1:1935 / live/test110
Copy the code

3.4 MPV

Download binary installation package, install, and then input pull stream address play, basically and VLC, refer to 2.1 VLC

3.5 RTMP Playback Page provided by SRS (Based on Adobe Flash technology)

Open the RTMP playback page provided by SRS:

http://ossrs.net/players/srs_player.html?app=live&stream=livestream&server=r.ossrs.net&port=1935&autostart=true&vhost=r. ossrs.netCopy the code

Fill the URL input box with the RTMP pull flow address and click the Play video button

4 http-flvandhttps-flvPull flow

Http-flv pull streams, for VLC, FFMPEG, FFplay, MPV, are the same as pull RTMP streams, The flow from the RTMP URL: / / 127.0.0.1:1935 / live/test110 to http://127.0.0.1:8080/live/test110.flv.

HTTPS – FLV is the same as HTTP-FLV.

5 HLS(m3u8+ts)Pull flow

5.1 Safari

Open safari, in address line input HLS flow at http://127.0.0.1:8081/hls/test110/playlist.m3u8.

5.2 VLC, FFMPEG, FFplay

HLS(m3U8 + TS) pull stream, for VLC, FFMPEG, FFplay, is the same as pull RTMP stream, The flow from the RTMP URL: / / 127.0.0.1:1935 / live/test110 to http://127.0.0.1:8081/hls/test110/playlist.m3u8.

6 http-tsPull flow

Http-ts pull streams, for VLC, FFMPEG, FFplay, MPV, are the same as pull RTMP streams, The flow from the RTMP URL: / / 127.0.0.1:1935 / live/test110 to http://127.0.0.1:8082/live/test110.ts.

7 RTSP stream

$ffplay rtsp://localhost:5544/live/test110
$ffmpeg -i rtsp://localhost:5544/live/test110 -vcodec copy -acodec copy -f flv /tmp/test110.flv
$ffmpeg -rtsp_transport tcp -i rtsp://localhost:5544/live/test110 -vcodec copy -acodec copy -f flv /tmp/test110.flv
Copy the code

8 Test Files

Test file download address:

Github.com/q191201771/…

Test file conversion generation command:

$ffmPEG-i wontcry. Mp4-acodec aAC-vcodec h264-r 15-g 30-keyint_min 30-bf 0 FLV wontcry. FLV # -r 15fps FPS, Represents the size of 1 second encoding 15 frames # -g 30 GOP, namely I frame interval, 1 I frame for every 30 frames, That is, 1 I frame in 2 seconds # -keyint_min 30 Minimum GOP size # -bf 0 Do not use B frame encoding # -acodec AAC output file audio encoding use AAC # -vCOdec H264 Output file video encoding use H264 # -i FLV $ffmpeg -I wontcry. FLV -acodec copy -vcodec copy -t 30 -f FLV Wontcry30s. FLV # -t $ffmpeg-i wontcry30s. FLV -acodec aac -vcodec hevc-r 15-g 30-keyint_min 30-bf 0 - Preset ultrafast - X265-params "bframes=0" -f FLV hevc. FLV # Preset to ultrafast - X265-Params "bframes=0" -f FLV hevcCopy the code

Ffmpeg installation

  • Linux install ffmpeg
  • MacOS compiles Jinshan Cloud KSVC FFMPEG and supports HEVC H265 on top of RTMP FLV
  • MacOS compiles the player ffplay in FFMPEG
  • Ffmpeg compiled for macOS Catalina 10.15.1 does not run and crashes upon startup

Original is not easy to reproduce, please indicate the article from the open source streaming media server Lal, Github: github.com/q191201771/… Official document: pengrl.com/lal

yoko, 20210206