docker - 具有 gcsfuse ffmpeg 权限的 nginx-rtmp
问题描述
我nginx-rtmp-module
在 Docker 中使用将rtmp
流记录到Google Cloud Storage
安装有gcsfuse
.
虽然我能够将流记录到.flv
,exec_record_done
用于将文件转换为0 字节大小.mp4
的结果。.mp4
将 shell 附加到 Docker 容器并执行ffmpeg
命令会生成.mp4
按预期工作的文件。nginx
我怀疑这可能是用户权限和用户权限之间存在差异的问题ffmpeg
。
user nginx;
worker_processes auto;
rtmp_auto_push on;
events {
# use epoll;
}
rtmp {
log_format stream '$remote_addr $app $name $command $bytes_received $session_time';
access_log on;
server {
listen 1935;
listen [::]:1935 ipv6only=on;
application live {
live on;
record all;
record_path /opt/static/videos;
record_max_size 100000K;
record_suffix %Y%m%d%H%M%S.flv; #Colon permitted in Linux Filesystem.
exec_record_done ffmpeg -i $path -codec copy /opt/static/videos/$basename.mp4;
}
}
}
这是我的Dockerfile
# Production image, copy all the files and run next
FROM ubuntu:18.04
ENV NGINX_USER nginx
RUN useradd -r -u 1001 ${NGINX_USER}
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
# USER root
# Versions of Nginx and nginx-rtmp-module to use
ENV NGINX_VERSION=nginx-1.18.0
ENV NGINX_RTMP_MODULE_VERSION=1.2.1
ENV DEBIAN_FRONTEND=noninteractive
# ENV VOD_MODULE_VERSION=399e1a0ecb5b0007df3a627fa8b03628fc922d5e
ENV VOD_MODULE_VERSION=master
# Install dependencies
RUN apt-get update && apt-get install -y software-properties-common && add-apt-repository ppa:jonathonf/ffmpeg-4 && \
apt-get install -y gcc mono-mcs zlib1g-dev libpcre3-dev ca-certificates openssl libssl-dev gnupg lsb-release wget ffmpeg && \
rm -rf /var/lib/apt/lists/*
# Download and decompress Nginx
RUN mkdir -p /tmp/build/nginx && \
cd /tmp/build/nginx && \
wget -O ${NGINX_VERSION}.tar.gz https://nginx.org/download/${NGINX_VERSION}.tar.gz && \
tar -zxf ${NGINX_VERSION}.tar.gz
# Download and decompress VOD module
# RUN mkdir -p /tmp/build/nginx-vod-module && \
# cd /tmp/build/nginx-vod-module && \
# wget -O nginx-vod-module-${VOD_MODULE_VERSION}.tar.gz https://github.com/kaltura/nginx-vod-module/archive/${VOD_MODULE_VERSION}.tar.gz && \
# tar -zxf nginx-vod-module-${VOD_MODULE_VERSION}.tar.gz && \
# cd nginx-vod-module-${VOD_MODULE_VERSION}
# Download and decompress RTMP module
RUN mkdir -p /tmp/build/nginx-rtmp-module && \
cd /tmp/build/nginx-rtmp-module && \
wget -O nginx-rtmp-module-${NGINX_RTMP_MODULE_VERSION}.tar.gz https://github.com/arut/nginx-rtmp-module/archive/v${NGINX_RTMP_MODULE_VERSION}.tar.gz && \
tar -zxf nginx-rtmp-module-${NGINX_RTMP_MODULE_VERSION}.tar.gz && \
cd nginx-rtmp-module-${NGINX_RTMP_MODULE_VERSION}
# Build and install Nginx
# The default puts everything under /usr/local/nginx, so it's needed to change
# it explicitly. Not just for order but to have it in the PATH
RUN cd /tmp/build/nginx/${NGINX_VERSION} && \
./configure \
--sbin-path=/usr/local/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx/nginx.lock \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/tmp/nginx-client-body \
--with-http_ssl_module \
--with-threads \
--add-module=/tmp/build/nginx-rtmp-module/nginx-rtmp-module-${NGINX_RTMP_MODULE_VERSION} && \
make -j $(getconf _NPROCESSORS_ONLN) && \
make install && \
mkdir /var/lock/nginx && \
rm -rf /tmp/build
#install server
# Forward logs to Docker
RUN ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
RUN lsb_release -c -s > /tmp/lsb_release
RUN GCSFUSE_REPO=$(cat /tmp/lsb_release); echo "deb http://packages.cloud.google.com/apt gcsfuse-$GCSFUSE_REPO main" | tee /etc/apt/sources.list.d/gcsfuse.list
RUN wget -O - https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
RUN apt-get update
RUN apt-get install -y gcsfuse
# COPY ./nginx.conf /etc/nginx/nginx.conf
# COPY ./mime.types /etc/nginx/mime.types
# Set up user
RUN mkdir -p /opt/static/videos
RUN chmod 777 -R /opt/static/videos
RUN chown -R ${NGINX_USER}:${NGINX_USER} /opt/static/videos
# RUN
EXPOSE 1935 80
# USER nginx
CMD nginx && gcsfuse -o allow_other --uid=1001 --debug_gcs --foreground xxxxx.appspot.com /opt/static/videos
如何确保ffmpeg
具有正确的用户权限来读取和写入已安装的文件夹?
解决方案
推荐阅读
- asp.net-mvc - 我有一个问题角服务与 asp.net mvc 控制器不连接
- python - 提交表单时参考当前模型django
- cumulocity - 如何在 Cumulocity 中创建层次结构?
- excel - 搜索另一列时,Google 会计算一列中的值实例
- python - 检查 Hive 列中重复数字或字符的计数
- php - PHP 中用于文本字段提交的安全 unicode 正则表达式
- c# - C#为什么当定时器调用绘图函数时我的图片框不移动?
- python - 如何使用 setup.py 从自托管位置在 zip 文件中安装 python 包?
- java - 在 spring rest Api 中启用 SSL (HTTPS)
- ajax - 使用 ajax 发送 >1 GB 数组缓冲区以制作字符串文件