Skip to content

Commit

Permalink
Cuda updates (#87)
Browse files Browse the repository at this point in the history
* Updating Cuda build to use 11.1.

* Update Cuda build and add more resources to docs.
  • Loading branch information
alfg authored Feb 11, 2021
1 parent 534d93e commit 19265b1
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 39 deletions.
57 changes: 23 additions & 34 deletions Dockerfile.cuda
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ RUN cd /tmp/nginx-${NGINX_VERSION} && \

###############################
# Build the FFmpeg-build image.
FROM nvidia/cuda:10.2-devel-ubuntu18.04 as build-ffmpeg
FROM nvidia/cuda:11.1-devel-ubuntu20.04 as build-ffmpeg

ENV DEBIAN_FRONTEND=noninteractive
ARG FFMPEG_VERSION
ARG PREFIX=/usr/local
ARG MAKEFLAGS="-j4"
Expand Down Expand Up @@ -105,25 +107,16 @@ RUN cd /tmp/ffmpeg-${FFMPEG_VERSION} && \
--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 \
--enable-libnpp \
--enable-cuda \
--enable-cuvid \
--enable-nvenc \
--enable-libnpp \
--disable-debug \
--disable-doc \
--disable-ffplay \
--enable-cuda-nvcc \
--enable-libnpp \
--extra-cflags=-I/usr/local/cuda/include \
--extra-ldflags=-L/usr/local/cuda/lib64 \
--extra-libs="-lpthread -lm" && \
Expand All @@ -134,42 +127,38 @@ RUN rm -rf /var/cache/* /tmp/*

##########################
# Build the release image.
FROM nvidia/cuda:10.2-runtime-ubuntu18.04
LABEL MAINTAINER Haned Bahadorzadeh <[email protected]>
FROM nvidia/cuda:11.1-runtime-ubuntu20.04
LABEL MAINTAINER Alfred Gutierrez <[email protected]>

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

RUN apt update && apt install -y \
RUN apt update && apt install -y --no-install-recommends \
ca-certificates \
gettext \
openssl \
libpcre3 \
lame \
libogg0 \
libx264-152 \
libx265-146 \
curl \
libass9 \
libvpx5 \
libvorbis0a \
libwebp6 \
gettext \
libpcre3-dev \
libnvidia-decode-${NVIDIA_DRIVER_VERSION} \
libnvidia-encode-${NVIDIA_DRIVER_VERSION} \
libtheora0 \
libopus0 \
openssl \
rtmpdump

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 /usr/lib/x86_64-linux-gnu/libfdk-aac.so
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"
ENV HW_ACCEL "-hwaccel cuda -hwaccel_output_format cuda"
ADD nginx.conf /etc/nginx/nginx.conf.template
RUN sed -i "s/ffmpeg/ffmpeg ${HW_ACCEL}/g" /etc/nginx/nginx.conf.template
ADD nginx-cuda.conf /etc/nginx/nginx.conf.template
RUN mkdir -p /opt/data && mkdir /www
ADD static /www/static

Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ docker run -it -p 1935:1935 -p 8080:80 --rm nginx-rtmp

* Stream live content to:
```
rtmp://<server ip>:1935/stream/$STREAM_NAME
rtmp://localhost:1935/stream/$STREAM_NAME
```

### SSL
Expand Down Expand Up @@ -64,10 +64,10 @@ volumes:
### Watch Stream
* In Safari, VLC or any HLS player, open:
```
http://<server ip>:8080/live/$STREAM_NAME.m3u8
http://localhost:8080/live/$STREAM_NAME.m3u8
```
* Example Playlist: `http://localhost:8080/live/hello.m3u8`
* [VideoJS Player](https://hls-js.netlify.app/demo/?src=http%3A%2F%2Flocalhost%3A8080%2Flive%2Fhello.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
Expand Down Expand Up @@ -122,13 +122,18 @@ Use the tag: `alfg/nginx-rtmp:cuda`:
docker run -it -p 1935:1935 -p 8080:80 --rm alfg/nginx-rtmp:cuda
```
**This image is experimental!*
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.ffmpeg.org
* https://trac.ffmpeg.org/wiki/HWAccelIntro#CUDANVENCNVDEC
* https://obsproject.com
96 changes: 96 additions & 0 deletions nginx-cuda.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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 -hwaccel cuvid -c:v h264_cuvid -i rtmp://localhost:1935/stream/$name
-c:a libfdk_aac -b:a 128k -c:v h264_nvenc -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 h264_nvenc -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 h264_nvenc -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 h264_nvenc -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 h264_nvenc -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 {
access_log /dev/stdout combined;

ssl_ciphers HIGH:!aNULL:!MD5;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

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 static/stat.xsl;
}

location /static {
alias /www/static;
}

location = /crossdomain.xml {
root /www/static;
default_type text/xml;
expires 24h;
}
}
}

0 comments on commit 19265b1

Please sign in to comment.