当前位置:网站首页>Playing RTSP streaming video on Web pages (webrtc)

Playing RTSP streaming video on Web pages (webrtc)

2022-06-26 06:08:00 Qi_ z

The environment required

node.js + FFmpeg

In this way, the client only needs to pass video Label can be played

ffmpeg download link :https://pan.baidu.com/s/1ntOVSpxmtHO861V-dT5Kyg?pwd=nx7y 
Extraction code :nx7y 

FFmpeg Environmental installation

1. install FFmpeg Dependence yasm

​yum Way to install yasm, It can also be done through Download - The Yasm Modular Assembler Project Download and install

yum install yasm -y

#  compile 
./configure

#  install 
make && make install

2. install FFmpeg

 wget obtain ffmpeg, It may not download , It is suggested to use the ffmpeg-4.1.8.tar.bz2 Manually upload to the server

wget https://ffmpeg.org/releases/ffmpeg-4.1.8.tar.bz2

#  decompression 
tar -xjvf ffmpeg-4.1.8.tar.bz2

#  Go to unzip directory 
cd ffmpeg-4.1.8

#  compile 
./configure

#  install 
make && make install

3. Verify that the installation was successful

Input ffmpeg command , Check whether the console has output , If yes, it means installation ffmpeg success .

NodeJS Environmental installation

1. NodeJS The installation steps for are ignored ..

2. install rtsp2web plug-in unit

#  Create a directory , Directory name cannot be rtsp2web, Enter the directory and execute the following command to install rtsp2web plug-in unit 
npm init --yes
npm i rtsp2web

3. establish  index.js, And run , Run the command node index.js

// index.js

const RTSP2web = require('rtsp2web')

//  The port number occupied by the long connection of the server ; The port number can be customized 
const port = 9999
new RTSP2web({
    port
})

At this point, the video transcoding service installation is complete .

Here we provide Open rtsp flow Available for testing :

rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4

verification html Play live video

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no,viewport-fit=cover">
  <script src="https://jsmpeg.com/jsmpeg.min.js" charset="utf-8"></script>
  <title> Play rtsp</title>
</head>
<body>
<canvas id="canvas" style="width: 600px; height: 600px;"></canvas>
</body>
<script>
        //  Change it to yours rtsp flow 
    var rtsp = 'rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4'
  window.onload = () => {
    // location by node The service address where the service is located , Port is rtsp2web Set the port 
    new JSMpeg.Player("ws://localhost:9999/rtsp?url="+btoa(rtsp), {
       canvas: document.getElementById("canvas")
    })
  }
</script>
</html>

Will be html copy Open it on the desktop to see the effect .

原网站

版权声明
本文为[Qi_ z]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260551185660.html