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

Written by tabvn | Published 2017/12/13
Tech Story Tags: docker | nodejs | nginx | nginx-rtmp | live-stream-server

TLDRvia the TL;DR App

[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


Published by HackerNoon on 2017/12/13