Streaming workflow with Nginx
install Nginx and RTMP module
$ brew tap denji/homebrew-nginx
==> Tapping denji/nginx
Cloning into '/usr/local/Homebrew/Library/Taps/denji/homebrew-nginx'...
remote: Enumerating objects: 75, done.
remote: Counting objects: 100% (75/75), done.
remote: Compressing objects: 100% (74/74), done.
remote: Total 75 (delta 1), reused 29 (delta 1), pack-reused 0
Unpacking objects: 100% (75/75), done.
Tapped 64 formulae (169 files, 138.3KB).
$ brew install nginx-full --with-rtmp-module
==> Installing nginx-full from denji/nginx
==> Installing dependencies for denji/nginx/nginx-full: [email protected] and rtmp-nginx-module
==> Installing denji/nginx/nginx-full dependency: [email protected]
Check the install location.
$ brew info nginx-full
denji/nginx/nginx-full: stable 1.17.3, HEAD
HTTP(S) server, reverse proxy, IMAP/POP3 proxy server
https://nginx.org/
Conflicts with:
nginx (because nginx-full symlink with the name for compatibility with nginx)
/usr/local/Cellar/nginx-full/1.17.3 (8 files, 1.2MB) *
Built from source on 2019-08-24 at 15:24:26 with: --with-rtmp-module
--HEAD
Install HEAD version
==> Caveats
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
- Tips -
Run port 80:
$ sudo chown root:wheel /usr/local/opt/nginx-full/bin/nginx
$ sudo chmod u+s /usr/local/opt/nginx-full/bin/nginx
- install location is
/usr/local/opt/nginx-full/bin/nginx
- config file in
/usr/local/etc/nginx/nginx.conf
- server root is
/usr/local/var/www
- default port is 8080
Commands:
$ nginx -s reload # Reload config
$ nginx -s reopen # Reopen Logfile
$ nginx -s stop # Stop process
$ nginx -s quit # Waiting on exit process
start nginx server
$nginx
Open http://localhost:8080 in browser.
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
config the RTMP
$ cd /usr/local/etc/nginx/
$ vim nginx.conf
Add the RTMP configuration.
http {
...
}
rtmp {
server {
listen 1935; # default port
application live {
live on;
record off;
}
}
}
record and push to nginx server
$ ffmpeg -f avfoundation -framerate 30 -i "0" -vcodec libx264 -preset ultrafast -acodec libfaac -f flv rtmp://localhost:1935/live/room
Abobe command will have below warning.
[flv @ 0x7ff5e907fa00] Failed to update header with correct duration.926.8kbits/s speed=1.01x
[flv @ 0x7ff5e907fa00] Failed to update header with correct filesize.
playback
$ ffplay -v debug rtmp://localhost:1935/live/room
pixel format is not supported
[avfoundation @ 0x7fa0db800000] Selected pixel format (yuv420p) is not supported by the input device.
[avfoundation @ 0x7fa0db800000] Supported pixel formats:
[avfoundation @ 0x7fa0db800000] uyvy422
[avfoundation @ 0x7fa0db800000] yuyv422
[avfoundation @ 0x7fa0db800000] nv12
[avfoundation @ 0x7fa0db800000] 0rgb
[avfoundation @ 0x7fa0db800000] bgr0
[avfoundation @ 0x7fa0db800000] Overriding selected pixel format to use uyvy422 instead.
Ignore this warning or specific the pixel format with -pixel_format
command.