使用 NGINX 的 WebRTC

发布于 2025-01-10 14:58:21 字数 2234 浏览 0 评论 0原文

我想在 Web 应用程序中显示 RTSP 流。我使用 HLS 成功进行了流式传输,配置如下: RTSP 到 RTMP:

ffmpeg -stream_loop -1 -re -i "C:\RA\test.m3u8" -acodec aac -vcodec libx264 -f flv rtmp:localhost/live/stream

Nginx(Windows 上为 1.7)配置

# RTMP configuration
rtmp { 
    server { 
        listen 1935; 
        application live { 
            live on; 
            interleave on;
 
            hls on; 
            hls_path C:\RA\NGINX\hls; 
            hls_fragment 15s; 
        } 
    } 
} 

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


    server {
        listen 81;


        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 C:\RA\NGINX;
        }
    }
}

我找不到与 NGINX 的 WebRTC 配置相关的文档或示例 我尝试使用套接字连接,但我不知道如何定义我的输入流,也不知道测试这个的 URL 是什么...

# RTMP configuration
rtmp { 
    server { 
        listen 1935; 
        application live { 
            live on; 
            
        } 
    } 
} 

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }
 
    upstream websocket {
        server localhost:8010;
    }
 
    server {
        listen 8020;
        location / {
            proxy_pass http://websocket;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_set_header Host $host;
        }
    }
}

I would like to show a RTSP stream in a Web application. I successfully streamed using HLS with the following configuration:
RTSP to RTMP:

ffmpeg -stream_loop -1 -re -i "C:\RA\test.m3u8" -acodec aac -vcodec libx264 -f flv rtmp:localhost/live/stream

Nginx (1.7 on windows) configuration

# RTMP configuration
rtmp { 
    server { 
        listen 1935; 
        application live { 
            live on; 
            interleave on;
 
            hls on; 
            hls_path C:\RA\NGINX\hls; 
            hls_fragment 15s; 
        } 
    } 
} 

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


    server {
        listen 81;


        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 C:\RA\NGINX;
        }
    }
}

I cannot find the documentation or examples related to the WebRTC configuration for NGINX
I tried with the socket connection but I don't know how to defined my input stream or what would be the URL to test this...

# RTMP configuration
rtmp { 
    server { 
        listen 1935; 
        application live { 
            live on; 
            
        } 
    } 
} 

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }
 
    upstream websocket {
        server localhost:8010;
    }
 
    server {
        listen 8020;
        location / {
            proxy_pass http://websocket;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_set_header Host $host;
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文