Browser No plug-in playback RTSP stream solution

1. Install FFmpeg

Refer to Installing FFmpeg under CentOS, especially for details.

The error I encountered and the solution:

  • Missing lame ffmpeg+libmp3lame library source code installation tutorial (CentOS)
  • make ffmpeg Times acc related , The version is too high, and the low version is installed.
    After FFmpeg is installed and configured under Linux, some problems in use
  • make times report if(x264_bit_depth>8) error, reinstall The new version of ffmpeg has a small error in the compilation of ffmpeg with x264
  • After installing the new version of FFmpeg, remove the ./configure parameter –enable-libnut
  • < p>If pkg-config is missing, you need to install Linux CentOS. Install pkg-config

  • The compiled library needs to add environment variables, otherwise ffmpeg cannot be opened, and the library is compiled with the default address In /usr/local/lib. Use of export LD_LIBRARY_PATH

2. Install NGINX (with rtmp module)

Installation and configuration reference Notes on building a streaming media server with nginx+nginx-rtmp-module+ffmpeg (1).

/usr/sbin/nginx is docker nginx
/usr/local/nginx/sbin/nginx is the newly installed nginx p>

Use the blogger’s command after completion:

ffmpeg -i rtsp://admin:[emailprotected]:9204 -rtsp_transport tcp -acodec aac -strict experimental -ar 44100 -ac 2 -b:a 96k -r 25 -b:v 500k -s 640*480 -f flv rtmp://127.0.0.1:1935/myapp/test1

Failed to start . Error UDP timeout, retrying with TCP [rtsp @ 0x1431700] method PAUSE failed: 551 Option not supported. UDP reading timeout, add -rtsp_transport tcp to force the use of tcp to read the rtsp stream https://github.com/datarhei/restreamer/issues /3.

Command: ffmpeg -rtsp_transport tcp -i rtsp://admin:[email protected]:9204 -c copy -f flv rtmp://127.0.0.1:1935/myapp/test1< /code> After successful operation, you can see the rtmp stream through the external network address rtmp://118.1.2.3:1935/myapp/test1. (The external network port needs to be opened for access)

3. Transforming hls

Refer to the use of nginx+nginx-rtmp-module+ffmpeg to build a streaming media server notes ( Two), modify the nginx configuration to direct the rtmp stream to the file.

Use the ffmpeg command: ffmpeg -rtsp_transport tcp -i rtsp://admin:[emailprotected]:9204 -vcodec copy -acodec copy -vbsf h264_mp4toannexb -f flv rtmp://127.0. 0.1:1935/hls/test2

http://118.1.2.3:81/hls/test2.m3u8 to view the stream.

4. Failed attempt: h5 play m3u8

https://www.zhihu.com/question/21087379 uses the videojs package Https://github.com/huangyaoxin/hLive is still very slow, and the browser has not opened. VLC is also particularly slow.

5. Try the solution through websocket

Originally planned to try

The browser plays rtsp Streaming media solution?

Convert rtsp to websocket and then use video tag to play, you can refer to mse technical solution
SpecForge/html5_rtsp_player

The attempt was unsuccessful and gave up.


Mistakenly hit by mistake, modify the nginx configuration, hls_fragment 1s; the page is no longer black and can be played.

I found out that chunk_size sets the segment size https://www.cnblogs.com/tinywan/p/6292357.html

Occasionally, it can be broadcasted and continue to use the websocket method.

Reference: html5 playing rtsp program, using jsmpeg, the server has only one js file websocket-relay.js (use node.js to transfer the mpeg data generated by ffmpeg to websocket service ); The client display uses a js jsmpeg.min.js and html view-stream.html file (js is used to open ws and draw the canvas to the page).

Final display effect+ie

1563514755542

Command: ffmpeg -rtsp_transport tcp -re -i rtsp://admin:[emailprotected]:9204 -q 0 -f mpegts -b 50 -r 20 -ss 3 -s 800/600- codec:v mpeg1video http://127.0.0.1:1936/1234 is still a bit stuck (please ignore the strange parameter settings inside, in order to transmit small data, just try some parameters randomly ), and there is no sound, but it proves that it is feasible to use websocket directly.

6. Optimize video transmission speed

Research the parameters of FFmpeg. It is to find the parameter that minimizes the transmitted data. FFmpeg Chinese document-actually translated the FFmpeg man manual.

Find the -q parameter, use a fixed quality (VBR), where the value of q is 0.01-255, the smaller The better the quality, when used to set -q 200, the video will be blurred immediately, but it can move every second. Set to -q 1 (bitrate=5800kbits/s each time, resulting in too slow transmission)

1563518050613

-q 50 The bit rate is 300+k

 1563518159717

It is necessary to find a balance point and give priority to the maximum definition (image quality). When -q 8, the size is 1000k/s, and the quality is acceptable. If it is stuck, it can be adjusted to -q 9, and the bit rate is maintained at 890k.

Record the current command:

ffmpeg -rtsp_transport tcp -re -i rtsp://admin:[emailprotected]:9204 -f mpegts -r 20 -q 9 -an -s 800/600 -codec:v mpeg1video http://127.0.0.1:1936/1234

where: -an prohibits audio (because the current No audio is needed, if needed), -r 20 frame rate, -s 800/600 screen size

7. Multi-channel video transmission

Refer to the RtspWebSocket of the author of the html5 playing rtsp program, and modify the js in (https://github.com/phoboslab/jsmpeg) to make more Each stream corresponds to multiple websocket services.

The final configuration and commands are as follows:

  • Node.js start: node websocket-relay.js 1234 1936 82 Monitor mpeg stream Port 1936, ws service port 82

  • Start ffmpeg in the background to convert the video format to mpeg to port 1936:

nohup ffmpeg -rtsp_transport tcp -re -i rtsp://admin:[emailprotected]:9201 -f mpegts -r 20 -q 15 -an -s 800/600 -codec:v mpeg1video http://127.0.0.1:1936 /1234/1 &

nohup ffmpeg -rtsp_transport tcp -re -i rtsp://admin:[emailprotected]:9204 -f mpegts -r 20 -q 15 -an -s 800/600 -codec:v mpeg1video http://127.0.0.1:1936/1234/4 &

Note: transfer to m3u8 does not require -rtsp_transport tcp parameter ffmpeg -re- i http://v.warcraft.com/openlive/1a4ccf5dc3af4dc7a3c400f953fad089.m3u8 -f mpegts -r 20 -q 15 -an -s 800/600 -codec:v mpeg1video http://127.0.0.1:1936/1234/5

  • Foreground view

Leave a Comment

Your email address will not be published.