JJ The Second
JJ The Second

Reputation: 97

Issue with RTMP to HLS multi variants

I have a server that successfully streaming RTMP on port 1935. I can access this stream from VLC. Address is rtmp://localhost:1935/live

I can also successfully use Nginx-RTMP-Module https://github.com/arut/nginx-rtmp-module to stream in HLS. In nginx I'm transforming RTMP to a HLS path and have a server block that serves generated .m3u8 file over http(s).

Issue I'm having is when configuring HLS variants as per as recommended in named library above.

Just to clarify: RTMP to HLS works fine however issue is when trying to serve multi variants. Here is what I've done so far and done some investigation however still struggling to serve my m3u8, I keep getting 404s and when I run top command I can't see anything. I've also changed my user in Nginx conf from www-data to Ubuntu.

Current configuration:

Running Ubuntu 18.04 Pulling RTMP on port 1935 Access over https is: https://rtmp.dev/live/stream.m3u8 (This configuration works fine when I have one stream)

Nginx.conf


user ubuntu;
worker_processes 1;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
}

http {

    sendfile off;
    tcp_nopush on;
    keepalive_timeout 65;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;  
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    gzip on;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}




rtmp {
    server {
            listen 1935;
            chunk_size 4000;
       appliation src {
        live on;
        exec ffmpeg -i rtmp://127.0.0.1/live/$name
            -c:a libfdk_aac -b:a 32k  -c:v libx264 -b:v 128K -f flv rtmp://localhost/hls/$name_low
                -c:a libfdk_aac -b:a 64k  -c:v libx264 -b:v 256k -f flv rtmp://localhost/hls/$name_mid
                -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 512K -f flv rtmp://localhost/hls/$name_hi;

       }

            application live {
                    live on;
                hls on;
                    hls_path /home/ubuntu/hls;
            hls_nested on;
                    hls_fragment 3;
                    hls_playlist_length 60;
            hls_variant _low BANDWIDTH=160000;
                    hls_variant _mid BANDWIDTH=320000;
                    hls_variant _hi  BANDWIDTH=640000;   

            }
    }

}

and here is server nginx server block that allows access over https


server {

     listen 80 http2;
     listen [::]:80 http2;
     listen 443 http2 ssl;
         ssl on;

         ssl_certificate         /home/ubuntu/ssl/domain-ca-bundle.crt;
         ssl_certificate_key     /home/ubuntu/ssl/domain.key;
         ssl_session_timeout 10m;
         ssl_session_cache shared:SSL:20m;
         ssl_protocols                   TLSv1 TLSv1.1 TLSv1.2;
         ssl_prefer_server_ciphers       on;

    root /home/ubuntu/hls;
        server_name rtmp.dev;

        location / {

       types {
                application/dash+xml mpd;
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }

      }
 }




I use FFMPEG to stream in RTMP and I can play stream.m3u8 stream on its own but when multi variant is setup this becomes a 404 response.

As you can see Nginx stores a file in /home/ubuntu/hls however this folder is empty when I I change nginx conf to multi variant version.

My guess is that issue could be that FFMPEG couldn't access this folder however I changed the nginx user to ubuntu and reloaded nginx, once I did this folder owner became ubuntu

drwxr-xr-x 2 ubuntu www-data 4096 Jul 23 12:26 hls

Is there a permission issue that I need to look into? Have you experienced same issue before?

Thanks for your inputs.

Upvotes: 1

Views: 3811

Answers (1)

Can ÖZGEN
Can ÖZGEN

Reputation: 278

According to Docs, your ffmpeg input was using live path but your application's path is src. Corrected version is this:

  appliation src {
    live on;
    exec ffmpeg -i rtmp://127.0.0.1/src/$name
        -c:a libfdk_aac -b:a 32k  -c:v libx264 -b:v 128K -f flv rtmp://localhost/live/$name_low
            -c:a libfdk_aac -b:a 64k  -c:v libx264 -b:v 256k -f flv rtmp://localhost/live/$name_mid
            -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 512K -f flv rtmp://localhost/live/$name_hi;

   }

Upvotes: 1

Related Questions