Build Live Video Streaming Server using ffmpeg Nginx Rtmp Module & Nodejs
[Video Coming soon] In this tutorial series i will use Ffmpeg, Nginx + Nginx-rtmp-module + Nodejs create live streaming service allow user connect their camera to their account and display live video on user’s dashboard.
Features
- Live Stream, save recording file for watch later.
- Each user has one or many cameras with many live stream secret key. Allow Camera devices send video for streaming.
- View camera private , or share their camera , such as public street camera.
- Target devices: Raspberry pi zero w, Raspberry pi 3 with camera module (will use in this tutorial series), or other cameras, screen streaming
- Web app(Mobile App) use React for Front-End, Nodejs for backend api restful service + Realtime use WebSocket (Uws), and user stream service key.
Software requirements
- Ffmpeg: http://ffmpeg.org
- Nginx: http://nginx.org
- Nginx-rtmp-module https://github.com/arut/nginx-rtmp-module
- Nodejs: http://nodejs.org
- Reactjs: http://reactjs.org
- Player: hls.js https://github.com/video-dev/hls.js
- MongoDB http://mongodb.org/
Setup Nginx + Nginx-rtmp-module on MacOs
- Command: brew tap homebrew/nginx
- Command: brew options nginx-full
- Command: brew info nginx-full
- Command: brew install nginx-full — with-rtmp-module — with-debug
Setup FFMPEG on MacOs
- Option 1: downlpoad package: https://www.ffmpeg.org/download.html
- Option 2: use homebrew on Mac: https://trac.ffmpeg.org/wiki/CompilationGuide/macOS
- Use Brew to install brew install ffmpeg
- Or brew info ffmpeg: brew install ffmpeg \
— with-tools \
— with-fdk-aac \
— with-freetype \
— with-fontconfig \
— with-libass \
— with-libvorbis \
— with-libvpx \
— with-opus \
— with-x265 - Update FFMPEG: brew update && brew upgrade ffmpeg
- Input output devices list: https://www.ffmpeg.org/ffmpeg-devices.html on Mac os: ffmpeg -f avfoundation -list_devices true -i “”
- Sample stream camera on mac to server: ffmpeg -f avfoundation -r 30 -i “0:0” -deinterlace -vcodec libx264 -pix_fmt yuv420p -preset medium -g 60 -b:v 2500k -acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b:a 712000 -bufsize 512k -f flv rtmp://localhost/live/tabvn
- Stream from a file to server: ffmpeg -re -i video.mkv -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmp://localhost/live/tabvn
Sample Nginx Config
Next Part: Setup Nginx ,Nginx-Rtmp-Module & Ffmpeg Build Live Video Streaming Server
Documents: https://docs.google.com/document/d/1SnoTl9RlUMWn7MC-9k-nCK1myWYspzbPfL29hPpgwPE