paint-brush
Build Live Video Streaming Server using ffmpeg Nginx Rtmp Module & Nodejsby@tabvn
55,611 reads
55,611 reads

Build Live Video Streaming Server using ffmpeg Nginx Rtmp Module & Nodejs

by Toan Nguyen DinhDecember 13th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

[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.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Build Live Video Streaming Server using ffmpeg Nginx Rtmp Module & Nodejs
Toan Nguyen Dinh HackerNoon profile picture

[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

  1. Live Stream, save recording file for watch later.
  2. Each user has one or many cameras with many live stream secret key. Allow Camera devices send video for streaming.
  3. View camera private , or share their camera , such as public street camera.
  4. Target devices: Raspberry pi zero w, Raspberry pi 3 with camera module (will use in this tutorial series), or other cameras, screen streaming
  5. 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

  1. Ffmpeg: http://ffmpeg.org
  2. Nginx: http://nginx.org
  3. Nginx-rtmp-module https://github.com/arut/nginx-rtmp-module
  4. Nodejs: http://nodejs.org
  5. Reactjs: http://reactjs.org
  6. Player: hls.js https://github.com/video-dev/hls.js
  7. MongoDB http://mongodb.org/

Setup Nginx + Nginx-rtmp-module on MacOs

  1. Command: brew tap homebrew/nginx
  2. Command: brew options nginx-full
  3. Command: brew info nginx-full
  4. Command: brew install nginx-full — with-rtmp-module — with-debug

Setup FFMPEG on MacOs

  1. Option 1: downlpoad package: https://www.ffmpeg.org/download.html
  2. Option 2: use homebrew on Mac: https://trac.ffmpeg.org/wiki/CompilationGuide/macOS
  3. Use Brew to install brew install ffmpeg









  4. 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

  5. Update FFMPEG: brew update && brew upgrade ffmpeg
  6. Input output devices list: https://www.ffmpeg.org/ffmpeg-devices.html on Mac os: ffmpeg -f avfoundation -list_devices true -i “”
  7. 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
  8. 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

Video: https://www.youtube.com/watch?v=OS6ZAlCZvGs