I need to split the $name variable from my nginx conf file.

I got a $name that is something like "12345_stream". I need to split this and use the part before "_" (12345) inside the execution to puth the value 12345 inside the FFMPEG execution and inside other parameters for HLS push directive.

I've tried to do something like that:

set $splittename = $name ~^ "([^_])+";

Tried to put this code on each block (on top of all, rtmp, server, etc) but i got always the same error:

 nginx: [emerg] "set" directive is not allowed here

Some suggertion on how to split this variable or how to pass directly some argument through the RTMP request when client start stream?


  worker_processes  4;

error_log  logs/error.log debug;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

pid /usr/local/nginx/logs/nginx.pid;
rtmp_auto_push on;

events {
    worker_connections  1024;

rtmp {

    server {

        listen 587;
        chunk_size 4000;

        application live {
            live on;
            interleave on;
            wait_key on;
            on_publish http://example/publish;
            record all;
            record_path /path/to/recorded;
            record_append on;
            on_record_done http://example.com/done;
            notify_method get;
            exec ffmpeg -i rtmp://localhost:587/live/$name
         -c:a libfdk_aac -b:a 128k -vcodec libx264 -tune zerolatency -b:v 1920k -vf "scale=1280:trunc(ow/a/2)*2" -movflags +faststart -preset veryfast  -f flv rtmp://localhost:587/hls/$name_high
         -c:a libfdk_aac -b:a 128k -vcodec libx264 -tune zerolatency -b:v 1024k -vf "scale=854:trunc(ow/a/2)*2" -movflags +faststart -preset veryfast  -f flv rtmp://localhost:587/hls/$name_mid
         -c:a libfdk_aac -b:a 96k -vcodec libx264 -tune zerolatency  -b:v 300k -vf "scale=426:trunc(ow/a/2)*2" -movflags +faststart -preset veryfast  -f flv rtmp://localhost:587/hls/$name_low;

        application hls {
            live on;
            interleave on;
            wait_key on;
            hls on;
            hls_fragment 4;
            hls_path /tmp/hls;
            hls_nested on;
            hls_cleanup off;
            hls_variant _high BANDWIDTH=2048000; 
            hls_variant _mid BANDWIDTH=448000; 
            hls_variant _low BANDWIDTH=288000; 


This is my current conf without the split of the $name variable.



You must log in to answer this question.

Browse other questions tagged .