RTSP Wasm Player

RTSP Wasm Player

Overview

# RTSP WebSocket Proxy
RTSP/Webcam/File > FFmpeg open > Packets > WebSocket

# WS Wasm Player
WebSocket > Packets > Wasm FFmpeg decode to YUV > WebGL display
                                                > Wasm OpenGL display

# WS Local Player
WebSocket > Packets > FFmpeg decode to YUV > OpenGL display

# RTSP Local Player
RTSP/Webcam/File > FFmpeg open and decode to BGR/YUV > OpenCV/OpenGL display

Usage

Prerequisites

  • Ubuntu 18.04

Install develop tools

sudo apt install -y build-essential git wget yasm

# cmake: https://cmake.org/download/
export PATH=./cmake-3.21.1-linux-x86_64/bin:$PATH

Prepare third-party dependencies

  • Boost.Beast: HTTP for stream infos (CORS supported), WebSocket for stream packets.
  • FFmpeg: RTSP/Webcam/File open, decode (h264/hevc/rawvideo), scale and bsf (bitstream filter) for annexb format.
  • glog: logging. It can also enable macro UTIL_LOGGER_ENABLE to use stdout instead.
  • glfw, glew, glm: OpenGL render, yuv420p to rgb888.
  • jbeder/yaml-cpp: read/write config file.
  • nlohmann/json: parse/stringify http json.
git clone https://github.com/ikuokuo/rtsp-wasm-player.git
cd rtsp-wasm-player
export MY_ROOT=`pwd`

# boost: https://www.boost.org/
#  Beast: https://github.com/boostorg/beast
wget -p $MY_ROOT/3rdparty/ https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.bz2
cd $MY_ROOT/3rdparty/
tar --bzip2 -xf boost_1_76_0.tar.bz2
cd $MY_ROOT/3rdparty/boost_1_76_0/
./bootstrap.sh --prefix=$MY_ROOT/3rdparty/boost-1.76 --with-libraries=coroutine
./b2 install
cd $MY_ROOT/3rdparty/
ln -s boost-1.76 $MY_ROOT/3rdparty/boost

# ffmpeg: https://ffmpeg.org/
git clone --depth 1 -b n4.4 https://git.ffmpeg.org/ffmpeg.git $MY_ROOT/3rdparty/source/ffmpeg
cd $MY_ROOT/3rdparty/source/ffmpeg
./configure --prefix=$MY_ROOT/3rdparty/ffmpeg-4.4 \
--enable-gpl --enable-version3 \
--disable-programs --disable-doc --disable-everything \
--enable-decoder=h264 --enable-parser=h264 \
--enable-decoder=hevc --enable-parser=hevc \
--enable-demuxer=rtsp \
--enable-demuxer=rawvideo --enable-decoder=rawvideo --enable-indev=v4l2 \
--enable-protocol=file
make -j`nproc`
make install
cd $MY_ROOT/3rdparty/
ln -s ffmpeg-4.4 $MY_ROOT/3rdparty/ffmpeg

# If wanna build ffmpeg with nvidia,
# NVIDIA Video Codec SDK
#  https://developer.nvidia.com/nvidia-video-codec-sdk
# NVIDIA FFmpeg Transcoding Guide
#  https://developer.nvidia.com/blog/nvidia-ffmpeg-transcoding-guide/
git clone --depth 1 -b n11.0.10.1 https://github.com/FFmpeg/nv-codec-headers.git $MY_ROOT/3rdparty/source/nv-codec-headers
cd $MY_ROOT/3rdparty/source/nv-codec-headers
sudo make install
cd $MY_ROOT/3rdparty/source/ffmpeg
./configure --prefix=$MY_ROOT/3rdparty/ffmpeg-4.4 \
...
--enable-cuda --enable-cuvid --enable-nvdec --enable-nvenc --enable-nonfree --enable-libnpp \
--extra-cflags=-I$CUDA_HOME/include --extra-ldflags=-L$CUDA_HOME/lib64 \
--enable-decoder=h264_cuvid --enable-decoder=hevc_cuvid \
--enable-encoder=h264_nvenc --enable-encoder=hevc_nvenc \
--enable-hwaccel=h264_nvdec --enable-hwaccel=hevc_nvdec \
--enable-bsf=h264_mp4toannexb --enable-bsf=hevc_mp4toannexb --enable-bsf=null
# For video filters (rtsp-ws-proxy): --enable-encoder, --enable-bsf
# For h264/hevc encoders:
#  sudo apt install libx264-dev libx265-dev -y
# --enable-libx264 --enable-libx265 \
# --enable-encoder=libx264 --enable-encoder=libx265 \

# glog: https://github.com/google/glog
git clone --depth 1 -b v0.5.0 https://github.com/google/glog.git $MY_ROOT/3rdparty/source/glog
cd $MY_ROOT/3rdparty/source/glog
mkdir _build; cd _build
cmake -DCMAKE_INSTALL_PREFIX=$MY_ROOT/3rdparty/glog-0.5 ..
cmake --build . --target install --config Release -- -j`nproc`
cd $MY_ROOT/3rdparty/
ln -s glog-0.5 $MY_ROOT/3rdparty/glog

# glew, glfw3
sudo apt install -y libglew-dev libglfw3-dev
# glm
git clone --depth 1 -b 0.9.9.8 https://github.com/g-truc/glm.git $MY_ROOT/3rdparty/glm

# jbeder/yaml-cpp: https://github.com/jbeder/yaml-cpp
git clone --depth 1 -b yaml-cpp-0.7.0 https://github.com/jbeder/yaml-cpp.git $MY_ROOT/3rdparty/source/yaml-cpp
cd $MY_ROOT/3rdparty/source/yaml-cpp
mkdir _build; cd _build
cmake -DCMAKE_INSTALL_PREFIX=$MY_ROOT/3rdparty/yaml-cpp-0.7.0 -DYAML_CPP_BUILD_TESTS=OFF ..
cmake --build . --target install --config Release -- -j`nproc`
cd $MY_ROOT/3rdparty/
ln -s yaml-cpp-0.7.0 $MY_ROOT/3rdparty/yaml-cpp

# nlohmann/json: https://github.com/nlohmann/json
git clone --depth 1 -b v3.10.0 https://github.com/nlohmann/json.git $MY_ROOT/3rdparty/json

Rebuild wasm libraries

If wanna rebuild wasm libraries in ws-wasm-player, install Emscripten first:

# Get the emsdk repo
git clone --depth 1 https://github.com/emscripten-core/emsdk.git
# Enter that directory
cd emsdk
# Fetch the latest version of the emsdk (not needed the first time you clone)
git pull
# Download and install the latest SDK tools.
./emsdk install latest
# Make the "latest" SDK "active" for the current user. (writes .emscripten file)
./emsdk activate latest
# Activate PATH and other environment variables in the current terminal
source ./emsdk_env.sh

Then:

cd rtsp-wasm-player
export MY_ROOT=`pwd`

cd $MY_ROOT/3rdparty/source/ffmpeg
emconfigure ./configure --prefix=$MY_ROOT/ws-wasm-player/dist/ffmpeg \
--cc=emcc --cxx=em++ --ar=emar --ranlib=emranlib --disable-stripping \
--enable-cross-compile --target-os=none --arch=x86_32 --cpu=generic \
--disable-x86asm --disable-inline-asm \
--enable-gpl --enable-version3 \
--disable-programs --disable-doc --disable-everything \
--enable-decoder=h264 --enable-parser=h264 \
--enable-decoder=hevc --enable-parser=hevc \
--enable-decoder=rawvideo \
--enable-bsf=h264_mp4toannexb --enable-bsf=hevc_mp4toannexb --enable-bsf=null
emmake make -j`nproc`
emmake make install

# emcc settings
#  https://emscripten.org/docs/tools_reference/emcc.html
#  https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
# emcc default options
#  INITIAL_MEMORY=104857600 (100M)
#  INITIAL_MEMORY=33554432 (32M): h264 1920x1080 will abort(OOM) directly
cd $MY_ROOT/ws-wasm-player
emcc -std=c++14 -Os -DNDEBUG -s WASM=1 -s USE_SDL=2 -v \
-s INITIAL_MEMORY=104857600 \
-I . -I .. -I dist/ffmpeg/include \
-I ../3rdparty/boost/include \
-I ../3rdparty/json/single_include \
-I ../3rdparty/glm \
-L dist/ffmpeg/lib \
-lavcodec -lavdevice -lavfilter -lavformat \
-lavutil -lpostproc -lswresample -lswscale \
-D UTIL_LOG_TAG=\"WASM\" \
-D UTIL_LOGGER_ENABLE \
src/main.cc ../common/media/*.cc \
--bind -o lib/decoder.js

# emcc pthreads
#  https://emscripten.org/docs/porting/pthreads.html
# if wanna use threads, you should:
#  1. rebuild the wasm libs with `-s USE_PTHREADS=1`
#  2. set decode_* options in ws-wasm-player/lib/ws_client.js
#  3. build rtsp-ws-proxy with ssl (recommended)
emcc -std=c++14 -Os -DNDEBUG -s WASM=1 -s USE_SDL=2 -v \
-s INITIAL_MEMORY=104857600 -s USE_PTHREADS=1 \
...

# emcc simd
#  https://emscripten.org/docs/porting/simd.html

# emcc debugging
#  https://emscripten.org/docs/debugging/Sanitizers.html
emcc -std=c++14 -g2 -s WASM=1 -s USE_SDL=2 -v \
-fsanitize=address -s ALLOW_MEMORY_GROWTH=1 \
...

Build

cd rtsp-wasm-player
# build all projects in rootdir
make
# clean in rootdir
make clean
# clean all, include subdirs
make cleanall

RTSP WebSocket Proxy

RTSP/Webcam/File > FFmpeg open > Packets > WebSocket

Build and run:

cd rtsp-ws-proxy

# build
make
# if wanna build with ssl (COOP need https, otherwise localhost only)
sudo apt install libssl-dev -y
make CMAKE_OPTIONS="-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=_install -DUSE_SSL=ON"

# run
./_output/bin/rtsp-ws-proxy ./config.yaml

WS Wasm Player

WebSocket > Packets > Wasm FFmpeg decode to YUV > WebGL display
                                                > Wasm OpenGL display

Run:

cd ws-wasm-player

# Method 1. serve by rtsp-ws-proxy if default config
# open http://127.0.0.1:8080 in browser
#  use https if build with ssl, don't forget to import SSL certificate:
#   1. create: https://stackoverflow.com/a/60516812
#   2. change: rtsp-ws-proxy/config.yaml server.http.ssl_*
#   3. import: chrome://settings/certificates

# Method 2. serve by python http server
python -m http.server 8000
#  if wanna response headers: COOP, COEP
python http_server.py 8000
# open http://127.0.0.1:8000 in browser

WS Local Player

WebSocket > Packets > FFmpeg decode to YUV > OpenGL display

Build and run:

cd ws-local-player

# build
make

# run
./_output/bin/ws-local-player ./config.yaml [stream_id]

RTSP Local Player

RTSP/Webcam/File > FFmpeg open and decode to BGR/YUV > OpenCV/OpenGL display

Build and run:

cd rtsp-local-player

# if wanna enable build with opencv
# export OpenCV_DIR=~/opencv-4/lib/cmake/opencv4

# build
make

# run
./_output/bin/rtsp-local-player_ogl ./cfg_rtsp.yaml
#  or
./_output/bin/rtsp-local-player_ocv ./cfg_webcam.yaml

相关文章

Similar Resources

Yakuza Arcade Machine Player - play Virtua Fighter 5: Final Showdown on PC, using Yakuza 6 files.

Yakuza Arcade Machine Player - play Virtua Fighter 5: Final Showdown on PC, using Yakuza 6 files.

Yakuza Arcade Machines Player Yakuza Arcade Machines Player is a launcher that allows you to run Virtua Fighter 5: Final Showdown, standalone and nati

Nov 26, 2022

A clone of Media Player Classic reimplemented in Qt.

A clone of Media Player Classic reimplemented in Qt.

Media Player Classic Qute Theater A clone of Media Player Classic reimplemented in Qt. Media Player Classic Home Cinema (mpc-hc) is considered by many

Nov 26, 2022

🤟Super fast H.264/H.265 FLV player

🤟Super fast H.264/H.265 FLV player

🤟Super fast H.264/H.265 FLV player

Nov 26, 2022

simple mp4 player based on rockchip rv1109 platform

mp4player RV1109平台上实现一个简单的 mp4 播放器,主要是本人使用的开发板QT无法播放mp4,应该是没有编译qst所致,因而想利用rockchip平台自有的 功能实现一个简单的播放器。 base目录包含一些基础框架实现,包含信号,线程,时间等,线程和消息泵的实现非常非常简单,因而不

Jul 17, 2022

Implement a universal video player based on FFmpeg

qiaopcmusic 实现一个万能视频播放器 添加依赖方式: To get a Git project into your build: Step 1. Add the JitPack repository to your build file Add it in your root build.

Oct 15, 2021

FFmpeg powered audio player in node.js

sange FFmpeg powered audio player in node.js prerequisites node.js cmake sudo apt install cmake c++ compiler sudo apt install g++ gcc ffmpeg sudo apt

Nov 25, 2022

Poppy Music Player

Poppy Music Player poppy is a simple music player that is controlled by process signals. Build Before anything: meson setup build cd build Compiling n

Apr 26, 2022

Kodi is an award-winning free and open source software media player and entertainment hub for digital media

Kodi is an award-winning free and open source software media player and entertainment hub for digital media

website • docs • community • add-ons Welcome to Kodi Home Theater Software! Kodi is an award-winning free and open source software media player and en

Dec 1, 2022

Free and open-source media player written in C++

Liquid Media Player Free and open-source media player written in C++. Currently in development. Build Guide Windows Install the MSYS2 Building Platfor

Sep 20, 2022
OvenMediaEngine (OME) is a Streaming Server for Sub-Second Latency. It supports WebRTC, RTMP, SRT, MPEG-2 TS, RTSP as input, WebRTC, LL-DASH, MPEG-DASH, HLS as output.
OvenMediaEngine (OME) is a Streaming Server for Sub-Second Latency. It supports WebRTC, RTMP, SRT, MPEG-2 TS, RTSP as input, WebRTC, LL-DASH, MPEG-DASH, HLS as output.

OvenMediaEngine (OME) is a Streaming Server for Sub-Second Latency. It supports WebRTC, RTMP, SRT, MPEG-2 TS, RTSP as input, WebRTC, LL-DASH, MPEG-DASH, HLS as output.

Nov 24, 2022
Use rtsp protocol to push local H265 video encoding files

rtspServerH265 Use rtsp protocol to push local H265 video encoding files 项目介绍 C++11实现的RTSP服务器和推流器。主要完成对H265视频编码文件的RTSP推流 使用说明 1.编译并运行程序; 2.打开VLC软件,在媒体

Oct 12, 2022
theora-player is an embeddable theora video player C++ library based on the libtheora sample. It has no audio support at this moment.

theora-player Description theora-player is an embeddable theora video player C++ library based on the libtheora sample. It has no audio support at thi

Jun 18, 2022
🎥 mpv is a free (as in freedom) media player for the command line.
🎥 mpv is a free (as in freedom) media player for the command line.

mpv is a free (as in freedom) media player for the command line. It supports a wide variety of media file formats, audio and video codecs, and subtitle types.

Nov 25, 2022
An Open Source PSVita/TV MP4 player with 1080p playback and subtitle support
An Open Source PSVita/TV MP4 player with 1080p playback and subtitle support

Vita-Media-Player An Open Source PSVita/TV MP4 player with 1080p playback and subtitle support 1080i output supported on the PSTV natively and on the

Nov 25, 2022
Video player for 3ds
Video player for 3ds

Video player for 3DS Patch note v1.0.1 Added allow skip frames option v1.0.0 Initial release Summary Video player for 3DS Performance 256x144(144p)@30

Nov 21, 2022
TIP (translate it, please) is a plugin for VLC media player that helps you to study languages by watching videos.

vlc-tip-plugin TIP (translate it, please) is a plugin for VLC media player that helps you to study languages by watching videos. Features The plugin a

Oct 11, 2022
Jellyfin Desktop Client based on Plex Media Player
Jellyfin Desktop Client based on Plex Media Player

Desktop client using jellyfin-web with embedded MPV player. Supports Windows, Mac OS, and Linux. Media plays within the same window using the jellyfin-web interface unlike Jellyfin Desktop. Supports audio passthrough. Based on Plex Media Player.

Nov 30, 2022
A simple but powerful multimedia player library designed for Qt Quick.

QtMediaPlayer A simple but powerful multimedia player library designed for Qt Quick. Features Full-featured multimedia player Cross-platform: support

Nov 11, 2022
GB Studio Extended Nominal Player Adaptation/Interface
GB Studio Extended Nominal Player Adaptation/Interface

gbsenpai gbsenpai - GB Studio Extended Nominal Player Adaptation/Interface - is a project to port the GB Studio player to additional, non-GB/GBC platf

Oct 24, 2022