Dockerfile.cuda 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. ARG NGINX_VERSION=1.23.1
  2. ARG NGINX_RTMP_VERSION=1.2.2
  3. ARG FFMPEG_VERSION=5.1
  4. ##############################
  5. # Build the NGINX-build image.
  6. FROM ubuntu:22.04 as build-nginx
  7. ARG NGINX_VERSION
  8. ARG NGINX_RTMP_VERSION
  9. ARG MAKEFLAGS="-j4"
  10. # Build dependencies.
  11. RUN apt update && apt install -y --no-install-recommends\
  12. build-essential \
  13. cmake \
  14. ca-certificates \
  15. curl \
  16. gcc \
  17. libc-dev \
  18. make \
  19. musl-dev \
  20. openssl \
  21. libssl-dev \
  22. libpcre3 \
  23. libpcre3-dev \
  24. pkg-config \
  25. zlib1g-dev \
  26. wget && \
  27. rm -rf /var/lib/apt/lists/*
  28. WORKDIR /tmp
  29. # Get nginx source.
  30. RUN wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
  31. tar zxf nginx-${NGINX_VERSION}.tar.gz && \
  32. rm nginx-${NGINX_VERSION}.tar.gz
  33. # Get nginx-rtmp module.
  34. RUN wget https://github.com/arut/nginx-rtmp-module/archive/v${NGINX_RTMP_VERSION}.tar.gz && \
  35. tar zxf v${NGINX_RTMP_VERSION}.tar.gz && \
  36. rm v${NGINX_RTMP_VERSION}.tar.gz
  37. # Compile nginx with nginx-rtmp module.
  38. WORKDIR /tmp/nginx-${NGINX_VERSION}
  39. RUN \
  40. ./configure \
  41. --prefix=/usr/local/nginx \
  42. --add-module=/tmp/nginx-rtmp-module-${NGINX_RTMP_VERSION} \
  43. --conf-path=/etc/nginx/nginx.conf \
  44. --with-threads \
  45. --with-file-aio \
  46. --with-http_ssl_module \
  47. --with-debug \
  48. --with-http_stub_status_module \
  49. --with-cc-opt="-Wimplicit-fallthrough=0" && \
  50. make && \
  51. make install
  52. ###############################
  53. # Build the FFmpeg-build image.
  54. FROM nvidia/cuda:11.7.0-devel-ubuntu20.04 as build-ffmpeg
  55. ENV DEBIAN_FRONTEND=noninteractive
  56. ARG FFMPEG_VERSION
  57. ARG PREFIX=/usr/local
  58. ARG MAKEFLAGS="-j4"
  59. # FFmpeg build dependencies.
  60. RUN apt update && apt install -y --no-install-recommends \
  61. build-essential \
  62. coreutils \
  63. cmake \
  64. libx264-dev \
  65. libx265-dev \
  66. libc6 \
  67. libc6-dev \
  68. libfreetype6-dev \
  69. libfdk-aac-dev \
  70. libmp3lame-dev \
  71. libogg-dev \
  72. libass9 \
  73. libass-dev \
  74. libnuma1 \
  75. libnuma-dev \
  76. libopus-dev \
  77. librtmp-dev \
  78. libvpx-dev \
  79. libvorbis-dev \
  80. libwebp-dev \
  81. libtheora-dev \
  82. libtool \
  83. libssl-dev \
  84. pkg-config \
  85. wget \
  86. yasm \
  87. git \
  88. ca-certificates && \
  89. rm -rf /var/lib/apt/lists/*
  90. WORKDIR /tmp
  91. # Clone and install ffnvcodec
  92. RUN git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git && \
  93. cd nv-codec-headers && \
  94. make install
  95. # Get FFmpeg source.
  96. RUN wget http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz && \
  97. tar zxf ffmpeg-${FFMPEG_VERSION}.tar.gz && \
  98. rm ffmpeg-${FFMPEG_VERSION}.tar.gz
  99. # Compile ffmpeg.
  100. WORKDIR /tmp/ffmpeg-${FFMPEG_VERSION}
  101. RUN \
  102. ./configure \
  103. --prefix=${PREFIX} \
  104. --enable-version3 \
  105. --enable-gpl \
  106. --enable-nonfree \
  107. --enable-small \
  108. --enable-libfdk-aac \
  109. --enable-openssl \
  110. --enable-libnpp \
  111. --enable-cuda \
  112. --enable-cuvid \
  113. --enable-nvenc \
  114. --enable-libnpp \
  115. --disable-debug \
  116. --disable-doc \
  117. --disable-ffplay \
  118. --extra-cflags=-I/usr/local/cuda/include \
  119. --extra-ldflags=-L/usr/local/cuda/lib64 \
  120. --extra-libs="-lpthread -lm" && \
  121. make && \
  122. make install && \
  123. make distclean
  124. # Cleanup.
  125. RUN rm -rf /var/cache/* /tmp/*
  126. ##########################
  127. # Build the release image.
  128. FROM nvidia/cuda:11.7.0-devel-ubuntu20.04
  129. LABEL MAINTAINER Alfred Gutierrez <alf.g.jr@gmail.com>
  130. ENV DEBIAN_FRONTEND=noninteractive
  131. ENV NVIDIA_DRIVER_VERSION=455
  132. ENV NVIDIA_VISIBLE_DEVICES all
  133. ENV NVIDIA_DRIVER_CAPABILITIES compute,video,utility
  134. # Set default ports.
  135. ENV HTTP_PORT 80
  136. ENV HTTPS_PORT 443
  137. ENV RTMP_PORT 1935
  138. # Set default options.
  139. ENV SINGLE_STREAM ""
  140. ENV MAX_MUXING_QUEUE_SIZE ""
  141. ENV ANALYZEDURATION ""
  142. RUN apt update && apt install -y --no-install-recommends \
  143. ca-certificates \
  144. curl \
  145. gettext \
  146. libpcre3-dev \
  147. libnvidia-decode-${NVIDIA_DRIVER_VERSION} \
  148. libnvidia-encode-${NVIDIA_DRIVER_VERSION} \
  149. libtheora0 \
  150. openssl \
  151. rtmpdump && \
  152. rm -rf /var/lib/apt/lists/*
  153. COPY --from=build-nginx /usr/local/nginx /usr/local/nginx
  154. COPY --from=build-nginx /etc/nginx /etc/nginx
  155. COPY --from=build-ffmpeg /usr/local /usr/local
  156. COPY --from=build-ffmpeg /usr/lib/x86_64-linux-gnu/libfdk-aac.so.1 /usr/lib/x86_64-linux-gnu/libfdk-aac.so.1
  157. # Add NGINX path, config and static files.
  158. ENV PATH "${PATH}:/usr/local/nginx/sbin"
  159. RUN mkdir -p /opt/data && mkdir /www
  160. COPY nginx-cuda.conf /etc/nginx/nginx.conf.template
  161. COPY entrypoint.cuda.sh /opt/entrypoint.sh
  162. RUN chmod gu+x /opt/entrypoint.sh
  163. COPY static /www/static
  164. EXPOSE 1935
  165. EXPOSE 80
  166. ENTRYPOINT ["/opt/entrypoint.sh"]