zhensolid 1 год назад
Родитель
Сommit
12e1b31f50

+ 7 - 0
.dockerignore

@@ -0,0 +1,7 @@
+.git
+.gitignore
+README.md
+*.md
+*.log
+.DS_Store
+node_modules

+ 11 - 0
.github/dependabot.yml

@@ -0,0 +1,11 @@
+version: 2
+updates:
+  - package-ecosystem: "docker"
+    directory: "/"
+    schedule:
+      interval: "monthly"
+  - package-ecosystem: "github-actions"
+    directory: "/"
+    schedule:
+      interval: "monthly"
+

+ 18 - 0
.github/workflows/docker-build.yml

@@ -0,0 +1,18 @@
+name: Build Docker Image
+
+on:
+  push:
+    branches: [ master ]
+  pull_request:
+    branches: [ master ]
+
+jobs:
+
+  build:
+
+    runs-on: ubuntu-latest
+
+    steps:
+    - uses: actions/checkout@v3
+    - name: Build the Docker image
+      run: docker build . --file Dockerfile --tag nginx-rtmp:$(date +%s)

+ 33 - 0
.github/workflows/docker-publish.yml

@@ -0,0 +1,33 @@
+name: Publish Docker Image
+
+on:
+  release:
+    types: [published]
+
+jobs:
+  push_to_registry:
+    name: Push Docker image to Docker Hub
+    runs-on: ubuntu-latest
+    steps:
+      - name: Check out the repo
+        uses: actions/checkout@v3
+      
+      - name: Log in to Docker Hub
+        uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b
+        with:
+          username: ${{ secrets.DOCKER_USERNAME }}
+          password: ${{ secrets.DOCKER_PASSWORD }}
+      
+      - name: Extract metadata (tags, labels) for Docker
+        id: meta
+        uses: docker/metadata-action@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a
+        with:
+          images: alfg/nginx-rtmp
+      
+      - name: Build and push Docker image
+        uses: docker/build-push-action@1cb9d22b932e4832bb29793b7777ec860fc1cde0
+        with:
+          context: .
+          push: true
+          tags: ${{ steps.meta.outputs.tags }}
+          labels: ${{ steps.meta.outputs.labels }}

+ 23 - 0
.travis.yml

@@ -0,0 +1,23 @@
+sudo: required
+
+language: bash
+services: docker
+
+jobs:
+  include:
+    - env: 
+      - DOCKER_FILE=Dockerfile
+      - DOCKER_TAG=latest
+      - DOCKER_IMAGE=nginx-rtmp 
+    - env:
+      - DOCKER_FILE=Dockerfile.cuda
+      - DOCKER_TAG=cuda
+      - DOCKER_IMAGE=nginx-rtmp
+
+script:
+  - docker build -t ${DOCKER_IMAGE}:${DOCKER_TAG} -f ${DOCKER_FILE} .
+
+after_script:
+  - docker images
+  - docker run -d -p 1935:1935 -p 8080:80 -t ${DOCKER_IMAGE}:${DOCKER_TAG}
+  - docker ps -a

+ 218 - 0
Dockerfile

@@ -0,0 +1,218 @@
+ARG ALPINE_VERSION=3.18
+ARG NGINX_VERSION=1.23.1
+ARG NGINX_RTMP_VERSION=1.2.2
+ARG FFMPEG_VERSION=5.1
+ARG BUILD_CORES
+ARG MAKEFLAGS="-j${BUILD_CORES:-4}"
+ARG BUILDTIME=unknown
+
+##############################
+# Build the NGINX-build image.
+FROM alpine:${ALPINE_VERSION} AS build-nginx
+ARG NGINX_VERSION
+ARG NGINX_RTMP_VERSION
+ARG MAKEFLAGS
+
+# 合并 RUN 命令,优化层数
+RUN apk add --no-cache \
+    build-base \
+    ca-certificates \
+    curl \
+    gcc \
+    libc-dev \
+    libgcc \
+    linux-headers \
+    make \
+    musl-dev \
+    openssl \
+    openssl-dev \
+    pcre \
+    pcre-dev \
+    pkgconf \
+    pkgconfig \
+    zlib-dev \
+    && mkdir -p /tmp/nginx \
+    && cd /tmp/nginx \
+    # 获取并编译 nginx
+    && wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
+    && tar zxf nginx-${NGINX_VERSION}.tar.gz \
+    && rm nginx-${NGINX_VERSION}.tar.gz \
+    # 获取 nginx-rtmp 模块
+    && wget https://github.com/arut/nginx-rtmp-module/archive/v${NGINX_RTMP_VERSION}.tar.gz \
+    && tar zxf v${NGINX_RTMP_VERSION}.tar.gz \
+    && rm v${NGINX_RTMP_VERSION}.tar.gz \
+    #  nginx
+    && cd /tmp/nginx/nginx-${NGINX_VERSION} \
+    && ./configure \
+        --prefix=/usr/local/nginx \
+        --add-module=/tmp/nginx/nginx-rtmp-module-${NGINX_RTMP_VERSION} \
+        --conf-path=/etc/nginx/nginx.conf \
+        --with-threads \
+        --with-file-aio \
+        --with-http_ssl_module \
+        --with-debug \
+        --with-http_stub_status_module \
+        --with-cc-opt="-Wimplicit-fallthrough=0" \
+    && make \
+    && make install \
+    # 清理构建文件
+    && rm -rf /var/cache/* /tmp/* /var/tmp/*
+
+###############################
+# Build the FFmpeg-build image.
+FROM alpine:${ALPINE_VERSION} AS build-ffmpeg
+ARG FFMPEG_VERSION
+ARG PREFIX=/usr/local
+ARG MAKEFLAGS
+
+# 合并 FFmpeg 构建命令
+RUN apk add --no-cache \
+    build-base \
+    coreutils \
+    freetype-dev \
+    lame-dev \
+    libogg-dev \
+    libass \
+    libass-dev \
+    libvpx-dev \
+    libvorbis-dev \
+    libwebp-dev \
+    libtheora-dev \
+    openssl-dev \
+    opus-dev \
+    pkgconf \
+    pkgconfig \
+    rtmpdump-dev \
+    wget \
+    x264-dev \
+    x265-dev \
+    yasm \
+    # 添加 edge 仓库并安装 fdk-aac-dev
+    && echo http://dl-cdn.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories \
+    && apk add --no-cache fdk-aac-dev \
+    # 编译 FFmpeg
+    && cd /tmp \
+    && wget http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz \
+    && tar zxf ffmpeg-${FFMPEG_VERSION}.tar.gz \
+    && rm ffmpeg-${FFMPEG_VERSION}.tar.gz \
+    && cd /tmp/ffmpeg-${FFMPEG_VERSION} \
+    && ./configure \
+        --prefix=${PREFIX} \
+        --enable-version3 \
+        --enable-gpl \
+        --enable-nonfree \
+        --enable-small \
+        --enable-libmp3lame \
+        --enable-libx264 \
+        --enable-libx265 \
+        --enable-libvpx \
+        --enable-libtheora \
+        --enable-libvorbis \
+        --enable-libopus \
+        --enable-libfdk-aac \
+        --enable-libass \
+        --enable-libwebp \
+        --enable-postproc \
+        --enable-libfreetype \
+        --enable-openssl \
+        --disable-debug \
+        --disable-doc \
+        --disable-ffplay \
+        --extra-libs="-lpthread -lm" \
+    && make \
+    && make install \
+    && make distclean \
+    # 清理
+    && rm -rf /var/cache/* /tmp/*
+
+##########################
+# Build the release image.
+FROM alpine:${ALPINE_VERSION}
+LABEL version="1.0" \
+      description="NGINX RTMP Server" \
+      maintainer="zhensolidsl"
+
+# 设置环境变量,添加 ffmpeg 路径
+ENV HTTP_PORT=80 \
+    HTTPS_PORT=443 \
+    RTMP_PORT=1935 \
+    PATH="/usr/local/bin:${PATH}:/usr/local/nginx/sbin"
+
+# 基础包安装
+RUN apk update && \
+    apk add --no-cache \
+    ca-certificates \
+    openssl \
+    pcre
+
+# 媒体相关包装
+RUN apk add --no-cache \
+    gettext \
+    lame \
+    libogg \
+    curl \
+    libass \
+    libvpx \
+    libvorbis \
+    libwebp \
+    libtheora \
+    opus
+
+# 编码工具安装
+RUN apk add --no-cache \
+    rtmpdump \
+    x264-dev \
+    x265-dev \
+    ffmpeg \
+    fdk-aac \
+    fdk-aac-dev
+
+# 时区设置
+RUN apk add --no-cache tzdata && \
+    mkdir -p /opt/data /www && \
+    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
+    echo "Asia/Shanghai" > /etc/timezone && \
+    apk del tzdata
+
+# 创建必要的目录
+RUN mkdir -p /opt/data/hls /www /var/log/nginx
+
+# 复制构建产物
+COPY --from=build-nginx /usr/local/nginx /usr/local/nginx
+COPY --from=build-nginx /etc/nginx /etc/nginx
+COPY --from=build-ffmpeg /usr/local /usr/local
+COPY --from=build-ffmpeg /usr/lib/libfdk-aac.so.2 /usr/lib/libfdk-aac.so.2
+
+# 复制配置文件和静态文件
+COPY nginx.conf /etc/nginx/nginx.conf.template
+COPY static /www/static
+
+# 创建nginx用户和设置权限
+RUN addgroup -S nginx && \
+    adduser -S -G nginx nginx && \
+    # 设置目录权限
+    chown -R nginx:nginx /opt/data /www /usr/local/nginx /etc/nginx /var/log/nginx && \
+    chmod -R 755 /opt/data && \
+    # 确保 ffmpeg 在正确的位置并有正确的权限
+    ln -sf /usr/local/bin/ffmpeg /usr/bin/ffmpeg && \
+    chown root:nginx /usr/local/bin/ffmpeg /usr/bin/ffmpeg && \
+    chmod 755 /usr/local/bin/ffmpeg /usr/bin/ffmpeg && \
+    # 设置库文件权限
+    chown -R root:nginx /usr/local/lib && \
+    chmod -R 755 /usr/local/lib && \
+    # 直接添加 nginx 用户到已存在的 video 组
+    adduser nginx video && \
+    # 确保日志目录存在并有正确权限
+    touch /dev/stdout && \
+    chown nginx:nginx /dev/stdout
+
+# 声明数据卷
+VOLUME ["/opt/data/hls"]
+
+EXPOSE 1935 80
+
+# 添加健康检查
+HEALTHCHECK --interval=30s --timeout=3s \
+    CMD curl -f http://localhost:${HTTP_PORT}/healthcheck || exit 1
+
+CMD ["sh", "-c", "envsubst \"$(env | sed -e 's/=.*//' -e 's/^/\\$/g')\" < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && nginx -g 'daemon off;'"]

+ 176 - 0
Dockerfile-orgin-backup

@@ -0,0 +1,176 @@
+ARG NGINX_VERSION=1.23.1
+ARG NGINX_RTMP_VERSION=1.2.2
+ARG FFMPEG_VERSION=5.1
+
+##############################
+# Build the NGINX-build image.
+FROM alpine:3.16.1 as build-nginx
+ARG NGINX_VERSION
+ARG NGINX_RTMP_VERSION
+ARG MAKEFLAGS="-j4"
+
+# Build dependencies.
+RUN apk add --no-cache \
+  build-base \
+  ca-certificates \
+  curl \
+  gcc \
+  libc-dev \
+  libgcc \
+  linux-headers \
+  make \
+  musl-dev \
+  openssl \
+  openssl-dev \
+  pcre \
+  pcre-dev \
+  pkgconf \
+  pkgconfig \
+  zlib-dev
+
+WORKDIR /tmp
+
+# Get nginx source.
+RUN wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
+  tar zxf nginx-${NGINX_VERSION}.tar.gz && \
+  rm nginx-${NGINX_VERSION}.tar.gz
+
+# Get nginx-rtmp module.
+RUN wget https://github.com/arut/nginx-rtmp-module/archive/v${NGINX_RTMP_VERSION}.tar.gz && \
+  tar zxf v${NGINX_RTMP_VERSION}.tar.gz && \
+  rm v${NGINX_RTMP_VERSION}.tar.gz
+
+# Compile nginx with nginx-rtmp module.
+WORKDIR /tmp/nginx-${NGINX_VERSION}
+RUN \
+  ./configure \
+  --prefix=/usr/local/nginx \
+  --add-module=/tmp/nginx-rtmp-module-${NGINX_RTMP_VERSION} \
+  --conf-path=/etc/nginx/nginx.conf \
+  --with-threads \
+  --with-file-aio \
+  --with-http_ssl_module \
+  --with-debug \
+  --with-http_stub_status_module \
+  --with-cc-opt="-Wimplicit-fallthrough=0" && \
+  make && \
+  make install
+
+###############################
+# Build the FFmpeg-build image.
+FROM alpine:3.16.1 as build-ffmpeg
+ARG FFMPEG_VERSION
+ARG PREFIX=/usr/local
+ARG MAKEFLAGS="-j4"
+
+# FFmpeg build dependencies.
+RUN apk add --no-cache \
+  build-base \
+  coreutils \
+  freetype-dev \
+  lame-dev \
+  libogg-dev \
+  libass \
+  libass-dev \
+  libvpx-dev \
+  libvorbis-dev \
+  libwebp-dev \
+  libtheora-dev \
+  openssl-dev \
+  opus-dev \
+  pkgconf \
+  pkgconfig \
+  rtmpdump-dev \
+  wget \
+  x264-dev \
+  x265-dev \
+  yasm
+
+RUN echo http://dl-cdn.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories
+RUN apk add --no-cache fdk-aac-dev
+
+WORKDIR /tmp
+
+# Get FFmpeg source.
+RUN wget http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz && \
+  tar zxf ffmpeg-${FFMPEG_VERSION}.tar.gz && \
+  rm ffmpeg-${FFMPEG_VERSION}.tar.gz
+
+# Compile ffmpeg.
+WORKDIR /tmp/ffmpeg-${FFMPEG_VERSION}
+RUN \
+  ./configure \
+  --prefix=${PREFIX} \
+  --enable-version3 \
+  --enable-gpl \
+  --enable-nonfree \
+  --enable-small \
+  --enable-libmp3lame \
+  --enable-libx264 \
+  --enable-libx265 \
+  --enable-libvpx \
+  --enable-libtheora \
+  --enable-libvorbis \
+  --enable-libopus \
+  --enable-libfdk-aac \
+  --enable-libass \
+  --enable-libwebp \
+  --enable-postproc \
+  --enable-libfreetype \
+  --enable-openssl \
+  --disable-debug \
+  --disable-doc \
+  --disable-ffplay \
+  --extra-libs="-lpthread -lm" && \
+  make && \
+  make install && \
+  make distclean
+
+# Cleanup.
+RUN rm -rf /var/cache/* /tmp/*
+
+##########################
+# Build the release image.
+FROM alpine:3.16.1
+LABEL MAINTAINER Alfred Gutierrez <alf.g.jr@gmail.com>
+
+# Set default ports.
+ENV HTTP_PORT 80
+ENV HTTPS_PORT 443
+ENV RTMP_PORT 1935
+
+RUN apk add --no-cache \
+  ca-certificates \
+  gettext \
+  openssl \
+  pcre \
+  lame \
+  libogg \
+  curl \
+  libass \
+  libvpx \
+  libvorbis \
+  libwebp \
+  libtheora \
+  opus \
+  rtmpdump \
+  x264-dev \
+  x265-dev
+
+COPY --from=build-nginx /usr/local/nginx /usr/local/nginx
+COPY --from=build-nginx /etc/nginx /etc/nginx
+COPY --from=build-ffmpeg /usr/local /usr/local
+COPY --from=build-ffmpeg /usr/lib/libfdk-aac.so.2 /usr/lib/libfdk-aac.so.2
+
+# Add NGINX path, config and static files.
+ENV PATH "${PATH}:/usr/local/nginx/sbin"
+COPY nginx.conf /etc/nginx/nginx.conf.template
+RUN mkdir -p /opt/data && mkdir /www
+COPY static /www/static
+
+EXPOSE 1935
+EXPOSE 80
+
+CMD envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < \
+  /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && \
+  nginx

+ 189 - 0
Dockerfile.cuda

@@ -0,0 +1,189 @@
+ARG NGINX_VERSION=1.23.1
+ARG NGINX_RTMP_VERSION=1.2.2
+ARG FFMPEG_VERSION=5.1
+
+##############################
+# Build the NGINX-build image.
+FROM ubuntu:22.04 as build-nginx
+ARG NGINX_VERSION
+ARG NGINX_RTMP_VERSION
+ARG MAKEFLAGS="-j4"
+
+# Build dependencies.
+RUN apt update && apt install -y --no-install-recommends\
+  build-essential \
+  cmake \
+  ca-certificates \
+  curl \
+  gcc \
+  libc-dev \
+  make \
+  musl-dev \
+  openssl \
+  libssl-dev \
+  libpcre3 \
+  libpcre3-dev \
+  pkg-config \
+  zlib1g-dev \
+  wget && \
+  rm -rf /var/lib/apt/lists/*
+
+WORKDIR /tmp
+
+# Get nginx source.
+RUN wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
+  tar zxf nginx-${NGINX_VERSION}.tar.gz && \
+  rm nginx-${NGINX_VERSION}.tar.gz
+
+# Get nginx-rtmp module.
+RUN wget https://github.com/arut/nginx-rtmp-module/archive/v${NGINX_RTMP_VERSION}.tar.gz && \
+  tar zxf v${NGINX_RTMP_VERSION}.tar.gz && \
+  rm v${NGINX_RTMP_VERSION}.tar.gz
+
+# Compile nginx with nginx-rtmp module.
+WORKDIR /tmp/nginx-${NGINX_VERSION}
+RUN \
+  ./configure \
+  --prefix=/usr/local/nginx \
+  --add-module=/tmp/nginx-rtmp-module-${NGINX_RTMP_VERSION} \
+  --conf-path=/etc/nginx/nginx.conf \
+  --with-threads \
+  --with-file-aio \
+  --with-http_ssl_module \
+  --with-debug \
+  --with-http_stub_status_module \
+  --with-cc-opt="-Wimplicit-fallthrough=0" && \
+  make && \
+  make install
+
+###############################
+# Build the FFmpeg-build image.
+FROM nvidia/cuda:11.7.0-devel-ubuntu20.04 as build-ffmpeg
+
+ENV DEBIAN_FRONTEND=noninteractive
+ARG FFMPEG_VERSION
+ARG PREFIX=/usr/local
+ARG MAKEFLAGS="-j4"
+
+# FFmpeg build dependencies.
+RUN apt update && apt install -y --no-install-recommends \
+  build-essential \
+  coreutils \
+  cmake \
+  libx264-dev \
+  libx265-dev \
+  libc6 \
+  libc6-dev \
+  libfreetype6-dev \
+  libfdk-aac-dev \
+  libmp3lame-dev \
+  libogg-dev \
+  libass9 \
+  libass-dev \
+  libnuma1 \
+  libnuma-dev \
+  libopus-dev \
+  librtmp-dev \
+  libvpx-dev \
+  libvorbis-dev \
+  libwebp-dev \
+  libtheora-dev \
+  libtool \
+  libssl-dev \
+  pkg-config \
+  wget \
+  yasm \
+  git \
+  ca-certificates && \
+  rm -rf /var/lib/apt/lists/*
+
+WORKDIR /tmp
+
+# Clone and install ffnvcodec
+RUN git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git && \
+  cd nv-codec-headers && \
+  make install
+
+# Get FFmpeg source.
+RUN wget http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz && \
+  tar zxf ffmpeg-${FFMPEG_VERSION}.tar.gz && \
+  rm ffmpeg-${FFMPEG_VERSION}.tar.gz
+
+# Compile ffmpeg.
+WORKDIR /tmp/ffmpeg-${FFMPEG_VERSION}
+RUN \
+  ./configure \
+  --prefix=${PREFIX} \
+  --enable-version3 \
+  --enable-gpl \
+  --enable-nonfree \
+  --enable-small \
+  --enable-libfdk-aac \
+  --enable-openssl \
+  --enable-libnpp \
+  --enable-cuda \
+  --enable-cuvid \
+  --enable-nvenc \
+  --enable-libnpp \
+  --disable-debug \
+  --disable-doc \
+  --disable-ffplay \
+  --extra-cflags=-I/usr/local/cuda/include \
+  --extra-ldflags=-L/usr/local/cuda/lib64 \
+  --extra-libs="-lpthread -lm" && \
+  make && \
+  make install && \
+  make distclean
+
+# Cleanup.
+RUN rm -rf /var/cache/* /tmp/*
+
+##########################
+# Build the release image.
+FROM nvidia/cuda:11.7.0-devel-ubuntu20.04
+LABEL MAINTAINER Alfred Gutierrez <alf.g.jr@gmail.com>
+
+ENV DEBIAN_FRONTEND=noninteractive
+ENV NVIDIA_DRIVER_VERSION=455
+ENV NVIDIA_VISIBLE_DEVICES all
+ENV NVIDIA_DRIVER_CAPABILITIES compute,video,utility
+
+# Set default ports.
+ENV HTTP_PORT 80
+ENV HTTPS_PORT 443
+ENV RTMP_PORT 1935
+
+# Set default options.
+ENV SINGLE_STREAM ""
+ENV MAX_MUXING_QUEUE_SIZE ""
+ENV ANALYZEDURATION ""
+
+RUN apt update && apt install -y --no-install-recommends \
+  ca-certificates \
+  curl \
+  gettext \
+  libpcre3-dev \
+  libnvidia-decode-${NVIDIA_DRIVER_VERSION} \
+  libnvidia-encode-${NVIDIA_DRIVER_VERSION} \
+  libtheora0 \
+  openssl \
+  rtmpdump && \
+  rm -rf /var/lib/apt/lists/*
+
+COPY --from=build-nginx /usr/local/nginx /usr/local/nginx
+COPY --from=build-nginx /etc/nginx /etc/nginx
+COPY --from=build-ffmpeg /usr/local /usr/local
+COPY --from=build-ffmpeg /usr/lib/x86_64-linux-gnu/libfdk-aac.so.1 /usr/lib/x86_64-linux-gnu/libfdk-aac.so.1
+
+# Add NGINX path, config and static files.
+ENV PATH "${PATH}:/usr/local/nginx/sbin"
+RUN mkdir -p /opt/data && mkdir /www
+COPY nginx-cuda.conf /etc/nginx/nginx.conf.template
+COPY entrypoint.cuda.sh /opt/entrypoint.sh
+RUN chmod gu+x /opt/entrypoint.sh
+COPY static /www/static
+
+EXPOSE 1935
+EXPOSE 80
+
+ENTRYPOINT ["/opt/entrypoint.sh"]

+ 21 - 72
LICENSE

@@ -1,72 +1,21 @@
-Apache License 
-Version 2.0, January 2004 
-http://www.apache.org/licenses/
-TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-1. Definitions.
-
-"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
-
-"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
-
-"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
-
-"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
-
-"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
-
-"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
-
-"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
-
-"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
-
-"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
-
-"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
-
-2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
-
-3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
-
-4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
-
-(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
-
-(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
-
-(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
-
-(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
-
-You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
-
-5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
-
-6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
-
-7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
-
-8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
-
-9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
-
-END OF TERMS AND CONDITIONS
-
-APPENDIX: How to apply the Apache License to your work.
-
-To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
-
-Copyright [yyyy] [name of copyright owner]
-
-Licensed under the Apache License, Version 2.0 (the "License"); 
-you may not use this file except in compliance with the License. 
-You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software 
-distributed under the License is distributed on an "AS IS" BASIS, 
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-See the License for the specific language governing permissions and 
-limitations under the License.
+The MIT License (MIT)
+
+Copyright (c) 2016 Alfred Gutierrez
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 142 - 0
README.md

@@ -1,2 +1,144 @@
 # docker-nginx-rtmp
+A Dockerfile installing NGINX, nginx-rtmp-module and FFmpeg from source with
+default settings for HLS live streaming. Built on Alpine Linux.
 
+* Nginx 1.23.1 (Mainline version compiled from source)
+* nginx-rtmp-module 1.2.2 (compiled from source)
+* ffmpeg 5.1 (compiled from source)
+* Default HLS settings (See: [nginx.conf](nginx.conf))
+
+[![Docker Stars](https://img.shields.io/docker/stars/alfg/nginx-rtmp.svg)](https://hub.docker.com/r/alfg/nginx-rtmp/)
+[![Docker Pulls](https://img.shields.io/docker/pulls/alfg/nginx-rtmp.svg)](https://hub.docker.com/r/alfg/nginx-rtmp/)
+[![Docker Automated build](https://img.shields.io/docker/automated/alfg/nginx-rtmp.svg)](https://hub.docker.com/r/alfg/nginx-rtmp/builds/)
+[![Build Status](https://travis-ci.org/alfg/docker-nginx-rtmp.svg?branch=master)](https://travis-ci.org/alfg/docker-nginx-rtmp)
+
+## Usage
+
+### Server
+* Pull docker image and run:
+```
+docker pull alfg/nginx-rtmp
+docker run -it -p 1935:1935 -p 8080:80 --rm alfg/nginx-rtmp
+```
+or 
+
+* Build and run container from source:
+```
+docker build -t nginx-rtmp .
+docker run -it -p 1935:1935 -p 8080:80 --rm nginx-rtmp
+```
+
+* Stream live content to:
+```
+rtmp://localhost:1935/stream/$STREAM_NAME
+```
+
+### SSL 
+To enable SSL, see [nginx.conf](nginx.conf) and uncomment the lines:
+```
+listen 443 ssl;
+ssl_certificate     /opt/certs/example.com.crt;
+ssl_certificate_key /opt/certs/example.com.key;
+```
+
+This will enable HTTPS using a self-signed certificate supplied in [/certs](/certs). If you wish to use HTTPS, it is **highly recommended** to obtain your own certificates and update the `ssl_certificate` and `ssl_certificate_key` paths.
+
+I recommend using [Certbot](https://certbot.eff.org/docs/install.html) from [Let's Encrypt](https://letsencrypt.org).
+
+### Environment Variables
+This Docker image uses `envsubst` for environment variable substitution. You can define additional environment variables in `nginx.conf` as `${var}` and pass them in your `docker-compose` file or `docker` command.
+
+
+### Custom `nginx.conf`
+If you wish to use your own `nginx.conf`, mount it as a volume in your `docker-compose` or `docker` command as `nginx.conf.template`:
+```yaml
+volumes:
+  - ./nginx.conf:/etc/nginx/nginx.conf.template
+```
+
+### OBS Configuration
+* Stream Type: `Custom Streaming Server`
+* URL: `rtmp://localhost:1935/stream`
+* Stream Key: `hello`
+
+### Watch Stream
+* Load up the example hls.js player in your browser:
+```
+http://localhost:8080/player.html?url=http://localhost:8080/live/hello.m3u8
+```
+
+* Or in Safari, VLC or any HLS player, open:
+```
+http://localhost:8080/live/$STREAM_NAME.m3u8
+```
+* Example Playlist: `http://localhost:8080/live/hello.m3u8`
+* [HLS.js Player](https://hls-js.netlify.app/demo/?src=http%3A%2F%2Flocalhost%3A8080%2Flive%2Fhello.m3u8)
+* FFplay: `ffplay -fflags nobuffer rtmp://localhost:1935/stream/hello`
+
+### FFmpeg Build
+```
+$ ffmpeg -buildconf
+
+ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
+  built with gcc 10.2.1 (Alpine 10.2.1_pre1) 20201203
+  configuration: --prefix=/usr/local --enable-version3 --enable-gpl --enable-nonfree --enable-small --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libvpx --enable-libtheora --enable-libvorbis --enable-libopus --enable-libfdk-aac --enable-libass --enable-libwebp --enable-postproc --enable-avresample --enable-libfreetype --enable-openssl --disable-debug --disable-doc --disable-ffplay --extra-libs='-lpthread -lm'
+  libavutil      56. 70.100 / 56. 70.100
+  libavcodec     58.134.100 / 58.134.100
+  libavformat    58. 76.100 / 58. 76.100
+  libavdevice    58. 13.100 / 58. 13.100
+  libavfilter     7.110.100 /  7.110.100
+  libavresample   4.  0.  0 /  4.  0.  0
+  libswscale      5.  9.100 /  5.  9.100
+  libswresample   3.  9.100 /  3.  9.100
+  libpostproc    55.  9.100 / 55.  9.100
+
+  configuration:
+    --prefix=/usr/local
+    --enable-version3
+    --enable-gpl
+    --enable-nonfree
+    --enable-small
+    --enable-libmp3lame
+    --enable-libx264
+    --enable-libx265
+    --enable-libvpx
+    --enable-libtheora
+    --enable-libvorbis
+    --enable-libopus
+    --enable-libfdk-aac
+    --enable-libass
+    --enable-libwebp
+    --enable-postproc
+    --enable-avresample
+    --enable-libfreetype
+    --enable-openssl
+    --disable-debug
+    --disable-doc
+    --disable-ffplay
+    --extra-libs='-lpthread -lm'
+```
+
+
+### FFmpeg Hardware Acceleration
+A `Dockerfile.cuda` image is available to enable FFmpeg hardware acceleration via the [NVIDIA's CUDA](https://trac.ffmpeg.org/wiki/HWAccelIntro#CUDANVENCNVDEC).
+
+Use the tag: `alfg/nginx-rtmp:cuda`:
+```
+docker run -it -p 1935:1935 -p 8080:80 --rm alfg/nginx-rtmp:cuda
+```
+
+You must have a supported platform and driver to run this image.
+
+* https://github.com/NVIDIA/nvidia-docker
+* https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker
+* https://docs.docker.com/docker-for-windows/wsl/
+* https://trac.ffmpeg.org/wiki/HWAccelIntro#CUDANVENCNVDEC
+
+**This image is experimental!*
+
+## Resources
+* https://alpinelinux.org/
+* http://nginx.org
+* https://github.com/arut/nginx-rtmp-module
+* https://www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ATE KEY-----

+ 14 - 0
docker-compose.yml

@@ -0,0 +1,14 @@
+version: '3'
+
+services:
+  nginx-rtmp:
+    build: .
+    ports:
+      - 1935:1935
+      - 8080:80
+      - 8443:443
+    environment:
+      - HTTP_PORT=80
+      - RTMP_PORT=1935
+    volumes:
+      - ./certs:/opt/certs

+ 37 - 0
entrypoint.cuda.sh

@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+set -e
+
+if [ ! -v "${MAX_MUXING_QUEUE_SIZE}" ]; then
+  MAX_MUXING_QUEUE_SIZE_ARG="-max_muxing_queue_size ${MAX_MUXING_QUEUE_SIZE} "
+fi
+
+if [ ! -v "${ANALYZEDURATION}" ]; then
+  ANALYZEDURATION_ARG="-analyzeduration ${ANALYZEDURATION} "
+fi
+
+quality1=('480' '256k' '64k' 'low' '448000')
+quality2=('720' '768k' '128k' 'mid' '448000')
+quality3=('960' '1240k' '128k' 'high' '1152000')
+quality4=('1280' '1920k' '128k' 'hd720' '2048000')
+
+if [ -v ${SINGLE_STREAM} ]; then
+  qualities=(quality1 quality2 quality3 quality4)
+else
+  qualities=(quality4)
+fi
+
+output_execpush="/usr/local/bin/ffmpeg $ANALYZEDURATION_ARG-async 1 -vsync -1 -hwaccel cuda -hwaccel_output_format cuda -c:v h264_cuvid -i rtmp://localhost:1935/stream/\$name "
+output_hlsvariants=""
+for quality in "${qualities[@]}"; do
+  declare -n qualitylist=$quality
+  output_execpush="$output_execpush"$'\n\t\t'"-c:v h264_nvenc -c:a aac -b:v ${qualitylist[1]} -b:a ${qualitylist[2]} -vf \"scale_npp=${qualitylist[0]}:trunc(ow/a/2)*2\" -zerolatency 1 $MAX_MUXING_QUEUE_SIZE_ARG-f flv rtmp://localhost:1935/hls/\$name_${qualitylist[3]}"
+  output_hlsvariants=$'\n\t\t'"hls_variant _${qualitylist[3]} BANDWIDTH=${qualitylist[4]};"$'\n'"${output_hlsvariants}"
+done
+
+export EXECPUSH="$output_execpush"
+export HLSVARIANTS="$output_hlsvariants"
+
+envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < \
+  /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf
+
+nginx

+ 92 - 0
nginx-cuda.conf

@@ -0,0 +1,92 @@
+daemon off;
+
+error_log /dev/stdout info;
+
+events {
+    worker_connections 1024;
+}
+
+rtmp {
+    server {
+        listen ${RTMP_PORT};
+        chunk_size 4000;
+
+        application stream {
+            live on;
+
+            exec_push ${EXECPUSH};
+        }
+
+        application hls {
+            live on;
+            hls on;
+            hls_fragment_naming system;
+            hls_fragment 5;
+            hls_playlist_length 10;
+            hls_path /opt/data/hls;
+            hls_nested on;
+
+            ${HLSVARIANTS}
+        }
+    }
+}
+
+http {
+    root /www/static;
+    sendfile off;
+    tcp_nopush on;
+    server_tokens off;
+    access_log /dev/stdout combined;
+
+    # Uncomment these lines to enable SSL.
+    # ssl_protocols TLSv1.2 TLSv1.3;
+    # ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
+    # ssl_prefer_server_ciphers off;
+    # ssl_session_cache shared:SSL:10m;
+    # ssl_session_timeout 1d;
+
+    server {
+        listen ${HTTP_PORT};
+
+        # Uncomment these lines to enable SSL.
+        # Update the ssl paths with your own certificate and private key.
+
+        # listen ${HTTPS_PORT} ssl;
+        # ssl_certificate     /opt/certs/example.com.crt;
+        # ssl_certificate_key /opt/certs/example.com.key;
+
+        location /hls {
+            types {
+                application/vnd.apple.mpegurl m3u8;
+                video/mp2t ts;
+            }
+            root /opt/data;
+            add_header Cache-Control no-cache;
+            add_header Access-Control-Allow-Origin *;
+        }
+
+        location /live {
+          alias /opt/data/hls;
+          types {
+              application/vnd.apple.mpegurl m3u8;
+              video/mp2t ts;
+          }
+          add_header Cache-Control no-cache;
+          add_header Access-Control-Allow-Origin *;
+        }
+
+        location /stat {
+            rtmp_stat all;
+            rtmp_stat_stylesheet stat.xsl;
+        }
+
+        location /stat.xsl {
+            root /www/static;
+        }
+
+        location /crossdomain.xml {
+            default_type text/xml;
+            expires 24h;
+        }
+    }
+}

+ 101 - 0
nginx-orgin-backup.conf

@@ -0,0 +1,101 @@
+daemon off;
+
+error_log /dev/stdout info;
+
+events {
+    worker_connections 1024;
+}
+
+rtmp {
+    server {
+        listen ${RTMP_PORT};
+        chunk_size 4000;
+
+        application stream {
+            live on;
+
+            exec ffmpeg -i rtmp://localhost:1935/stream/$name
+              -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1280x720 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_720p2628kbs
+              -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 1000k -f flv -g 30 -r 30 -s 854x480 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_480p1128kbs
+              -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 750k -f flv -g 30 -r 30 -s 640x360 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_360p878kbs
+              -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 400k -f flv -g 30 -r 30 -s 426x240 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_240p528kbs
+              -c:a libfdk_aac -b:a 64k -c:v libx264 -b:v 200k -f flv -g 15 -r 15 -s 426x240 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_240p264kbs;
+        }
+
+        application hls {
+            live on;
+            hls on;
+            hls_fragment_naming system;
+            hls_fragment 5;
+            hls_playlist_length 10;
+            hls_path /opt/data/hls;
+            hls_nested on;
+
+            hls_variant _720p2628kbs BANDWIDTH=2628000,RESOLUTION=1280x720;
+            hls_variant _480p1128kbs BANDWIDTH=1128000,RESOLUTION=854x480;
+            hls_variant _360p878kbs BANDWIDTH=878000,RESOLUTION=640x360;
+            hls_variant _240p528kbs BANDWIDTH=528000,RESOLUTION=426x240;
+            hls_variant _240p264kbs BANDWIDTH=264000,RESOLUTION=426x240;
+        }
+    }
+}
+
+http {
+    root /www/static;
+    sendfile off;
+    tcp_nopush on;
+    server_tokens off;
+    access_log /dev/stdout combined;
+
+    # Uncomment these lines to enable SSL.
+    # ssl_protocols TLSv1.2 TLSv1.3;
+    # ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
+    # ssl_prefer_server_ciphers off;
+    # ssl_session_cache shared:SSL:10m;
+    # ssl_session_timeout 1d;
+
+    server {
+        listen ${HTTP_PORT};
+
+        # Uncomment these lines to enable SSL.
+        # Update the ssl paths with your own certificate and private key.
+            
+        # listen ${HTTPS_PORT} ssl;
+        # ssl_certificate     /opt/certs/example.com.crt;
+        # ssl_certificate_key /opt/certs/example.com.key;
+
+        location /hls {
+            types {
+                application/vnd.apple.mpegurl m3u8;
+                video/mp2t ts;
+            }
+            root /opt/data;
+            add_header Cache-Control no-cache;
+            add_header Access-Control-Allow-Origin *;
+        }
+
+        location /live {
+          alias /opt/data/hls;
+          types {
+              application/vnd.apple.mpegurl m3u8;
+              video/mp2t ts;
+          }
+          add_header Cache-Control no-cache;
+          add_header Access-Control-Allow-Origin *;
+        }
+
+        location /stat {
+            rtmp_stat all;
+            rtmp_stat_stylesheet stat.xsl;
+        }
+
+        location /stat.xsl {
+            root /www/static;
+        }
+
+        location /crossdomain.xml {
+            default_type text/xml;
+            expires 24h;
+        }
+    }
+}

+ 121 - 0
nginx.conf

@@ -0,0 +1,121 @@
+#daemon off;
+
+error_log /dev/stdout info;
+
+events {
+    worker_connections 1024;
+}
+
+rtmp {
+    server {
+        listen ${RTMP_PORT};
+        chunk_size 4000;
+
+        application stream {
+            live on;
+
+            exec ffmpeg -i rtmp://localhost:1935/stream/$name
+                # 4K (2160p) - 比特率设置为 20Mbps
+                -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 20000k -f flv -g 60 -r 60 -s 3840x2160 -preset superfast -profile:v high rtmp://localhost:1935/hls/$name_2160p20000kbs
+                # 2K (1440p) - 比特率设置为 12Mbps
+                -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 12000k -f flv -g 60 -r 60 -s 2560x1440 -preset superfast -profile:v high rtmp://localhost:1935/hls/$name_1440p12000kbs
+                # 1080p - 比特率设置为 6Mbps
+                -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 6000k -f flv -g 60 -r 60 -s 1920x1080 -preset superfast -profile:v high rtmp://localhost:1935/hls/$name_1080p6000kbs
+                # 720p
+                -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1280x720 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_720p2628kbs
+                # 480p
+                -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 1000k -f flv -g 30 -r 30 -s 854x480 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_480p1128kbs
+                # 360p
+                -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 750k -f flv -g 30 -r 30 -s 640x360 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_360p878kbs;
+        }
+
+        application hls {
+            live on;
+            hls on;
+            hls_fragment_naming system;
+            hls_fragment 5;
+            hls_playlist_length 10;
+            hls_path /opt/data/hls;
+            hls_nested on;
+
+            # 添加新的分辨率变体
+            hls_variant _2160p20000kbs BANDWIDTH=20192000,RESOLUTION=3840x2160;
+            hls_variant _1440p12000kbs BANDWIDTH=12192000,RESOLUTION=2560x1440;
+            hls_variant _1080p6000kbs BANDWIDTH=6192000,RESOLUTION=1920x1080;
+            hls_variant _720p2628kbs BANDWIDTH=2628000,RESOLUTION=1280x720;
+            hls_variant _480p1128kbs BANDWIDTH=1128000,RESOLUTION=854x480;
+            hls_variant _360p878kbs BANDWIDTH=878000,RESOLUTION=640x360;
+        }
+    }
+}
+
+http {
+    include       mime.types;
+    default_type  application/octet-stream;
+
+    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
+                     '$status $body_bytes_sent "$http_referer" '
+                     '"$http_user_agent" "$http_x_forwarded_for"';
+    access_log /dev/stdout main;
+
+    root /www/static;
+    sendfile off;
+    tcp_nopush on;
+    server_tokens off;
+    
+    # 安全设置
+    add_header X-Frame-Options "SAMEORIGIN";
+    add_header X-XSS-Protection "1; mode=block";
+    add_header X-Content-Type-Options "nosniff";
+    
+    # 超时设置
+    client_body_timeout 12;
+    client_header_timeout 12;
+    keepalive_timeout 65;
+    
+    server {
+        listen ${HTTP_PORT};
+
+        location /hls {
+            types {
+                application/vnd.apple.mpegurl m3u8;
+                video/mp2t ts;
+            }
+            root /opt/data;
+            add_header Cache-Control no-cache;
+            add_header Access-Control-Allow-Origin *;
+        }
+
+        location /live {
+            alias /opt/data/hls;
+            types {
+                application/vnd.apple.mpegurl m3u8;
+                video/mp2t ts;
+            }
+            add_header Cache-Control no-cache;
+            add_header Access-Control-Allow-Origin *;
+        }
+
+        location /stat {
+            rtmp_stat all;
+            rtmp_stat_stylesheet stat.xsl;
+        }
+
+        location /stat.xsl {
+            root /www/static;
+        }
+
+        location = /healthcheck {
+            access_log off;
+            add_header Content-Type text/plain;
+            return 200 'ok';
+            allow 127.0.0.1;
+            deny all;
+        }
+
+        location /crossdomain.xml {
+            default_type text/xml;
+            expires 24h;
+        }
+    }
+}

+ 7 - 0
static/crossdomain.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
+<cross-domain-policy>
+  <site-control permitted-cross-domain-policies="all"/>
+  <allow-access-from domain="*" secure="false"/>
+  <allow-http-request-headers-from domain="*" headers="*" secure="false"/>
+</cross-domain-policy>

+ 52 - 0
static/player.html

@@ -0,0 +1,52 @@
+
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>hls.js Player</title>
+    <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
+    <style>
+        .container {
+            width: 80%;
+            margin: 0 auto;
+        }
+
+        .video-wrapper {
+            padding-top: 20px;
+            height: 80%;
+            margin: 0 auto;
+        }
+
+        video {
+            display: block;
+            width: 100%;
+            height: 100%;
+        }
+    </style>
+  </head>
+  <body>
+    <div class="container">
+        <h1>hls.js player</h1>
+        <a href="https://github.com/video-dev/hls.js">github.com/video-dev/hls.js</a>
+        <div class="video-wrapper">
+            <video id="video" controls muted></video>
+        </div>
+    </div>
+
+    <script>
+    var params = new URLSearchParams(window.location.search);
+    var url = params.get('url');
+    if (Hls.isSupported()) {
+        var video = document.getElementById('video');
+        var hls = new Hls();
+        hls.attachMedia(video);
+        hls.on(Hls.Events.MEDIA_ATTACHED, function () {
+            hls.loadSource(url);
+            hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
+                video.play();
+            });
+        });
+    }
+    </script>
+  </body>
+</html>

+ 355 - 0
static/stat.xsl

@@ -0,0 +1,355 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+
+<!--
+   Copyright (C) Roman Arutyunyan
+-->
+
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+
+<xsl:template match="/">
+    <html>
+        <head>
+            <title>RTMP statistics</title>
+        </head>
+        <body>
+            <xsl:apply-templates select="rtmp"/>
+            <hr/>
+            Generated by <a href='https://github.com/arut/nginx-rtmp-module'>
+            nginx-rtmp-module</a>&#160;<xsl:value-of select="/rtmp/nginx_rtmp_version"/>,
+            <a href="http://nginx.org">nginx</a>&#160;<xsl:value-of select="/rtmp/nginx_version"/>,
+            pid <xsl:value-of select="/rtmp/pid"/>,
+            built <xsl:value-of select="/rtmp/built"/>&#160;<xsl:value-of select="/rtmp/compiler"/>
+        </body>
+    </html>
+</xsl:template>
+
+<xsl:template match="rtmp">
+    <table cellspacing="1" cellpadding="5">
+        <tr bgcolor="#999999">
+            <th>RTMP</th>
+            <th>#clients</th>
+            <th colspan="4">Video</th>
+            <th colspan="4">Audio</th>
+            <th>In bytes</th>
+            <th>Out bytes</th>
+            <th>In bits/s</th>
+            <th>Out bits/s</th>
+            <th>State</th>
+            <th>Time</th>
+        </tr>
+        <tr>
+            <td colspan="2">Accepted: <xsl:value-of select="naccepted"/></td>
+            <th bgcolor="#999999">codec</th>
+            <th bgcolor="#999999">bits/s</th>
+            <th bgcolor="#999999">size</th>
+            <th bgcolor="#999999">fps</th>
+            <th bgcolor="#999999">codec</th>
+            <th bgcolor="#999999">bits/s</th>
+            <th bgcolor="#999999">freq</th>
+            <th bgcolor="#999999">chan</th>
+            <td>
+                <xsl:call-template name="showsize">
+                    <xsl:with-param name="size" select="bytes_in"/>
+                </xsl:call-template>
+            </td>
+            <td>
+                <xsl:call-template name="showsize">
+                    <xsl:with-param name="size" select="bytes_out"/>
+                </xsl:call-template>
+            </td>
+            <td>
+                <xsl:call-template name="showsize">
+                    <xsl:with-param name="size" select="bw_in"/>
+                    <xsl:with-param name="bits" select="1"/>
+                    <xsl:with-param name="persec" select="1"/>
+                </xsl:call-template>
+            </td>
+            <td>
+                <xsl:call-template name="showsize">
+                    <xsl:with-param name="size" select="bw_out"/>
+                    <xsl:with-param name="bits" select="1"/>
+                    <xsl:with-param name="persec" select="1"/>
+                </xsl:call-template>
+            </td>
+            <td/>
+            <td>
+                <xsl:call-template name="showtime">
+                    <xsl:with-param name="time" select="/rtmp/uptime * 1000"/>
+                </xsl:call-template>
+            </td>
+        </tr>
+        <xsl:apply-templates select="server"/>
+    </table>
+</xsl:template>
+
+<xsl:template match="server">
+    <xsl:apply-templates select="application"/>
+</xsl:template>
+
+<xsl:template match="application">
+    <tr bgcolor="#999999">
+        <td>
+            <b><xsl:value-of select="name"/></b>
+        </td>
+    </tr>
+    <xsl:apply-templates select="live"/>
+    <xsl:apply-templates select="play"/>
+</xsl:template>
+
+<xsl:template match="live">
+    <tr bgcolor="#aaaaaa">
+        <td>
+            <i>live streams</i>
+        </td>
+        <td align="middle">
+            <xsl:value-of select="nclients"/>
+        </td>
+    </tr>
+    <xsl:apply-templates select="stream"/>
+</xsl:template>
+
+<xsl:template match="play">
+    <tr bgcolor="#aaaaaa">
+        <td>
+            <i>vod streams</i>
+        </td>
+        <td align="middle">
+            <xsl:value-of select="nclients"/>
+        </td>
+    </tr>
+    <xsl:apply-templates select="stream"/>
+</xsl:template>
+
+<xsl:template match="stream">
+    <tr valign="top">
+        <xsl:attribute name="bgcolor">
+            <xsl:choose>
+                <xsl:when test="active">#cccccc</xsl:when>
+                <xsl:otherwise>#dddddd</xsl:otherwise>
+            </xsl:choose>
+        </xsl:attribute>
+        <td>
+            <a href="">
+                <xsl:attribute name="onclick">
+                    var d=document.getElementById('<xsl:value-of select="../../name"/>-<xsl:value-of select="name"/>');
+                    d.style.display=d.style.display=='none'?'':'none';
+                    return false
+                </xsl:attribute>
+                <xsl:value-of select="name"/>
+                <xsl:if test="string-length(name) = 0">
+                    [EMPTY]
+                </xsl:if>
+            </a>
+        </td>
+        <td align="middle"> <xsl:value-of select="nclients"/> </td>
+        <td>
+            <xsl:value-of select="meta/video/codec"/>&#160;<xsl:value-of select="meta/video/profile"/>&#160;<xsl:value-of select="meta/video/level"/>
+        </td>
+        <td>
+            <xsl:call-template name="showsize">
+                <xsl:with-param name="size" select="bw_video"/>
+                <xsl:with-param name="bits" select="1"/>
+                <xsl:with-param name="persec" select="1"/>
+            </xsl:call-template>
+        </td>
+        <td>
+            <xsl:apply-templates select="meta/video/width"/>
+        </td>
+        <td>
+            <xsl:value-of select="meta/video/frame_rate"/>
+        </td>
+        <td>
+            <xsl:value-of select="meta/audio/codec"/>&#160;<xsl:value-of select="meta/audio/profile"/>
+        </td>
+        <td>
+            <xsl:call-template name="showsize">
+                <xsl:with-param name="size" select="bw_audio"/>
+                <xsl:with-param name="bits" select="1"/>
+                <xsl:with-param name="persec" select="1"/>
+            </xsl:call-template>
+        </td>
+        <td>
+            <xsl:apply-templates select="meta/audio/sample_rate"/>
+        </td>
+        <td>
+            <xsl:value-of select="meta/audio/channels"/>
+        </td>
+        <td>
+            <xsl:call-template name="showsize">
+               <xsl:with-param name="size" select="bytes_in"/>
+           </xsl:call-template>
+        </td>
+        <td>
+            <xsl:call-template name="showsize">
+                <xsl:with-param name="size" select="bytes_out"/>
+            </xsl:call-template>
+        </td>
+        <td>
+            <xsl:call-template name="showsize">
+                <xsl:with-param name="size" select="bw_in"/>
+                <xsl:with-param name="bits" select="1"/>
+                <xsl:with-param name="persec" select="1"/>
+            </xsl:call-template>
+        </td>
+        <td>
+            <xsl:call-template name="showsize">
+                <xsl:with-param name="size" select="bw_out"/>
+                <xsl:with-param name="bits" select="1"/>
+                <xsl:with-param name="persec" select="1"/>
+            </xsl:call-template>
+        </td>
+        <td><xsl:call-template name="streamstate"/></td>
+        <td>
+            <xsl:call-template name="showtime">
+               <xsl:with-param name="time" select="time"/>
+            </xsl:call-template>
+        </td>
+    </tr>
+    <tr style="display:none">
+        <xsl:attribute name="id">
+            <xsl:value-of select="../../name"/>-<xsl:value-of select="name"/>
+        </xsl:attribute>
+        <td colspan="16" ngcolor="#eeeeee">
+            <table cellspacing="1" cellpadding="5">
+                <tr>
+                    <th>Id</th>
+                    <th>State</th>
+                    <th>Address</th>
+                    <th>Flash version</th>
+                    <th>Page URL</th>
+                    <th>SWF URL</th>
+                    <th>Dropped</th>
+                    <th>Timestamp</th>
+                    <th>A-V</th>
+                    <th>Time</th>
+                </tr>
+                <xsl:apply-templates select="client"/>
+            </table>
+        </td>
+    </tr>
+</xsl:template>
+
+<xsl:template name="showtime">
+    <xsl:param name="time"/>
+
+    <xsl:if test="$time &gt; 0">
+        <xsl:variable name="sec">
+            <xsl:value-of select="floor($time div 1000)"/>
+        </xsl:variable>
+
+        <xsl:if test="$sec &gt;= 86400">
+            <xsl:value-of select="floor($sec div 86400)"/>d
+        </xsl:if>
+
+        <xsl:if test="$sec &gt;= 3600">
+            <xsl:value-of select="(floor($sec div 3600)) mod 24"/>h
+        </xsl:if>
+
+        <xsl:if test="$sec &gt;= 60">
+            <xsl:value-of select="(floor($sec div 60)) mod 60"/>m
+        </xsl:if>
+
+        <xsl:value-of select="$sec mod 60"/>s
+    </xsl:if>
+</xsl:template>
+
+<xsl:template name="showsize">
+    <xsl:param name="size"/>
+    <xsl:param name="bits" select="0" />
+    <xsl:param name="persec" select="0" />
+    <xsl:variable name="sizen">
+        <xsl:value-of select="floor($size div 1024)"/>
+    </xsl:variable>
+    <xsl:choose>
+        <xsl:when test="$sizen &gt;= 1073741824">
+            <xsl:value-of select="format-number($sizen div 1073741824,'#.###')"/> T</xsl:when>
+
+        <xsl:when test="$sizen &gt;= 1048576">
+            <xsl:value-of select="format-number($sizen div 1048576,'#.###')"/> G</xsl:when>
+
+        <xsl:when test="$sizen &gt;= 1024">
+            <xsl:value-of select="format-number($sizen div 1024,'#.##')"/> M</xsl:when>
+        <xsl:when test="$sizen &gt;= 0">
+            <xsl:value-of select="$sizen"/> K</xsl:when>
+    </xsl:choose>
+    <xsl:if test="string-length($size) &gt; 0">
+        <xsl:choose>
+            <xsl:when test="$bits = 1">b</xsl:when>
+            <xsl:otherwise>B</xsl:otherwise>
+        </xsl:choose>
+        <xsl:if test="$persec = 1">/s</xsl:if>
+    </xsl:if>
+</xsl:template>
+
+<xsl:template name="streamstate">
+    <xsl:choose>
+        <xsl:when test="active">active</xsl:when>
+        <xsl:otherwise>idle</xsl:otherwise>
+    </xsl:choose>
+</xsl:template>
+
+
+<xsl:template name="clientstate">
+    <xsl:choose>
+        <xsl:when test="publishing">publishing</xsl:when>
+        <xsl:otherwise>playing</xsl:otherwise>
+    </xsl:choose>
+</xsl:template>
+
+
+<xsl:template match="client">
+    <tr>
+        <xsl:attribute name="bgcolor">
+            <xsl:choose>
+                <xsl:when test="publishing">#cccccc</xsl:when>
+                <xsl:otherwise>#eeeeee</xsl:otherwise>
+            </xsl:choose>
+        </xsl:attribute>
+        <td><xsl:value-of select="id"/></td>
+        <td><xsl:call-template name="clientstate"/></td>
+        <td>
+            <a target="_blank">
+                <xsl:attribute name="href">
+                    http://apps.db.ripe.net/search/query.html&#63;searchtext=<xsl:value-of select="address"/>
+                </xsl:attribute>
+                <xsl:attribute name="title">whois</xsl:attribute>
+                <xsl:value-of select="address"/>
+            </a>
+        </td>
+        <td><xsl:value-of select="flashver"/></td>
+        <td>
+            <a target="_blank">
+                <xsl:attribute name="href">
+                    <xsl:value-of select="pageurl"/>
+                </xsl:attribute>
+                <xsl:value-of select="pageurl"/>
+            </a>
+        </td>
+        <td><xsl:value-of select="swfurl"/></td>
+        <td><xsl:value-of select="dropped"/></td>
+        <td><xsl:value-of select="timestamp"/></td>
+        <td><xsl:value-of select="avsync"/></td>
+        <td>
+            <xsl:call-template name="showtime">
+               <xsl:with-param name="time" select="time"/>
+            </xsl:call-template>
+        </td>
+    </tr>
+</xsl:template>
+
+<xsl:template match="publishing">
+    publishing
+</xsl:template>
+
+<xsl:template match="active">
+    active
+</xsl:template>
+
+<xsl:template match="width">
+    <xsl:value-of select="."/>x<xsl:value-of select="../height"/>
+</xsl:template>
+
+</xsl:stylesheet>