Skip to content

Commit 19265b1

Browse files
authored
Cuda updates (#87)
* Updating Cuda build to use 11.1. * Update Cuda build and add more resources to docs.
1 parent 534d93e commit 19265b1

File tree

3 files changed

+129
-39
lines changed

3 files changed

+129
-39
lines changed

Dockerfile.cuda

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ RUN cd /tmp/nginx-${NGINX_VERSION} && \
5353

5454
###############################
5555
# Build the FFmpeg-build image.
56-
FROM nvidia/cuda:10.2-devel-ubuntu18.04 as build-ffmpeg
56+
FROM nvidia/cuda:11.1-devel-ubuntu20.04 as build-ffmpeg
57+
58+
ENV DEBIAN_FRONTEND=noninteractive
5759
ARG FFMPEG_VERSION
5860
ARG PREFIX=/usr/local
5961
ARG MAKEFLAGS="-j4"
@@ -105,25 +107,16 @@ RUN cd /tmp/ffmpeg-${FFMPEG_VERSION} && \
105107
--enable-gpl \
106108
--enable-nonfree \
107109
--enable-small \
108-
--enable-libmp3lame \
109-
--enable-libx264 \
110-
--enable-libx265 \
111-
--enable-libvpx \
112-
--enable-libtheora \
113-
--enable-libvorbis \
114-
--enable-libopus \
115110
--enable-libfdk-aac \
116-
--enable-libass \
117-
--enable-libwebp \
118-
--enable-postproc \
119-
--enable-avresample \
120-
--enable-libfreetype \
121111
--enable-openssl \
112+
--enable-libnpp \
113+
--enable-cuda \
114+
--enable-cuvid \
115+
--enable-nvenc \
116+
--enable-libnpp \
122117
--disable-debug \
123118
--disable-doc \
124119
--disable-ffplay \
125-
--enable-cuda-nvcc \
126-
--enable-libnpp \
127120
--extra-cflags=-I/usr/local/cuda/include \
128121
--extra-ldflags=-L/usr/local/cuda/lib64 \
129122
--extra-libs="-lpthread -lm" && \
@@ -134,42 +127,38 @@ RUN rm -rf /var/cache/* /tmp/*
134127

135128
##########################
136129
# Build the release image.
137-
FROM nvidia/cuda:10.2-runtime-ubuntu18.04
138-
LABEL MAINTAINER Haned Bahadorzadeh <h.bahadorzadeh@gmail.com>
130+
FROM nvidia/cuda:11.1-runtime-ubuntu20.04
131+
LABEL MAINTAINER Alfred Gutierrez <alf.g.jr@gmail.com>
132+
133+
ENV DEBIAN_FRONTEND=noninteractive
134+
ENV NVIDIA_DRIVER_VERSION=455
135+
ENV NVIDIA_VISIBLE_DEVICES all
136+
ENV NVIDIA_DRIVER_CAPABILITIES compute,video,utility
139137

140138
# Set default ports.
141139
ENV HTTP_PORT 80
142140
ENV HTTPS_PORT 443
143141
ENV RTMP_PORT 1935
144142

145-
RUN apt update && apt install -y \
143+
RUN apt update && apt install -y --no-install-recommends \
146144
ca-certificates \
147-
gettext \
148-
openssl \
149-
libpcre3 \
150-
lame \
151-
libogg0 \
152-
libx264-152 \
153-
libx265-146 \
154145
curl \
155-
libass9 \
156-
libvpx5 \
157-
libvorbis0a \
158-
libwebp6 \
146+
gettext \
147+
libpcre3-dev \
148+
libnvidia-decode-${NVIDIA_DRIVER_VERSION} \
149+
libnvidia-encode-${NVIDIA_DRIVER_VERSION} \
159150
libtheora0 \
160-
libopus0 \
151+
openssl \
161152
rtmpdump
162153

163154
COPY --from=build-nginx /usr/local/nginx /usr/local/nginx
164155
COPY --from=build-nginx /etc/nginx /etc/nginx
165156
COPY --from=build-ffmpeg /usr/local /usr/local
166-
COPY --from=build-ffmpeg /usr/lib/x86_64-linux-gnu/libfdk-aac.so /usr/lib/x86_64-linux-gnu/libfdk-aac.so
157+
COPY --from=build-ffmpeg /usr/lib/x86_64-linux-gnu/libfdk-aac.so.1 /usr/lib/x86_64-linux-gnu/libfdk-aac.so.1
167158

168159
# Add NGINX path, config and static files.
169160
ENV PATH "${PATH}:/usr/local/nginx/sbin"
170-
ENV HW_ACCEL "-hwaccel cuda -hwaccel_output_format cuda"
171-
ADD nginx.conf /etc/nginx/nginx.conf.template
172-
RUN sed -i "s/ffmpeg/ffmpeg ${HW_ACCEL}/g" /etc/nginx/nginx.conf.template
161+
ADD nginx-cuda.conf /etc/nginx/nginx.conf.template
173162
RUN mkdir -p /opt/data && mkdir /www
174163
ADD static /www/static
175164

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ docker run -it -p 1935:1935 -p 8080:80 --rm nginx-rtmp
3030

3131
* Stream live content to:
3232
```
33-
rtmp://<server ip>:1935/stream/$STREAM_NAME
33+
rtmp://localhost:1935/stream/$STREAM_NAME
3434
```
3535

3636
### SSL
@@ -64,10 +64,10 @@ volumes:
6464
### Watch Stream
6565
* In Safari, VLC or any HLS player, open:
6666
```
67-
http://<server ip>:8080/live/$STREAM_NAME.m3u8
67+
http://localhost:8080/live/$STREAM_NAME.m3u8
6868
```
6969
* Example Playlist: `http://localhost:8080/live/hello.m3u8`
70-
* [VideoJS Player](https://hls-js.netlify.app/demo/?src=http%3A%2F%2Flocalhost%3A8080%2Flive%2Fhello.m3u8)
70+
* [HLS.js Player](https://hls-js.netlify.app/demo/?src=http%3A%2F%2Flocalhost%3A8080%2Flive%2Fhello.m3u8)
7171
* FFplay: `ffplay -fflags nobuffer rtmp://localhost:1935/stream/hello`
7272
7373
### FFmpeg Build
@@ -122,13 +122,18 @@ Use the tag: `alfg/nginx-rtmp:cuda`:
122122
docker run -it -p 1935:1935 -p 8080:80 --rm alfg/nginx-rtmp:cuda
123123
```
124124
125-
**This image is experimental!*
125+
You must have a supported platform and driver to run this image.
126126
127+
* https://github.com/NVIDIA/nvidia-docker
128+
* https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker
129+
* https://docs.docker.com/docker-for-windows/wsl/
130+
* https://trac.ffmpeg.org/wiki/HWAccelIntro#CUDANVENCNVDEC
131+
132+
**This image is experimental!*
127133
128134
## Resources
129135
* https://alpinelinux.org/
130136
* http://nginx.org
131137
* https://github.com/arut/nginx-rtmp-module
132138
* https://www.ffmpeg.org
133-
* https://trac.ffmpeg.org/wiki/HWAccelIntro#CUDANVENCNVDEC
134139
* https://obsproject.com

nginx-cuda.conf

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
daemon off;
2+
3+
error_log /dev/stdout info;
4+
5+
events {
6+
worker_connections 1024;
7+
}
8+
9+
rtmp {
10+
server {
11+
listen ${RTMP_PORT};
12+
chunk_size 4000;
13+
14+
application stream {
15+
live on;
16+
17+
exec ffmpeg -hwaccel cuvid -c:v h264_cuvid -i rtmp://localhost:1935/stream/$name
18+
-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
19+
-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
20+
-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
21+
-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
22+
-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;
23+
}
24+
25+
application hls {
26+
live on;
27+
hls on;
28+
hls_fragment_naming system;
29+
hls_fragment 5;
30+
hls_playlist_length 10;
31+
hls_path /opt/data/hls;
32+
hls_nested on;
33+
34+
hls_variant _720p2628kbs BANDWIDTH=2628000,RESOLUTION=1280x720;
35+
hls_variant _480p1128kbs BANDWIDTH=1128000,RESOLUTION=854x480;
36+
hls_variant _360p878kbs BANDWIDTH=878000,RESOLUTION=640x360;
37+
hls_variant _240p528kbs BANDWIDTH=528000,RESOLUTION=426x240;
38+
hls_variant _240p264kbs BANDWIDTH=264000,RESOLUTION=426x240;
39+
}
40+
}
41+
}
42+
43+
http {
44+
access_log /dev/stdout combined;
45+
46+
ssl_ciphers HIGH:!aNULL:!MD5;
47+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
48+
ssl_session_cache shared:SSL:10m;
49+
ssl_session_timeout 10m;
50+
51+
server {
52+
listen ${HTTP_PORT};
53+
54+
# Uncomment these lines to enable SSL.
55+
# Update the ssl paths with your own certificate and private key.
56+
57+
# listen ${HTTPS_PORT} ssl;
58+
# ssl_certificate /opt/certs/example.com.crt;
59+
# ssl_certificate_key /opt/certs/example.com.key;
60+
61+
location /hls {
62+
types {
63+
application/vnd.apple.mpegurl m3u8;
64+
video/mp2t ts;
65+
}
66+
root /opt/data;
67+
add_header Cache-Control no-cache;
68+
add_header Access-Control-Allow-Origin *;
69+
}
70+
71+
location /live {
72+
alias /opt/data/hls;
73+
types {
74+
application/vnd.apple.mpegurl m3u8;
75+
video/mp2t ts;
76+
}
77+
add_header Cache-Control no-cache;
78+
add_header Access-Control-Allow-Origin *;
79+
}
80+
81+
location /stat {
82+
rtmp_stat all;
83+
rtmp_stat_stylesheet static/stat.xsl;
84+
}
85+
86+
location /static {
87+
alias /www/static;
88+
}
89+
90+
location = /crossdomain.xml {
91+
root /www/static;
92+
default_type text/xml;
93+
expires 24h;
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)