Archive for September, 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
    stream
  • 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

Advertisements

4 Comments

Multiple recorders in nginx-rtmp

One of recent updates brought multiple recorder support to nginx-rtmp. Before that only one recorder could be created with record directive.

Now recorder{} block is supported within application{}.

application myapp {
  live on;

  #default recorder
  record all;
  record_path /var/rec;
  record_unique on;

  recorder audio_only {
    record audio;
    record_path /var/rec/audio;
  }

  recorder video_only {
    record video;
    record_max_size 256K;
  }

  recorder foo {
    record all;
    record_interval 10s;
  }
}

All settings are inherited by recorders from higher level.

Project page at github

2 Comments

Publish_done/play_done callbacks

Recently I have added a couple of new HTTP callbacks: on_publish_done and on_play_done. The old on_done is also supported. Moreover a bug with calling it twice is now fixed.

Note however these two are just plain notifications. Their result is never analyzed for future unlike on_publish/on_play.


application foo {
    live on;

    on_publish http://example.com/publish;
    on_publish_done http://example.com/publish_done;

    on_play http://example.com/play;
    on_play_done http://example.com/play_done;
}

Leave a comment

Multi-worker live streaming in master

A few days ago I have merged auto-push branch in master. Several people reported it’s pretty stable. Now it’s possible to do multi-worker live streaming with nginx-rtmp. That can make you achieve really huge traffic. The tests show 2-2.5 Gbps per core. With 16-core CPU it can be as much as 32-35 Gbps.

Auto-push module uses unix domain sockets to pass streams to all workers from the one which has accepted the connection. Every worker has its own unix socket to listen.

The directives to control this feature:

  • rtmp_auto_push on|off – toggle auto-push mode, off by default
  • rtmp_auto_push_reconnect timeout¬†– reconnect timeout after worker got killed, default is 100ms
  • rtmp_socket_dir dir – directory where worker unix domain sockets will be created, default it /tmp. Permissions to create files at that location are needed obviously

All the directives should be placed at the root (top) scope (not rtmp{} or whatever).

Example:

rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /var/sock;

rtmp {
    server {
        listen 1935;
        application myapp {
            live on;
        }
    }
}

Statistics url does not return overall statistics for all workers but for a single random worker (which accepted the request). That’s a task for future.

4 Comments

FFmpeg rtmp patch

Today I have submitted a patch to ffmpeg fixing rtmp protocol in master. Please update ffmpeg from git if you use one of recent versions. 

In certain cases ffmpeg used to receive Audio & Video as two Audio streams and could not do anything with the one of them which was actually a video stream.

Leave a comment