Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLS #18

Closed
wilhelm10243 opened this issue Nov 1, 2020 · 7 comments
Closed

HLS #18

wilhelm10243 opened this issue Nov 1, 2020 · 7 comments

Comments

@wilhelm10243
Copy link

Is it possible to open the HLS Feature in the RTMP module?

@che1974
Copy link

che1974 commented Nov 6, 2020

ffmpeg -re -i "https://"
-vcodec copy -acodec copy -vbsf h264_mp4toannexb -f flv
rtmp://192.168.88.11/live/test

@charlesbrandt
Copy link

In a Dockerfile I put:

FROM tiangolo/nginx-rtmp

WORKDIR /mnt/hls/

# I prefer to configure this in docker-compose.yml
# COPY nginx.conf /etc/nginx/nginx.conf

Then in your nginx.conf file:

worker_processes auto;
rtmp_auto_push on;
events {}
rtmp {
    server {
        listen 1935;
        listen [::]:1935 ipv6only=on;    

        application live {
            live on;
            record off;

            hls on;
            hls_path /mnt/hls/live;
            hls_fragment 2s;
            hls_playlist_length 4s;

        }
    }
}

http {
    # Disable server tokens
    server_tokens off;

    # Include MIME types
    include mime.types;

    # Set timeout limit
    keepalive_timeout 65;

    server {
        listen 1999;      # HTTP IPv4
        listen [::]:1999; # HTTP IPv6
        # server_name example.com www.example.com # Your domain (RECOMMENDED BUT OPTIONAL)
        
        location / {
            # Disable cache
            add_header Cache-Control no-cache;

            # Enable CORS
            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;
            }

            # Specify file type to be served (.m3u8)
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t;
            }

            # File location
            # Set to the same hls_path specified in the rtmp application
            root /mnt/hls;
        }
    }
}

I'm still trying to tune the settings for more reliable loading via HLS clients. Suggestions / feedback welcome!

@BenceUszkai
Copy link

@wilhelm10243 , Daily.co solved this problem here:
https://github.com/daily-demos/nginx-rtmp

@ndmgrphc
Copy link

ndmgrphc commented Feb 1, 2022

@charlesbrandt did you ever manage to tune the settings for reliable loading? We're trying to minimize delay down to 5-10 seconds.

@robinp
Copy link

robinp commented Feb 23, 2022

Hey - accidentally I opened #34. I couldn't get the delay down too much either - it seems regardless of the 5s chunk setting, the minimum is around 7-8s. Maybe one could see the reason for that in the module source code if wants to dig in.

@robinp
Copy link

robinp commented Feb 23, 2022

Actually configuring

            hls_fragment 1s;
            hls_max_fragment 2s;
            hls_playlist_length 5s;

got the delay down to 5 sec. The hls_max_fragment is in the source code, but not documented on the wiki. It seems could lead to initial glitch. Also this works well on local network, but not sure if would over internet.

@ndmgrphc
Copy link

ndmgrphc commented Feb 23, 2022

The absolute only solution we found was to increase the frequency of key frames. It solved all problems...

application live {
  live on;
  record off;

  # on_publish http://nginx/rtmp/on_publish;
  # on_done http://nginx/rtmp/on_done;
  # ...
  # re-encode and forward to rtmp://.../hls
  exec /usr/bin/ffmpeg -i rtmp://localhost/live/$name -c:v libx264 -g 15 -keyint_min 15 -preset faster -b:v 512K -s 854x480 -f flv -c:a libfdk_aac -ac 1 -strict -2 -b:a 192k rtmp://localhost/hls/$name;
}      

Even increasing keyframe frequency in OBS solved it...

Repository owner locked and limited conversation to collaborators Aug 25, 2024
@tiangolo tiangolo converted this issue into discussion #79 Aug 25, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants