# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Nginx RTMP
spec:
    description: A simple self-hosted streaming live room.
    icon: https://www.svgrepo.com/show/373924/nginx.svg
    variables:
        - key: Nginx_DOMAIN
          type: DOMAIN
          name: Nginx Domain
          description: The domain name of Nginx.
    readme: |-
        # Nginx RTMP
        Project blog
        http://nginx-rtmp.blogspot.com
        Wiki manual
        https://github.com/arut/nginx-rtmp-module/wiki/Directives
        ## Features
        * RTMP/HLS/MPEG-DASH live streaming
        * RTMP Video on demand FLV/MP4,
          playing from local filesystem or HTTP
        * Stream relay support for distributed
          streaming: push & pull models
        * Recording streams in multiple FLVs
        * H264/AAC support
        * Online transcoding with FFmpeg
        * HTTP callbacks (publish/play/record/update etc)
        * Running external programs on certain events (exec)
        * HTTP control module for recording audio/video and dropping clients
        * Advanced buffering techniques
          to keep memory allocations at a minimum
          level for faster streaming and low
          memory footprint
        * Proved to work with Wirecast, FMS, Wowza,
          JWPlayer, FlowPlayer, StrobeMediaPlayback,
          ffmpeg, avconv, rtmpdump, flvstreamer
          and many more
        * Statistics in XML/XSL in machine- & human-
          readable form
        * Linux/FreeBSD/MacOS/Windows
        ## How to Use
        1. Add a custom domain to Nginx
           Open Config Edit and change your.nginx.domain in index.html to the custom domain you have set.
           Then restart Nginx RTMP
        2. Open OBS or other streaming software, and set in the live broadcast settings
           Server: rtmp://your.server.ip:rtmp_port/live
           Stream key: stream
           After setting, click start broadcast to begin streaming
        3. Open the Nginx custom domain to directly watch the live content
    services:
        - name: Nginx RTMP
          icon: https://www.svgrepo.com/show/373924/nginx.svg
          template: PREBUILT_V2
          spec:
            source:
                image: tiangolo/nginx-rtmp:latest
            ports:
                - id: web
                  port: 80
                  type: HTTP
                - id: rtmp
                  port: 1935
                  type: TCP
            configs:
                - path: /etc/nginx/nginx.conf
                  template: |-
                    worker_processes  1;
                    events {
                        worker_connections  1024;
                    }
                    rtmp {
                        server {
                            listen 1935;
                            chunk_size 4096;
                            application live {
                                live on;
                                record off;
                                hls on;
                                hls_path /tmp/hls;
                                hls_fragment 3;
                                hls_playlist_length 60;
                            }
                        }
                    }
                    http {
                        server {
                            listen 80;
                            location / {
                                root /usr/share/nginx/html;
                                index index.html index.htm;
                            }
                            location /hls {
                                types {
                                    application/vnd.apple.mpegurl m3u8;
                                    video/mp2t ts;
                                }
                                root /tmp;
                                add_header Cache-Control no-cache;
                            }
                        }
                    }
                  permission: null
                  envsubst: null
                - path: /usr/share/nginx/html/index.html
                  template: |-
                    <!DOCTYPE html>
                    <html>
                    <head>
                        <title>Streaming Player</title>
                        <style>
                            body, html {
                                height: 100%;
                                margin: 0;
                                padding: 0;
                                display: flex;
                                justify-content: center;
                                align-items: center;
                                background-color: #000;
                            }
                            #video-container {
                                position: relative;
                                width: 100%;
                                height: 100%;
                                display: flex;
                                justify-content: center;
                                align-items: center;
                            }
                            #video {
                                max-width: 100%;
                                max-height: 100%;
                            }
                        </style>
                        <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
                    </head>
                    <body>
                        <div id="video-container">
                            <video id="video" controls></video>
                        </div>
                        <script>
                            if (Hls.isSupported()) {
                                var video = document.getElementById('video');
                                var hls = new Hls();
                                hls.loadSource('https://your.nginx.domain/hls/stream.m3u8');
                                hls.attachMedia(video);
                                hls.on(Hls.Events.MANIFEST_PARSED, function() {
                                    video.play();
                                });
                            }
                        </script>
                    </body>
                    </html>
                  permission: null
                  envsubst: null
localization:
    zh-CN:
        description: 一个简单的自部署流式直播间。
        readme: |
            # Nginx RTMP
            项目博客
            http://nginx-rtmp.blogspot.com
            Wiki 手册
            https://github.com/arut/nginx-rtmp-module/wiki/Directives
            ## 功能
            * RTMP/HLS/MPEG-DASH 实时流媒体
            * RTMP 点播 FLV/MP4，
              从本地文件系统或 HTTP 播放
            * 支持分布式流媒体的流中继：推送和拉取模型
            * 多 FLV 文件记录流
            * H264/AAC 支持
            * 使用 FFmpeg 在线转码
            * HTTP 回调（发布/播放/记录/更新等）
            * 在特定事件上运行外部程序（exec）
            * HTTP 控制模块，用于录制音频/视频和断开客户端
            * 高级缓冲技术
              以保持内存分配在最低水平，
              实现更快的流传输和低内存占用
            * 已证明与 Wirecast、FMS、Wowza、
              JWPlayer、FlowPlayer、StrobeMediaPlayback、
              ffmpeg、avconv、rtmpdump、flvstreamer
              等多种工具兼容
            * 以机器和人类可读的形式提供 XML/XSL 统计数据
            * 支持 Linux/FreeBSD/MacOS/Windows
            ## 使用方法
            1. 为Nginx添加一个自定义域名
               打开Config Edit把index.html中的your.nginx.domain改成设置的自定义域名
               然后重启Nginx RTMP
            2. 打开OBS或者其他推流软件，在直播设置中设置
               服务器：rtmp://your.server.ip:rtmp_port/live
               推流码：stream
               设置完成后点击开始直播进行推流
            3. 打开Nginx自定义域名，可以直接观看直播内容
    zh-TW:
        description: 一個簡單的自部署流式直播間。
        readme: |-
            # Nginx RTMP
            項目博客
            http://nginx-rtmp.blogspot.com
            Wiki 手冊
            https://github.com/arut/nginx-rtmp-module/wiki/Directives
            ## 功能
            * RTMP/HLS/MPEG-DASH 實時流媒體
            * RTMP 點播 FLV/MP4，
              從本地文件系統或 HTTP 播放
            * 支援分佈式流媒體的流中繼：推送和拉取模型
            * 多 FLV 文件記錄流
            * H264/AAC 支援
            * 使用 FFmpeg 在線轉碼
            * HTTP 回調（發布/播放/記錄/更新等）
            * 在特定事件上運行外部程序（exec）
            * HTTP 控制模組，用於錄製音頻/視頻和斷開客戶端
            * 高級緩衝技術
              以保持記憶體分配在最低水平，
              實現更快的流傳輸和低記憶體佔用
            * 已證明與 Wirecast、FMS、Wowza、
              JWPlayer、FlowPlayer、StrobeMediaPlayback、
              ffmpeg、avconv、rtmpdump、flvstreamer
              等多種工具兼容
            * 以機器和人類可讀的形式提供 XML/XSL 統計數據
            * 支援 Linux/FreeBSD/MacOS/Windows
            ## 使用方法
            1. 為Nginx添加一個自定義域名
               打開Config Edit，將index.html中的your.nginx.domain改成設置的自定義域名
               然後重新啟動Nginx RTMP
            2. 打開OBS或者其他推流軟體，在直播設置中設置
               伺服器：rtmp://your.server.ip:rtmp_port/live
               推流碼：stream
               設置完成後點擊開始直播進行推流
            3. 打開Nginx自定義域名，可以直接觀看直播內容
