How to Run GStreamer in Docker
This tutorial shows you how to install and use GStreamer inside a Docker container on Ubuntu 22.04. We'll build a minimal Docker image with support for x264enc, then run a simple test pipeline to encode video to an MP4 file.
Step 1: Create a Dockerfile with GStreamer and x264enc
Create a file named Dockerfile
with the following contents:
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
# Install GStreamer with x264 support and minimal required tools
RUN apt-get update && apt-get install -y \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-bad1.0-dev \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav \
gstreamer1.0-tools \
gstreamer1.0-x \
gstreamer1.0-alsa \
gstreamer1.0-gl \
gstreamer1.0-gtk3 \
gstreamer1.0-qt5 \
gstreamer1.0-pulseaudio \
libx264-dev \
&& rm -rf /var/lib/apt/lists/*
CMD [ "tail", "-F", "/dev/null" ]
This Dockerfile installs a complete GStreamer stack along with the necessary packages to support x264enc
, allowing you to encode H.264 video streams.
Step 2: Build the Docker image
Use the following command to build the Docker image and tag it as gstreamer-test
:
docker build -t gstreamer-test .
Step 3: Start the GStreamer container in the background
Run the container in detached mode and give it a name:
docker run -d --name gstreamer-test gstreamer-test
Step 4: Run a sample GStreamer pipeline inside the container
Use the following GStreamer command to generate a test video, encode it with x264, and save it as an MP4 file:
gst-launch-1.0 videotestsrc num-buffers=300 is-live=true ! video/x-raw,width=640,height=480,framerate=30/1 ! x264enc ! mp4mux ! filesink location=output.mp4
This will create a short 10-second video called output.mp4
using GStreamer's built-in videotestsrc
source.
Step 5: Exit the container
After the pipeline finishes, you can exit the container shell:
exit
Step 6: Copy the video output to the host system
Transfer the generated MP4 file from the container to your local system:
docker cp gstreamer-test:/output.mp4 ./output.mp4
Step 7: Preview the video on your host machine
Open output.mp4
with any media player that supports MP4 and H.264, such as VLC or your system's default video player.
Conclusion
You've successfully created a Dockerized GStreamer environment with x264 encoding support. This is useful for rapid prototyping of pipelines, isolated testing, or running GStreamer apps on systems without native installations.
For more GStreamer examples, pipeline debugging tips, or Docker use cases in embedded systems, explore our other tutorials.
Need Further Support?
📞 Book Consultation Call: Show Calendar!
📩 Contact Via Email: support@proventusnova.com
🌐 Visit Our Website: ProventusNova.com