Is there any official image for gstreamer for ubuntu or alpine OS ? I have been looking at docker hub but couldn’t find any.
I have built my own image using the below Dockerfile, however I am facing an issue with x264enc, ie it throws a not found error when i use the x264enc in my code.
Ignore the other layers (there is a go module also in the image and controlling gstreamer using cgo).
# Stage 1: Build GStreamer
FROM ubuntu:22.04 AS gstreamer-build
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
# Install necessary dependencies
RUN apt-get update && apt-get install -y \
build-essential \
git \
wget \
autoconf \
automake \
libtool \
pkg-config \
bison \
flex \
python3 \
python3-pip \
python3-setuptools \
ninja-build \
libfaac-dev \
libx264-dev \
librtmp-dev \
libvorbis-dev \
libopus-dev \
libvpx-dev \
libjpeg-dev \
libpng-dev \
libglib2.0-dev \
liborc-0.4-dev \
libpango1.0-dev \
libsoup2.4-dev \
libssl-dev \
libopenh264-dev \
&& apt-get clean
ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu
ENV GST_PLUGIN_PATH=/usr/local/lib/x86_64-linux-gnu/gstreamer-1.0:/usr/include/glib-2.0:/usr/lib/x86_64-linux-gnu/glib-2.0/include
ENV GST_PLUGIN_SCANNER=/usr/local/libexec/gstreamer-1.0/gst-plugin-scanner
# Upgrade Meson to the latest version using pip
RUN pip3 install --upgrade meson
RUN find /usr -name x264.pc
RUN pkg-config --variable=pc_path pkg-config
RUN sed -i 's|Cflags: -I${prefix}/include -DX264_API_IMPORTS|Cflags: -I/usr/include -DX264_API_IMPORTS|' /usr/lib/x86_64-linux-gnu/pkgconfig/x264.pc
RUN pkg-config --cflags --libs openh264
RUN find /usr/include -name "x264.h"
RUN cat /usr/lib/x86_64-linux-gnu/pkgconfig/openh264.pc
# Build GStreamer from source
WORKDIR /usr/src
RUN git clone https://gitlab.freedesktop.org/gstreamer/gstreamer.git && \
cd gstreamer && \
git checkout 1.24.9 && \
meson setup build --prefix=/usr/local -Dugly=enabled -Dc_args="-I/usr/include" -Dc_link_args="-L/usr/lib/x86_64-linux-gnu -lx264" -Dgpl=enabled && \
meson compile -C build && \
meson install -C build
RUN chmod +x /usr/local/libexec/gstreamer-1.0/gst-plugin-scanner
# Set library and plugin paths for GStreamer
ENV PATH="/usr/local/bin:$PATH"
ENV GST_DEBUG=2
# Default command to run the Go application
CMD ["/bin/bash"]
FROM restreamio/gstreamer:latest-dev AS gstreamer-build
FROM ubuntu:22.04 AS go-build
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
# Install dependencies
RUN apt-get update && apt-get install -y \
swig \
wget \
gcc \
g++ \
build-essential \
&& apt-get clean
# Install Go
ENV GO_VERSION=1.22.4
RUN wget https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz && \
rm go${GO_VERSION}.linux-amd64.tar.gz
ENV PATH="/usr/local/go/bin:${PATH}"
# Copy GStreamer libraries, plugins, and headers from the GStreamer build stage
COPY --from=gstreamer-build /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu
COPY --from=gstreamer-build /usr/lib /usr/lib
COPY --from=gstreamer-build /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu
COPY --from=gstreamer-build /usr/include/gstreamer-1.0 /usr/include/gstreamer-1.0
COPY --from=gstreamer-build /usr/include/glib-2.0 /usr/include/glib-2.0
COPY --from=gstreamer-build /usr/lib/x86_64-linux-gnu/glib-2.0/include /usr/lib/x86_64-linux-gnu/glib-2.0/include
# Set Go environment variables for CGO
ENV CGO_CXXFLAGS="-std=c++17 -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include"
ENV CGO_LDFLAGS="-L/usr/lib/x86_64-linux-gnu -L/usr/lib -L/usr/lib/x86_64-linux-gnu -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 -lgstvideo-1.0 -lgstrtp-1.0"
# Set working directory
WORKDIR /app
# Copy project files into the container
COPY . .
# Generate SWIG bindings
RUN swig -go -c++ -intgosize 64 -module gst_helper -o gst_helper/gst_helper_wrap.cxx gst_helper/gst_helper.i
# Build the Go application
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=gcc \
go build -o app main.go
# Stage 3: Minimal runtime image
FROM ubuntu:22.04 AS runtime
# Install only runtime GStreamer libraries
RUN apt-get update && apt-get install -y \
libglib2.0-0 \
liborc-0.4-0 \
libpango1.0-0 \
libsoup2.4-1 \
libssl3 \
intel-media-va-driver \
libmfx1 \
libmfx-dev \
&& apt-get clean
# Copy GStreamer libraries and plugins from the build stage
COPY --from=gstreamer-build /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu
COPY --from=gstreamer-build /usr/lib /usr/lib
COPY --from=gstreamer-build /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu
COPY --from=gstreamer-build /usr/bin /usr/bin
COPY --from=gstreamer-build /usr/include/gstreamer-1.0 /usr/include/gstreamer-1.0
COPY --from=gstreamer-build /usr/include/glib-2.0 /usr/include/glib-2.0
COPY --from=gstreamer-build /usr/lib/x86_64-linux-gnu/glib-2.0/include /usr/lib/x86_64-linux-gnu/glib-2.0/include
COPY --from=gstreamer-build /usr/libexec/gstreamer-1.0/gst-plugin-scanner /usr/libexec/gstreamer-1.0/gst-plugin-scanner
RUN chmod +x /usr/libexec/gstreamer-1.0/gst-plugin-scanner
# Copy the Go application from the Go build stage
COPY --from=go-build /app/app /app/app
# Set library and plugin paths for GStreamer
ENV LD_LIBRARY_PATH=/usr/lib:/usr/lib/x86_64-linux-gnu
ENV GST_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/gstreamer-1.0:/usr/include/glib-2.0:/usr/lib/x86_64-linux-gnu/glib-2.0/include
ENV GST_PLUGIN_SCANNER=/usr/libexec/gstreamer-1.0/gst-plugin-scanner
ENV PATH="/usr/bin:$PATH"
ENV GST_DEBUG=3
ENV GST_DEBUG_DUMP_DOT_DIR=/var/logs
ENV GST_DEBUG_FILE=/var/logs/gstreamer_dev.log
# Set working directory
WORKDIR /app
COPY ./.env.dev .env
EXPOSE 8080
# Default command to run the Go application
CMD ["./app"]