Sunday, February 3, 2013

New static features in 0.9.5

Two new great features were merged into nginx-rtmp master on the weekend. The first is formerly announced static pull and the second is static exec.

Static pulls are pulls started at nginx startup. This makes it possible to generate HLS files without any dependence on rtmp clients currently playing the stream.

pull rtmp:// name=localstream static;

Static exec is a similar feature for running external programs at nginx startup. With this feature you can start streaming from an external source with ffmpeg.

exec_static ffmpeg -re -i /var/movies/movie.avi -c:v libx264
-c:a libmp3lame -ar 22050 -ac 1 -f flv rtmp://localhost/myapp/mystream;

The greatest thing that comes with static execs is the ability to receive data from webcam without running external scripts. Now it can all be done in nginx.conf.

exec_static ffmpeg -f video4linux2 -i /dev/video0 -c:v libx264
-an -f flv rtmp://localhost/myapp/mystream

The same applies to receiving stream from any remote source in any formats and codecs.

exec_static ffmpeg -i -c copy
-f flv rtmp://localhost/myapp/mystream

While static exec feature works perfectly on Linux it has certain limitations on FreeBSD. Because of missing prctl syscall or any substitution there's no simple way to make child process terminated automatically when parent gets killed. When a single nginx worker in multi-worker configuration is killed on FreeBSD it's still possible that a new exec child will be started even if the previously started child is still alive. If you use that on FreeBSD make sure you never kill a single nginx worker and always kill all.

No comments:

Post a Comment