arut / nginx-rtmp-module

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

exec_pull launches all external commands on connection #278

Open sameersbn opened 10 years ago

sameersbn commented 10 years ago

Hello,

I am testing the exec_pull function that has been added to the branch of the same name.

In my rtmp server configuration I have set up 2 streams in exec_pull mode. Please find paste of my sample config http://pastebin.com/u1m3wiD1

Using the sample config, If a user connects to rtmp://localhost:1935/bridge/feed02, the ffmpeg command for the stream is executed and the streaming begins. But at the same time, the ffmpeg command for the other stream (rtmp://localhost:1935/bridge/feed01) is also started even though there is no client viewing that stream.

So, If I add 10 streams like this and if only one user connects to one of the stream, the ffmpeg commands are started for each of the stream.

arut commented 10 years ago

Please show your config. I think you misunderstood the way it works. All exec_pulls are started for each stream. That's exactly how the old exec (exec_push) works. There's no stream filter.

sameersbn commented 10 years ago

Please find my config here: http://pastebin.com/u1m3wiD1

arut commented 10 years ago

I see two execs which are launched on each stream publish. That's exactly how it should work with the current implementation.

It would be nice to have stream filter but syntax would be complicated. Please feel free to suggest good syntax for that.

arudmin commented 10 years ago

Maybe introduce a new command "exec_pull_static [option]" and check match the name and stream For example:

application bridge { live on; exec_pull_static feed01 /usr/bin/ffmpeg -re -i "http://example.com/video111.mp4" -vcodec copy -acodec copy -f flv rtmp://localhost:1935/bridge/$name; exec_pull_static feed02 /usr/bin/ffmpeg -re -i "http://example.com/video222.mp4" -vcodec copy -acodec copy -f flv rtmp://localhost:1935/bridge/$name; }

I apologize if this is a crazy idea, do not take it seriously :-)

sameersbn commented 10 years ago

I am not sure about the internals of the module. Here are my suggestions anyway...

  1. add a 'name' parameter to the exec_pull command. eg. exec_pull /usr/bin/ffmpeg -re -i "" -vcodec copy -acodec copy -f flv rtmp://localhost:1935/bridge/feed01 name=feed01;

So if a user connects to ${app}/${name} then we know exactly which exec_pull command needs to be executed if it is not already running (similar to the pull command). This makes the ${name} redundant, but might not interfere with other use cases.

  1. the other option is to match the ${app}/${name} part of the destination rtmp url of the ffmpeg command. But I strongly feel that this might interfere with other use cases of the module (based on my limited knowledge), but I may be wrong.
arut commented 10 years ago
  1. how do I know if name= is a part of command line or directive argument
  2. parsing command line is not a good idea. There can be any call, not only ffmpeg (gst-launch for example). What if a new version of ffmpeg changes syntax.
sameersbn commented 10 years ago

ahhh... Now I get it.. I was thinking this was a trivial thing.

How about tagging the command itself eg. exec_pull cmd:'/usr/bin/ffmpeg -re -i "url" -vcodec copy -acodec copy -f flv rtmp://localhost:1935/bridge/feed01' name='feed01';

sameersbn commented 10 years ago

alternate suggestion could be something like

application bridge {
  live on;
  exec ${name} {
    type pull; # or static 
    cmd /usr/bin/ffmpeg -re -i "url" -vcodec copy -acodec copy -f flv rtmp://localhost:1935/bridge/feed01;
  }
}

This would if anything else, atleast make the config look cleaner

arut commented 10 years ago

The last idea is good. However it breaks compatibility with the current exec directive.

arut commented 10 years ago

BTW all other execs (exec_play, exec_publish etc) should be supported as well.

sameersbn commented 10 years ago

Well we can support both ways of at the moment and try to detect the way the exec directive has been specified based on the braces maybe. At the same time you can mark the current exec format as deprecated and maybe remove it after 6/12 months (that is, if you are up for it).

arut commented 10 years ago

Please try exec-pull-ext branch. I have added optional exec filtering. To make exec apply only to certain streams

Add exec_options on Add name=STREAMNAME to the end of exec line

exec_pull ffmpeg http://example.com/video.ts -c copy -f flv rtmp://localhost/$app/$name name=mystream;
sameersbn commented 10 years ago

Hi,

I added the following line to the bridge application

application bridge { live on; sync off; interleave on; exec_pull /usr/bin/ffmpeg -re -i "http://download.damagehead.com/samples/five.for.fighting.chances.mp4" vcodec copy -acodec copy -f flv rtmp://localhost:1935/bridge/chances name=chances; }

But the rtmp stream rtmp://localhost/bridge/chances does not work. I see that the ffmpeg command is launched and then repeatedly dies and relaunched.

Anything I am doing wrong here?

arut commented 10 years ago

That's ffmpeg commandline issue

Build nginx in debug mode (--with-debug) Add stderr (stream 2) output to file

exec_pull /usr/bin/ffmpeg -re -i "http://download.damagehead.com/samples/five.for.fighting.chances.mp4" vcodec copy -acodec copy -f flv rtmp://localhost:1935/bridge/chances 2>>/tmp/log name=chances

Then watch /tmp/log. The first line will be ffmpeg commandline after all substitutions.

sameersbn commented 10 years ago

FFMpeg says: "Unable to find a suitable output format for 'name=chances'"

The 'name=chances' part seems to get included in the ffmpeg command.

arut commented 10 years ago
  1. make sure you have exec-pull-ext branch, it's a new branch, not old exec-pull
  2. make sure you have exec_options on directive
sameersbn commented 10 years ago

After adding exec_options on to the bridge {} block it is working. I had not understood what you had meant by add exec_options on in your original message. Sorry about that.

Testing now... Will let you know if I come across any problems. Thanks

arut commented 10 years ago

Great! The new branch has rewritten and improved exec engine. I really need more feedback.

tahar1994 commented 6 years ago

hi please give us the last conf