Monday, September 17, 2012

New exec features

I've improved exec support in nginx-rtmp. Several new directives were added:

  • exec_publish - run external program on publish event

  • exec_play - run external program on play event

  • exec_publish_done - run external program when publisher closes stream

  • exec_play_done - run external program when player closes

  • exec_record_done - run external program when recording has finished

Previously implemented exec command is supported as well. The difference is old plain exec keeps external program running during all publishing period. It supports program restart. This behavior convenient for online transcoding with ffmpeg. The new features are pure notifiers. Unlike on_publish and on_play program result code is not used.

All (old & new) execs support the following variables:

  • app - application name

  • name - stream name

  • addr - client address

  • flashver - client flash version

  • pageurl - client page url

  • swfurl - client swf url

  • tcurl - client tc url

  • path - recorded file path (only for exec_record_done)

application foo {
live on;

# register all publishers in text file
exec_publish bash -c "echo $addr $app $name >> /var/publishers"

# register all players too
exec_play bash -c "echo $addr $app $name $pageurl $swfurl >> /var/players"

# make previews
recorder preview {
record keyframes;
record_max_frames 4;
record_path /var/rec;
record_interval 30s;

exec_record_done ffmpeg -i $path -vcodec png -vframes 1 -an -f rawvideo -s 320x240 -ss 00:00:01 -y $path.png;

Go to nginx-rtmp project page


  1. Nice additions! Is there any information on RTMP / AMF callbacks? Like, when Flash connects to an nginx-rtmp application and does this in the 'Live' manner. Then, if someone wants to start recording a callback on the NetConnection with a command like 'startRecord' could start the FLV writing, and cause a callback like 'recordStarted' back to the Flash app. A matching stopRecord with recordStopped feedback would be nice aswell. That way, from the webpage, a user can have a live stream running and at some points decide to capture it to a server. Or is this something that needs to be added as a plugin to this module...

  2. You're right. These callbacks should be implemented in plugins.

  3. You could if you want of course, add lua scripting support and make everyone happy and profit :D.
    Congratulations on all your hard and demanding work!

  4. I think I could but I don't see if it makes any sense. There's no output in handler unlike http case.