首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nginx RTMP拉流到HLS流

Nginx RTMP拉流到HLS流
EN

Stack Overflow用户
提问于 2020-05-06 11:24:47
回答 2查看 6.2K关注 0票数 3

我按照下面的指南将RTMP设置为HLS streaming - https://docs.peer5.com/guides/setting-up-hls-live-streaming-server-using-nginx/

RTMP流工作得很好,但由于某些原因,我无法让HLS与已经存在的RTMP服务器链接。我正在使用OBS来流式传输RTMP,它被设置在x264上,据我所知,音频的默认编解码器是AAC,所以我不确定它为什么不选择它。

当前Nginx.conf

代码语言:javascript
复制
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/;
        }
    }
}

我已经尝试将配置中的rtmp链接更改为内部和外部IP,因为它是可以访问的。我从网络上的另一台计算机上测试了rtmp,以确认它是否工作正常。我想避免使用ffmpeg进行代码转换,因为服务器没有这种能力。

EN

回答 2

Stack Overflow用户

发布于 2020-05-07 07:51:32

所以我把它整理好了。基本上,我所寻找的就是将RTMP转换为HLS,而不需要进行代码转换。如果其他人看到这个并需要它,这是非常简单的,但是,您确实需要ffmpeg来完成它。你本质上是告诉ffmpeg将流传递给HLS,因为OBS已经是正确的视频/音频格式,所以它将不会出现任何问题。我使用的命令是

代码语言:javascript
复制
ffmpeg -re -i rtmp://localhost:1935/stream/test -codec copy -f flv /mnt/hls/stream.m3u8

这样做对我的CPU几乎没有影响,而这正是我所需要的。

票数 1
EN

Stack Overflow用户

发布于 2021-02-22 03:58:21

使用push代替pull,并将流发送给您的hls应用。

看看这个:https://github.com/TareqAlqutami/rtmp-hls-server/blob/master/conf/nginx_no-ffmpeg.conf

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61626844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档