我需要从我的 nginx conf 文件中分离 $name 变量。
我得到的 $name 类似于“12345_stream”。我需要拆分它并使用执行中“_”(12345)之前的部分将值 12345 放入 FFMPEG 执行中以及 HLS 推送指令的其他参数中。
我曾尝试做类似的事情:
set $splittename = $name ~^ "([^_])+";
尝试将此代码放在每个块上(所有块、rtmp、服务器等之上),但我总是收到相同的错误:
nginx: [emerg] "set" directive is not allowed here
关于如何分割这个变量或如何在客户端启动流时通过 RTMP 请求直接传递一些参数的一些建议?
编辑1
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;
}
}
}
这是我当前的配置,没有拆分 $name 变量。