Nathaniel Anderson
Nathaniel Anderson

Reputation: 41

Nginx RTMP Pull to HLS Streaming

I've followed this guide on setting up RTMP to HLS streaming - https://web.archive.org/web/20221205201139/https://docs.peer5.com/guides/setting-up-hls-live-streaming-server-using-nginx/

RTMP streaming works just fine but for some reason I can't get HLS to link with the already existing RTMP server. I'm using OBS to stream to RTMP and it's set to be on x264 and as far as I know the default codec for audio is AAC so I'm not sure why it's not picking it up.

Current Nginx.conf

worker_processes  auto;
events {
    worker_connections  1024;
}

# RTMP configuration
rtmp {
    server {
        listen 1935; # Listen on standard RTMP port
        chunk_size 4000;

# Define the Application
        application show {
            live on;
            pull rtmp://localhost:1935/stream/test;
            # Turn on HLS
            hls on;
            hls_path /mnt/hls/;
            hls_fragment 3;
            hls_playlist_length 60;
            # disable consuming the stream from nginx as rtmp
            deny play all;
        }

        # RTMP video on demand for mp4 files
        application vod {
            play /mnt/mp4s;
        }

        # RTMP stream using OBS
        application stream {
            live on;
        }

    }
}

http {
    sendfile off;
    tcp_nopush on;
    aio on;
    directio 512;
    default_type application/octet-stream;

    server {
        listen 8080;

        location / {
            # Disable cache
            add_header 'Cache-Control' 'no-cache';

            # CORS setup
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Expose-Headers' 'Content-Length';

            # allow CORS preflight requests
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain charset=UTF-8';
                add_header 'Content-Length' 0;
                return 204;
            }

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

            root /mnt/;
        }
    }
}

I've tried changing the rtmp link I have in that config too to both internal and external IP's since it can be reached. I tested watching the rtmp from another computer on the network to confirm it was functional. I wanted to avoid transcoding with ffmpeg since the server doesn't have that kind of power.

Upvotes: 3

Views: 10267

Answers (2)

Sven Bergner
Sven Bergner

Reputation: 1

use "push" instead of "pull" and send the stream to your hls application.

see this: https://github.com/TareqAlqutami/rtmp-hls-server/blob/master/conf/nginx_no-ffmpeg.conf

Upvotes: 0

Nathaniel Anderson
Nathaniel Anderson

Reputation: 41

So I sorted it out. Essentially all I was looking for was getting RTMP to HLS without the need for transcoding. If anyone else see's this and needs it it's quite simple, however, you do need ffmpeg to pull it off. You essentially tell ffmpeg to pass the stream over to HLS and since OBS is already in the correct video/audio format it will take it without any issues. The command I used was

ffmpeg -re -i rtmp://localhost:1935/stream/test -codec copy -f flv /mnt/hls/stream.m3u8

Doing it this way had little to no effect on my CPU which was exactly what I needed.

Upvotes: 1

Related Questions