refactor: streamline FFmpeg installation process and remove unnecessary CUDA development tools
Some checks failed
Build Worker Base and Application Images / check-base-changes (push) Successful in 8s
Build Worker Base and Application Images / build-base (push) Failing after 4m18s
Build Worker Base and Application Images / build-docker (push) Has been skipped
Build Worker Base and Application Images / deploy-stack (push) Has been skipped
Some checks failed
Build Worker Base and Application Images / check-base-changes (push) Successful in 8s
Build Worker Base and Application Images / build-base (push) Failing after 4m18s
Build Worker Base and Application Images / build-docker (push) Has been skipped
Build Worker Base and Application Images / deploy-stack (push) Has been skipped
This commit is contained in:
parent
ff56c1b666
commit
47d4fa6b8f
1 changed files with 10 additions and 92 deletions
102
Dockerfile.base
102
Dockerfile.base
|
@ -31,24 +31,7 @@ RUN apt-get update && apt-get install -y \
|
|||
python3-numpy \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install CUDA development tools (required for FFmpeg CUDA compilation)
|
||||
RUN apt-get update && apt-get install -y \
|
||||
cuda-nvcc-12-6 \
|
||||
libcuda1 \
|
||||
cuda-cudart-dev-12-6 \
|
||||
cuda-driver-dev-12-6 \
|
||||
|| echo "CUDA development packages not available, continuing without them" && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Try to install NVIDIA packages (may not be available in all environments)
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libnvidia-encode-535 \
|
||||
libnvidia-decode-535 \
|
||||
|| echo "NVIDIA packages not available, continuing without them" && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Use pre-built FFmpeg with CUDA support using the build script
|
||||
ENV FFMPEG_BUILD_SCRIPT_VERSION=1.43
|
||||
# Install prebuilt FFmpeg with CUDA support
|
||||
# Ensure CUDA paths are available
|
||||
ENV PATH="/usr/local/cuda/bin:${PATH}"
|
||||
ENV LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"
|
||||
|
@ -61,23 +44,16 @@ RUN cd /tmp && \
|
|||
make install && \
|
||||
rm -rf /tmp/*
|
||||
|
||||
# Build FFmpeg using the well-maintained build script with CUDA support
|
||||
# Download and install prebuilt FFmpeg with CUDA support
|
||||
RUN cd /tmp && \
|
||||
echo "Building FFmpeg with CUDA support using build script..." && \
|
||||
curl -sL "https://raw.githubusercontent.com/markus-perl/ffmpeg-build-script/master/build-ffmpeg" -o build-ffmpeg && \
|
||||
chmod +x build-ffmpeg && \
|
||||
# Configure the build script for CUDA support
|
||||
SKIPINSTALL=yes \
|
||||
AUTOINSTALL=yes \
|
||||
./build-ffmpeg \
|
||||
--build \
|
||||
--enable-gpl-and-non-free \
|
||||
--latest \
|
||||
--cuda \
|
||||
&& \
|
||||
# Copy built binaries to system paths
|
||||
cp workspace/bin/* /usr/local/bin/ && \
|
||||
cp workspace/lib/* /usr/local/lib/ && \
|
||||
echo "Installing prebuilt FFmpeg with CUDA support..." && \
|
||||
wget https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz && \
|
||||
tar -xf ffmpeg-master-latest-linux64-gpl.tar.xz && \
|
||||
cd ffmpeg-master-latest-linux64-gpl && \
|
||||
# Copy binaries to system paths
|
||||
cp bin/* /usr/local/bin/ && \
|
||||
cp -r lib/* /usr/local/lib/ && \
|
||||
cp -r include/* /usr/local/include/ && \
|
||||
ldconfig && \
|
||||
# Verify CUVID decoders are available
|
||||
echo "=== Verifying FFmpeg CUVID Support ===" && \
|
||||
|
@ -86,45 +62,6 @@ RUN cd /tmp && \
|
|||
(ffmpeg -hide_banner -encoders 2>/dev/null | grep nvenc || echo "No NVENC encoders found") && \
|
||||
cd / && rm -rf /tmp/*
|
||||
|
||||
# Build OpenCV from source with custom FFmpeg and full CUDA support
|
||||
ENV OPENCV_VERSION=4.8.1
|
||||
RUN cd /tmp && \
|
||||
wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
|
||||
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
|
||||
unzip opencv.zip && \
|
||||
unzip opencv_contrib.zip && \
|
||||
cd opencv-${OPENCV_VERSION} && \
|
||||
mkdir build && cd build && \
|
||||
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH \
|
||||
cmake -D CMAKE_BUILD_TYPE=RELEASE \
|
||||
-D CMAKE_INSTALL_PREFIX=/usr/local \
|
||||
-D WITH_CUDA=ON \
|
||||
-D WITH_CUDNN=ON \
|
||||
-D OPENCV_DNN_CUDA=ON \
|
||||
-D ENABLE_FAST_MATH=ON \
|
||||
-D CUDA_FAST_MATH=ON \
|
||||
-D WITH_CUBLAS=ON \
|
||||
-D WITH_NVCUVID=ON \
|
||||
-D WITH_CUVID=ON \
|
||||
-D BUILD_opencv_cudacodec=ON \
|
||||
-D WITH_FFMPEG=ON \
|
||||
-D WITH_LIBV4L=ON \
|
||||
-D BUILD_opencv_python3=ON \
|
||||
-D OPENCV_GENERATE_PKGCONFIG=ON \
|
||||
-D OPENCV_ENABLE_NONFREE=ON \
|
||||
-D OPENCV_EXTRA_MODULES_PATH=/tmp/opencv_contrib-${OPENCV_VERSION}/modules \
|
||||
-D PYTHON3_EXECUTABLE=$(which python3) \
|
||||
-D PYTHON_INCLUDE_DIR=$(python3 -c "import sysconfig; print(sysconfig.get_path('include'))") \
|
||||
-D PYTHON_LIBRARY=$(python3 -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))") \
|
||||
-D BUILD_EXAMPLES=OFF \
|
||||
-D BUILD_TESTS=OFF \
|
||||
-D BUILD_PERF_TESTS=OFF \
|
||||
.. && \
|
||||
make -j$(nproc) && \
|
||||
make install && \
|
||||
ldconfig && \
|
||||
cd / && rm -rf /tmp/*
|
||||
|
||||
# Set environment variables for maximum hardware acceleration
|
||||
ENV LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/local/lib:${LD_LIBRARY_PATH}"
|
||||
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH}"
|
||||
|
@ -143,25 +80,6 @@ RUN grep -v opencv-python requirements.base.txt > requirements.tmp && \
|
|||
mv requirements.tmp requirements.base.txt && \
|
||||
pip install --no-cache-dir -r requirements.base.txt
|
||||
|
||||
# Verify complete hardware acceleration setup
|
||||
RUN echo "=== Hardware Acceleration Verification ===" && \
|
||||
echo "FFmpeg Hardware Accelerators:" && \
|
||||
(ffmpeg -hide_banner -hwaccels 2>/dev/null || echo "FFmpeg hwaccels command failed") && \
|
||||
echo "" && \
|
||||
echo "FFmpeg CUVID Decoders (NVIDIA):" && \
|
||||
(ffmpeg -hide_banner -decoders 2>/dev/null | grep -E "cuvid" || echo "No CUVID decoders found") && \
|
||||
echo "" && \
|
||||
echo "FFmpeg NVENC Encoders (NVIDIA):" && \
|
||||
(ffmpeg -hide_banner -encoders 2>/dev/null | grep -E "nvenc" || echo "No NVENC encoders found") && \
|
||||
echo "" && \
|
||||
echo "Testing CUVID decoder compilation (no GPU required):" && \
|
||||
(ffmpeg -hide_banner -f lavfi -i testsrc=duration=0.1:size=64x64:rate=1 -c:v libx264 -f null - 2>/dev/null && echo "✅ FFmpeg basic functionality working" || echo "❌ FFmpeg basic test failed") && \
|
||||
echo "" && \
|
||||
echo "OpenCV Configuration:" && \
|
||||
(python3 -c "import cv2; print('OpenCV version:', cv2.__version__); build_info = cv2.getBuildInformation(); print('CUDA support:', 'CUDA' in build_info); print('CUVID support:', 'CUVID' in build_info); print('FFmpeg support:', 'FFMPEG' in build_info)" || echo "OpenCV verification failed") && \
|
||||
echo "" && \
|
||||
echo "=== Verification Complete (build-time only) ==="
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue