Skip to content

Instantly share code, notes, and snippets.

@kevmo314
Last active April 28, 2021 03:40
Show Gist options
  • Save kevmo314/f73984bcd7247f59e2cd42b182d8fa77 to your computer and use it in GitHub Desktop.
Save kevmo314/f73984bcd7247f59e2cd42b182d8fa77 to your computer and use it in GitHub Desktop.
nginx + nginx-rtmp + ffmpeg + libsrt
FROM ubuntu:20.04
RUN apt-get -qq update && apt-get -qq upgrade
ENV NGINX_VERSION nginx-1.19.3
ENV FFMPEG_VERSION snapshot
ENV NGINX_RTMP_MODULE_VERSION 1.2.1
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=America/New_York
ENV LD_LIBRARY_PATH=/usr/local/lib
RUN apt-get -qq install git wget tclsh pkg-config cmake libssl-dev build-essential librtmp-dev yasm ca-certificates openssl libpcre3-dev
# Install libsrt.
RUN git clone https://github.com/Haivision/srt /tmp/build/srt
WORKDIR /tmp/build/srt
RUN ./configure
RUN make -j $(getconf _NPROCESSORS_ONLN)
RUN make install
WORKDIR /
# Install ffmpeg.
RUN mkdir -p /tmp/build/ffmpeg && \
cd /tmp/build/ffmpeg && \
wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
tar xjvf ffmpeg-snapshot.tar.bz2
WORKDIR /tmp/build/ffmpeg/ffmpeg
RUN ./configure --enable-libsrt --enable-librtmp
RUN make -j $(getconf _NPROCESSORS_ONLN)
RUN make install
WORKDIR /
# Install 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 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}
WORKDIR /tmp/build/nginx/${NGINX_VERSION}
RUN ./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 \
--with-ipv6 \
--add-module=/tmp/build/nginx-rtmp-module/nginx-rtmp-module-${NGINX_RTMP_MODULE_VERSION} \
--with-cc-opt="-Wimplicit-fallthrough=0" \
--with-debug
RUN make -j $(getconf _NPROCESSORS_ONLN)
RUN make install
WORKDIR /
RUN mkdir /var/lock/nginx
RUN rm -rf /tmp/build
# Forward logs to Docker
RUN ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 1935
CMD ["nginx", "-g", "daemon off;"]
worker_processes auto;
rtmp_auto_push on;
events {}
rtmp {
server {
listen 1935;
application live {
live on;
record off;
exec ffmpeg -i rtmp://localhost:1935/live/$name -vcodec copy -pkt_size 1316 -f= mpegts srt://[DESTINATION_IP]:1935?streamid=input/live/$name
respawn on;
respawn_timeout 2s;
}
}
}
@kevmo314
Copy link
Author

kevmo314 commented Feb 3, 2021

Build with docker build . then run the container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment