1

I'm unable to start restream using command exec. Also I tried exec_pull. It didn't help. My target is to restream rtmp://ktv.s4c.link/live/livestream url to my local nginx, to rtmp://localhost:1935/hls. /tmp/logs/ffmpeg.log is empty. I guess that exec not even called, but why?

    rtmp {

    server {
    listen 1935;
    chunk_size 4096;

    application live {
        allow play all;
        live on;
        record off;
        #pull rtmp://ktv.s4c.link/live/livestream;
        exec ffmpeg -i rtmp://localhost:1935/live -f flv rtmp://localhost:1935/hls 2>>/tmp/logs/ffmpeg.log;
    }

        application hls {
        allow play all;
        live on;
        record off;
    }

    }

I'm using nginx-1.12.0. I followed by this tutorial, watched this

Community
  • 1
  • 1
Victor Ponomarenko
  • 490
  • 1
  • 7
  • 12

1 Answers1

2

So, first of all, be aware of that Nginx run all your exec commands as nobody user. And you have to test it in command line like this:

sudo -u nobody ffmpeg -i rtmp://ktv.s4c.link/live/livestream -f flv rtmp://localhost:1935/hls

And then if this command line works - print to nginx.conf.

Secondly, use the full path. It's very important, because a child process than Nginx runs has different environment compared with your current user environment.

sudo -u nobody /usr/bin/ffmpeg -i rtmp://ktv.s4c.link/live/livestream -f flv rtmp://localhost:1935/hls

Thirdly, my mistake was that I used FFmpeg from the repository and that FFmpeg has 2.8.11-0ubuntu0.16.04.1 version. Related to this answer FFmpeg can be compiled with librtmp, that's why FFmpeg can require live=1 and quotes("). So the final command that I copied to nginx.conf was:

sudo -u nobody /usr/bin/ffmpeg -i "rtmp://ktv.s4c.link/live/livestream live=1" -f flv rtmp://localhost:1935/hls

My final nginx.conf

rtmp {
 server {
      listen 1935;
      chunk_size 4096;

       application live {
           live on;
           record off;
           pull rtmp://ktv.s4c.link/live/livestream;
           exec_play /usr/bin/ffmpeg -i "rtmp://ktv.s4c.link/live/livestream live=1" -f flv rtmp://localhost:1935/hls 2>>/tmp/ffmpeg-$name.log;
       }

       application hls {
           live on;
           record off;
       }

  }

As you can mention I added FFmpeg logs 2>>/tmp/ffmpeg-$name.log.

Community
  • 1
  • 1
Victor Ponomarenko
  • 490
  • 1
  • 7
  • 12