arut / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
13.46k stars 3.51k forks source link

Can not use map functionality outside http block #844

Open jgmio opened 8 years ago

jgmio commented 8 years ago

Before I start with my obstacle I want to say this module rocks!! I'm in the middle of a large tech. feasibility project and you really saved me lots of time!

I have a large set with sets of private rstp streams that i need to link with public keys.

The map $a $b{ } directive would solve it but is not allowed. Is there another way to use such a functionality? (http://nginx.org/en/docs/http/ngx_http_map_module.html)

rtmp {
    server {
        map $name $targetSource{
             publickey_code privateRTSP;
        }
        listen 1935;
        ping 30s;
        # chunk_size 128;
        buflen 0s;
        notify_method get;

        application output {
          live on;
          record off;
          wait_key on; #removes latency https://github.com/arut/nginx-rtmp-module/issues/119

          exec_pull /usr/bin/ffmpeg -rtsp_transport tcp -r 15 -probesize 32 -analyzeduration 0 -i rtsp://$targetSource -threads 1 -c:v libx264 -g 250 -b:v 350k -profile:v baseline -preset:v ultrafast -tune zerolatency -an -f flv rtmp://localhost:1935/output/$name;
        }

    }
}
misiek08 commented 8 years ago

Create bash/python script and use exec_pull on this script. You can use arrays in Python, so it should be exactly same difficulty level :)

jgmio commented 8 years ago

That is actually a very good idea!!! could I execute an API call to say NodeJS or even an external server?

I will open some time in a few hours to try this. I'll get back to you.

Sorry, I just learned Linux + nginx + nginx-rtmp module this month so thanks for understanding my level of ignorance

Didn't get time today :(

misiek08 commented 8 years ago

You should read more, ask less. You can.

jgmio commented 8 years ago

You are right. Usually I do but this project is on a super tight schedule and I needed to focus on other tasks first.

Thanks for your help.

jgmio commented 8 years ago

Sorry to say I can not get a bash to run from the exec command. Followed instructions in regards to the bash wrapper (1), tried the solution @arut provided (2). I've started using chmod to free log/, add execution permissions to scripts... I need more guidance in this because I don't have the linux skills or experience to know what to search for...

The test script:

#!/bin/bash

printf "%s" "teeest" >> ~/log/ffmpeg_wrapper.log

The intended script:

#!/bin/bash

on_die ()
{
    # kill all children
    pkill -KILL -P $$
}

now=$(date +"%b_%d_%Y_%H.%M.%S")

printf '%s\t%s\n' "$now" "$1" >> ~/log/ffmpeg_wrapper.log

trap 'on_die' TERM
ffmpeg -report -rtsp_transport tcp -r 15 -probesize 32 -analyzeduration 0 -i rtsp://###.###.###.###:$1/live2.sdp -threads 1 -c:v libx264 -g 250 -b:v 350k -profile:v baseline -preset:v ultrafast -tune zerolatency -an -f flv rtmp://localhost:1935/output/$1 &
wait

Both don't seem to run. I've tried (also to full path versions) exec bash -x ~/scripts/scripts.sh exec bash -c ~/scripts/scripts.sh exec /bin/bash -x ~/scripts/scripts.sh exec /bin/sh -x ~/scripts/scripts.sh

  1. https://github.com/arut/nginx-rtmp-module/wiki/Exec-wrapper-in-bash
  2. https://github.com/arut/nginx-rtmp-module/issues/45
jgmio commented 7 years ago

*bumb

asinorum commented 5 years ago

hi @jgmio, Did you solved this issue? I'm dealing with the same