Skip to content

Commit

Permalink
docker: split up docker images for ffmpeg, gstreamer, and opencv
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Oct 18, 2024
1 parent 5a93cc9 commit 19c5a18
Show file tree
Hide file tree
Showing 3 changed files with 260 additions and 88 deletions.
127 changes: 127 additions & 0 deletions Dockerfile.ffmpeg-static-alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# syntax=docker/dockerfile:1.3

# To build release:
# docker buildx build -f Dockerfile.ffmpeg-static-alpine -t ghcr.io/hybridgroup/ffmpeg:5.1.6-alpine --platform=linux/arm64,linux/amd64 --load .

# Stage 1: Build OpenCV
FROM --platform=linux/amd64 alpine:3.20 AS builder-amd64

# Install dependencies
RUN apk update && apk add --no-cache \
build-base \
cmake \
git \
diffutils \
perl \
wget \
unzip \
pkgconfig \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
eigen-dev \
nasm yasm \
bzip2 xz zlib-dev x264-dev libvpx-dev \
opus-dev dav1d-dev python3

ARG FFMPEG_VERSION=5.1.6
ARG XZ_VERSION=5.6.3

# Build and install xz
RUN wget -O xz-${XZ_VERSION}.tar.bz2 "https://github.com/tukaani-project/xz/releases/download/v${XZ_VERSION}/xz-${XZ_VERSION}.tar.bz2" && \
tar -xf xz-${XZ_VERSION}.tar.bz2

RUN cd xz-${XZ_VERSION} && \
./configure --disable-shared && \
make && make install

# Build and install bzip2
RUN wget -O bzip2-master.tar.bz2 "https://gitlab.com/bzip2/bzip2/-/archive/master/bzip2-master.tar.bz2" && \
tar -xf bzip2-master.tar.bz2

RUN cd bzip2-master && \
mkdir build && cd build && \
cmake .. -DCMAKE_BUILD_TYPE="Release" -DENABLE_STATIC_LIB=ON -DENABLE_LIB_ONLY=ON && \
cmake --build . --target install

# Build and install ffmpeg

RUN wget -O ffmpeg-5.0.tar.bz2 "https://www.ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2" && \
tar -xf ffmpeg-5.0.tar.bz2

# Build and install libvpx
RUN cd ffmpeg-${FFMPEG_VERSION} && \
git -C libvpx pull 2> /dev/null || git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
cd libvpx && \
./configure --enable-static --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm && \
make -j $(nproc --all) && make install

# Now finish building ffmpeg
RUN cd ffmpeg-${FFMPEG_VERSION} && \
./configure --pkg-config-flags="--static" \
--enable-static --disable-shared --enable-gpl --enable-libx264 --enable-libvpx --enable-zlib \
--disable-sdl2 --disable-vaapi --disable-vdpau --disable-v4l2-m2m --disable-doc && \
make -j $(nproc --all) && make install

FROM --platform=linux/arm64 alpine:3.20 AS builder-arm64

# Install dependencies
RUN apk update && apk add --no-cache \
build-base \
cmake \
git \
diffutils \
perl \
wget \
unzip \
pkgconfig \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
eigen-dev \
nasm yasm \
bzip2 xz zlib-dev x264-dev libvpx-dev \
opus-dev dav1d-dev python3

ARG FFMPEG_VERSION=5.1.6
ARG XZ_VERSION=5.6.3

# Build and install xz
RUN wget -O xz-${XZ_VERSION}.tar.bz2 "https://github.com/tukaani-project/xz/releases/download/v${XZ_VERSION}/xz-${XZ_VERSION}.tar.bz2" && \
tar -xf xz-${XZ_VERSION}.tar.bz2

RUN cd xz-${XZ_VERSION} && \
./configure --disable-shared && \
make && make install

# Build and install bzip2
RUN wget -O bzip2-master.tar.bz2 "https://gitlab.com/bzip2/bzip2/-/archive/master/bzip2-master.tar.bz2" && \
tar -xf bzip2-master.tar.bz2

RUN cd bzip2-master && \
mkdir build && cd build && \
cmake .. -DCMAKE_BUILD_TYPE="Release" -DENABLE_STATIC_LIB=ON -DENABLE_LIB_ONLY=ON && \
cmake --build . --target install

# Build and install ffmpeg
RUN wget -O ffmpeg-5.0.tar.bz2 "https://www.ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2" && \
tar -xf ffmpeg-5.0.tar.bz2

# Build and install libvpx
RUN cd ffmpeg-${FFMPEG_VERSION} && \
git -C libvpx pull 2> /dev/null || git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
cd libvpx && \
./configure --enable-static --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm && \
make -j $(nproc --all) && make install

# Now finish building ffmpeg
RUN cd ffmpeg-${FFMPEG_VERSION} && \
./configure --pkg-config-flags="--static" \
--enable-static --disable-shared --enable-gpl --enable-libx264 --enable-libvpx --enable-zlib \
--disable-sdl2 --disable-vaapi --disable-vdpau --disable-v4l2-m2m --disable-doc && \
make -j $(nproc --all) && make install

# Stage 2: Create final image
FROM builder-${TARGETARCH} AS final

CMD ["ffmpeg"]
113 changes: 113 additions & 0 deletions Dockerfile.gstreamer-static-alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# To build release:
# docker buildx build -f Dockerfile.gstreamer-static-alpine -t ghcr.io/hybridgroup/gstreamer:1.24-alpine --platform=linux/arm64,linux/amd64 --load .

FROM --platform=linux/amd64 alpine:3.20 AS builder-amd64

WORKDIR /gstreamer

ARG GST_BUILD_VERSION=1.24
RUN wget https://gitlab.freedesktop.org/gstreamer/gstreamer/-/archive/${GST_BUILD_VERSION}/gstreamer-${GST_BUILD_VERSION}.tar.gz && \
tar -xvzf gstreamer-${GST_BUILD_VERSION}.tar.gz

WORKDIR /gstreamer/gstreamer-${GST_BUILD_VERSION}

RUN apk update && apk add build-base \
libxml2-dev \
bison \
flex \
glib-dev \
gobject-introspection-dev \
libcap-dev \
libcap-utils \
meson \
perl \
wget \
git \
nasm

RUN meson --default-library=static --prefix=/gstbin \
-Dgst-full-target-type=static_library \
-Dauto_features=disabled \
-Dbase=enabled \
-Dgood=enabled \
-Dbad=enabled \
-Dgst-plugins-base:typefind=enabled \
-Dgst-plugins-base:playback=enabled \
-Dgst-plugins-base:volume=enabled \
-Dgst-plugins-base:audioconvert=enabled \
-Dgst-plugins-base:app=enabled \
-Dgst-plugins-good:isomp4=enabled \
-Dgst-plugins-good:rtp=enabled \
-Dgst-plugins-good:udp=enabled \
-Dgst-plugins-good:rtsp=enabled \
-Dgst-plugins-good:rtpmanager=enabled \
-Dgst-plugins-good:audioparsers=enabled \
-Dgst-plugins-bad:videoparsers=enabled \
-Dgst-plugins-bad:codectimestamper=enabled \
-Dgst-plugins-bad:openh264=enabled \
-Dtools=disabled \
build

RUN meson compile -C build

RUN meson install -C build


FROM --platform=linux/arm64 alpine:3.20 AS builder-arm64

WORKDIR /gstreamer

ARG GST_BUILD_VERSION=1.24
RUN wget https://gitlab.freedesktop.org/gstreamer/gstreamer/-/archive/${GST_BUILD_VERSION}/gstreamer-${GST_BUILD_VERSION}.tar.gz && \
tar -xvzf gstreamer-${GST_BUILD_VERSION}.tar.gz

WORKDIR /gstreamer/gstreamer-${GST_BUILD_VERSION}

RUN apk update && apk add build-base \
libxml2-dev \
bison \
flex \
glib-dev \
gobject-introspection-dev \
libcap-dev \
libcap-utils \
meson \
perl \
wget \
git \
nasm

RUN meson --default-library=static --prefix=/gstbin \
-Dgst-full-target-type=static_library \
-Dauto_features=disabled \
-Dbase=enabled \
-Dgood=enabled \
-Dbad=enabled \
-Dgst-plugins-base:typefind=enabled \
-Dgst-plugins-base:playback=enabled \
-Dgst-plugins-base:volume=enabled \
-Dgst-plugins-base:audioconvert=enabled \
-Dgst-plugins-base:app=enabled \
-Dgst-plugins-good:isomp4=enabled \
-Dgst-plugins-good:rtp=enabled \
-Dgst-plugins-good:udp=enabled \
-Dgst-plugins-good:rtsp=enabled \
-Dgst-plugins-good:rtpmanager=enabled \
-Dgst-plugins-good:audioparsers=enabled \
-Dgst-plugins-bad:videoparsers=enabled \
-Dgst-plugins-bad:codectimestamper=enabled \
-Dgst-plugins-bad:openh264=enabled \
-Dtools=disabled \
build

RUN meson compile -C build

RUN meson install -C build

ARG TARGETARCH

FROM builder-${TARGETARCH} AS final

ENV PATH=/gstbin/bin:${PATH}
ENV LD_LIBRARY_PATH=/usr/lib:/gstbin/lib:/usr/local/lib:${LD_LIBRARY_PATH}

Check warning on line 112 in Dockerfile.gstreamer-static-alpine

View workflow job for this annotation

GitHub Actions / gstreamer

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$LD_LIBRARY_PATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/
ENV PKG_CONFIG_PATH=/gstbin/lib/pkgconfig
108 changes: 20 additions & 88 deletions Dockerfile.opencv-static-alpine
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
# To build release:
# docker buildx build -f Dockerfile.opencv-static-alpine -t ghcr.io/hybridgroup/opencv:4.10-alpine --platform=linux/arm64,linux/amd64 --load .

FROM --platform=linux/amd64 ghcr.io/hybridgroup/gstreamer:1.24-alpine AS gstreamer-amd64

FROM --platform=linux/arm64 ghcr.io/hybridgroup/gstreamer:1.24-alpine AS gstreamer-arm64

# Stage 1: Build OpenCV
FROM --platform=linux/amd64 alpine:3.20 AS builder-amd64
FROM --platform=linux/amd64 ghcr.io/hybridgroup/ffmpeg:5.1.6-alpine AS builder-amd64

# Install dependencies
RUN apk update && apk add --no-cache \
Expand All @@ -22,48 +26,12 @@ RUN apk update && apk add --no-cache \
eigen-dev \
nasm yasm \
bzip2 xz zlib-dev x264-dev libvpx-dev \
opus-dev dav1d-dev \
gstreamer-dev gst-plugins-base-dev gstreamer gst-plugins-bad gst-plugins-good gst-plugins-base gst-plugins-ugly openssl gst-libav

# Build and install xz
ARG XZ_VERSION=5.6.3

RUN wget -O xz-${XZ_VERSION}.tar.bz2 "https://github.com/tukaani-project/xz/releases/download/v${XZ_VERSION}/xz-${XZ_VERSION}.tar.bz2" && \
tar -xf xz-${XZ_VERSION}.tar.bz2

RUN cd xz-${XZ_VERSION} && \
./configure --disable-shared && \
make && make install

# Build and install bzip2
RUN wget -O bzip2-master.tar.bz2 "https://gitlab.com/bzip2/bzip2/-/archive/master/bzip2-master.tar.bz2" && \
tar -xf bzip2-master.tar.bz2

RUN cd bzip2-master && \
mkdir build && cd build && \
cmake .. -DCMAKE_BUILD_TYPE="Release" -DENABLE_STATIC_LIB=ON -DENABLE_LIB_ONLY=ON && \
cmake --build . --target install

# Build and install ffmpeg
ARG FFMPEG_VERSION=5.1.6

RUN wget -O ffmpeg-5.0.tar.bz2 "https://www.ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2" && \
tar -xf ffmpeg-5.0.tar.bz2

# Build and install libvpx
RUN cd ffmpeg-${FFMPEG_VERSION} && \
git -C libvpx pull 2> /dev/null || git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
cd libvpx && \
./configure --enable-static --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm && \
make -j $(nproc --all) && make install

# Now finish building ffmpeg
RUN cd ffmpeg-${FFMPEG_VERSION} && \
./configure --pkg-config-flags="--static" \
--enable-static --disable-shared --enable-gpl --enable-libx264 --enable-libvpx --enable-zlib \
--disable-sdl2 --disable-vaapi --disable-vdpau --disable-v4l2-m2m --disable-doc && \
make -j $(nproc --all) && make install

opus-dev dav1d-dev openssl

# copy gstreamer
COPY --from=gstreamer-amd64 /gstbin/lib /usr/local/lib
COPY --from=gstreamer-amd64 /gstbin/include /usr/local/include

# Set OpenCV version
ARG OPENCV_VERSION=4.10.0

Expand Down Expand Up @@ -93,7 +61,7 @@ RUN cmake -D CMAKE_BUILD_TYPE=Release \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_SHARED_LIBS=OFF \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=OFF \
-D WITH_GSTREAMER=ON \
-D WITH_TBB=ON \
-D WITH_SIMD=ON \
-D BUILD_EXAMPLES=OFF \
Expand All @@ -118,7 +86,7 @@ RUN cmake -D CMAKE_BUILD_TYPE=Release \
make -j$(nproc) && \
make install

FROM --platform=linux/arm64 alpine:3.20 AS builder-arm64
FROM --platform=linux/arm64 ghcr.io/hybridgroup/ffmpeg:5.1.6-alpine AS builder-arm64

# Install dependencies
RUN apk update && apk add --no-cache \
Expand All @@ -136,48 +104,12 @@ RUN apk update && apk add --no-cache \
eigen-dev \
nasm yasm \
bzip2 xz zlib-dev x264-dev libvpx-dev \
opus-dev dav1d-dev \
gstreamer-dev gst-plugins-base-dev gstreamer gst-plugins-bad gst-plugins-good gst-plugins-base gst-plugins-ugly openssl gst-libav

# Build and install xz
ARG XZ_VERSION=5.6.3

RUN wget -O xz-${XZ_VERSION}.tar.bz2 "https://github.com/tukaani-project/xz/releases/download/v${XZ_VERSION}/xz-${XZ_VERSION}.tar.bz2" && \
tar -xf xz-${XZ_VERSION}.tar.bz2

RUN cd xz-${XZ_VERSION} && \
./configure --disable-shared && \
make && make install

# Build and install bzip2
RUN wget -O bzip2-master.tar.bz2 "https://gitlab.com/bzip2/bzip2/-/archive/master/bzip2-master.tar.bz2" && \
tar -xf bzip2-master.tar.bz2

RUN cd bzip2-master && \
mkdir build && cd build && \
cmake .. -DCMAKE_BUILD_TYPE="Release" -DENABLE_STATIC_LIB=ON -DENABLE_LIB_ONLY=ON && \
cmake --build . --target install

# Build and install ffmpeg
ARG FFMPEG_VERSION=5.1.6

RUN wget -O ffmpeg-5.0.tar.bz2 "https://www.ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2" && \
tar -xf ffmpeg-5.0.tar.bz2

# Build and install libvpx
RUN cd ffmpeg-${FFMPEG_VERSION} && \
git -C libvpx pull 2> /dev/null || git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
cd libvpx && \
./configure --enable-static --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm && \
make -j $(nproc --all) && make install

# Now finish building ffmpeg
RUN cd ffmpeg-${FFMPEG_VERSION} && \
./configure --pkg-config-flags="--static" \
--enable-static --disable-shared --enable-gpl --enable-libx264 --enable-libvpx --enable-zlib \
--disable-sdl2 --disable-vaapi --disable-vdpau --disable-v4l2-m2m --disable-doc && \
make -j $(nproc --all) && make install

opus-dev dav1d-dev openssl

# copy gstreamer
COPY --from=gstreamer-arm64 /gstbin/lib /usr/local/lib
COPY --from=gstreamer-arm64 /gstbin/include /usr/local/include

# Set OpenCV version
ARG OPENCV_VERSION=4.10.0

Expand Down Expand Up @@ -206,7 +138,7 @@ RUN cmake -D CMAKE_BUILD_TYPE=Release \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_SHARED_LIBS=OFF \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=OFF \
-D WITH_GSTREAMER=ON \
-D WITH_TBB=ON \
-D WITH_SIMD=ON \
-D ENABLE_LIBJPEG_TURBO_SIMD=OFF \
Expand Down

0 comments on commit 19c5a18

Please sign in to comment.