Home > AI > Server > Nginx >

nginx + ffmpeg for a livestreaming server

This example is to push a premade a video to the server and watch it from another terminal
push: terminal + premaid video
watch: terminal

System: Mac / Nginx / Homebrew / ffmpeg

Step 1: set up nginx server

  1. install rtmp module
# https://github.com/denji/homebrew-nginx

brew tap denji/homebrew-nginx

brew install nginx-full --with-rtmp-module

brew unlink nginx
brew link nginx-full

2. setup nginx.config

/usr/local/etc/nginx/nginx.conf

http {
   ...
}


rtmp {
    server {
        listen 1935;


        application rtmpapp {
            live on;
            max_connections 1024;
        }

        application hls {
            live on;
            hls on;
            hls_path /Users/dph/documents/work-web-rtmp;
            hls_fragment 1s;
        }
    }
}

3. test nginx

nginx -t # test config syntax
# restart machine 
nginx
netstat -ant | grep 8080 # check port

Step 2: push and watch

  1. push stream

If ffmpeg is not installed, you can use brew install ffmpeg

ffmpeg -re -i test.mov -vcodec copy -acodec copy -f flv rtmp://localhost/rtmpapp/room

2. play

ffplay rtmp://localhost/rtmpapp/room

If you can see the video, this means the chain is working.

About push and watch, we have other demands, such as

push: website + realtime
watch: website + realtime

push: website + realtime
watch: phone + realtime

push: phone + realtime
watch: phone + realtime

The point is rtmp server address.

Leave a Reply