How to use GStreamer on Torizon OS
Introduction
Video processing has become a major feature in the embedded world and has many facets. From decoding a camera's video stream to pre-process frames for an AI application, the use of GStreamer is a must. This article describes how to use GStreamer on Torizon OS to create simple pipelines executed on CPU.
While video processing can also be offloaded to a Video Processing Unit (VPU) for performance and efficiency gains, this article focuses solely on CPU-based processing. Currently, instructions for VPU usage are not covered in the Toradex Developer Center. If you need help or want to share details about VPU-based pipelines, we encourage you to contact us on Toradex Community.
For a comprehensive overview of GStreamer, see Video Processing - GStreamer.
The article Video Encoding and Playback (Linux) is not specific for Torizon, but some instructions may be applicable. For example, generic information about Wayland/Weston is provided.
The article How to use Cameras on Torizon aims to help you with instructions about the configuration and usage of cameras in the context of containers, using Gstreamer pipelines and Video4Linux2.
This article complies with the Typographic Conventions for Torizon Documentation.
Prerequisites
- A Toradex System on Module with Torizon OS installed.
- A configured build environment, as described in the Configure Build Environment for Torizon Containers article.
- It is recommended to use the Torizon IDE Extension for application development.
Wayland + Weston
This example runs a pipeline that uses waylandsink GStreamer's plugin. This plugin runs on top of Wayland and Weston. It is necessary to start 2 containers: One with the Weston image, and one with the application image, with Wayland support. They communicate through shared folders by bind mounting.
Dockerfile instructions
The implementation details will be explained in this session. See the Quickstart Guide with the instructions about how to compile the image on a host pc and pull the image onto the board. You can also scp
this file to the board and build it locally.
Building the Container Image
Make sure you have configured your Build Environment for Torizon Containers.
Now it's a good time to use torizon-samples repository or download the sample Dockerfile:
$ cd ~
$ git clone --branch bookworm https://github.com/toradex/torizon-samples.git
$ cd ~/torizon-samples/gstreamer/bash/simple-pipeline
And build the container image:
$ docker build --build-arg BASE_NAME=wayland-base-vivante --build-arg IMAGE_ARCH=linux/arm64/v8 -t <your-dockerhub-username>/gst_example .
Now it's a good time to use torizon-samples repository or download the sample Dockerfile:
$ cd ~
$ git clone --branch bookworm https://github.com/toradex/torizon-samples.git
$ cd ~/torizon-samples/gstreamer/bash/simple-pipeline
And build the container image:
$ docker build -t <your-dockerhub-username>/gst_example .
Now it's a good time to use torizon-samples repository or download the sample Dockerfile:
$ cd ~
$ git clone --branch bookworm https://github.com/toradex/torizon-samples.git
$ cd ~/torizon-samples/gstreamer/bash/simple-pipeline
And build the container image:
$ docker build --build-arg BASE_NAME=wayland-base-am62 --build-arg IMAGE_ARCH=linux/arm64/v8 --build-arg IMAGE_TAG=3 -t <your-dockerhub-username>/gst_example .
After the build, push the image to your Dockerhub account:
$ docker push <your-dockerhub-username>/gst_example
Details about the Dockerfile
In this section, you will go through some important snippets containing information about the Dockerfile.
Toradex Debian image - Wayland
Toradex provides a basic image with Wayland libraries on its Dockerhub page.
Ensure you use a the container image and tag compatible with your Torizon OS version.
Select the correct image for your module from the tabs below:
FROM torizon/wayland-base-vivante:3
FROM torizon/wayland-base:3
FROM torizon/wayland-base-am62:3
Install GStreamer application and plugins
Install the required packages on the image with the following commands:
RUN apt update
RUN apt install -y libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
RUN apt update
RUN apt install -y libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-pulseaudio
RUN apt update
RUN apt install -y libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
Test GStreamer
We will set gst-launch-1.0
as entrypoint for our Dockerfile with a default pipeline. A test source pattern will be output to a Wayland window.
ENTRYPOINT ["gst-launch-1.0"]
CMD ["videotestsrc", "!", "videoconvert", "!", "videoscale", "!", "waylandsink", "sync=false"]
You can modify the pipeline for your needs by adding it after the container name in the docker run
command. For example:
docker run -it --rm -v /tmp:/tmp -v /dev:/dev <your-username>/gst_example videotestsrc ! videoconvert ! videoscale ! waylandsink sync=false
Docker-compose
After building the Dockerfile image above and pushing it to your Dockerhub, you can launch Weston and Wayland with docker-compose.
Select your architecture from the tabs:
The docker-compose file for arm64v8 is available on GitHub.
Still on the torizon-samples/gstreamer/bash/simple-pipeline
directory, edit the docker-compose.arm64.yaml
file by filling the wayland's service image field with your dockerhub username:
wayland:
depends_on:
weston:
condition: service_healthy
image: <your-username>/gst_example
volumes:
- /tmp:/tmp
- /sys:/sys
- /dev:/dev
restart: on-failure
After filling it, send it to your module using scp
:
$ scp docker-compose.arm64.yaml torizon@<SoM-ip>:/home/torizon
Now enter your module using SSH:
$ ssh torizon@<SoM-ip>
Now you can launch by using the command:
# docker-compose -f docker-compose.arm64.yaml up
The docker-compose file for arm32v7 is available on GitHub.
Still on the torizon-samples/gstreamer/bash/simple-pipeline
directory, edit the docker-compose.armhf.yaml
file by filling the wayland's service image field with your dockerhub username:
wayland:
depends_on:
weston:
condition: service_healthy
image: <your-username>/gst_example
volumes:
- /tmp:/tmp
- /sys:/sys
- /dev:/dev
restart: on-failure
After filling it, send it to your module using scp
:
$ scp docker-compose.armhf.yaml torizon@<SoM-ip>:/home/torizon
Now enter your module using SSH:
$ ssh torizon@<SoM-ip>
Now you can launch by using the command:
# docker-compose -f docker-compose.armhf.yaml up
The docker-compose file for the Colibri iMX7 is available on GitHub.
Still on the torizon-samples/gstreamer/bash/simple-pipeline
directory, edit the docker-compose.colibri-imx7.yaml
file by filling the wayland's service image field with your dockerhub username:
wayland:
depends_on:
weston:
condition: service_healthy
image: <your-username>/gst_example
volumes:
- /tmp:/tmp
- /sys:/sys
- /dev:/dev
restart: on-failure
After filling it, send it to your module using scp
:
$ scp docker-compose.colibri-imx7.yaml torizon@<SoM-ip>:/home/torizon
Now enter your module using SSH:
$ ssh torizon@<SoM-ip>
Now you can launch by using the command:
# docker-compose -f docker-compose.colibri-imx7.yaml up
The docker-compose file for AM62 is available on GitHub.
Still on the torizon-samples/gstreamer/bash/simple-pipeline
directory, edit the docker-compose.am62.yaml
file by filling the wayland's service image field with your dockerhub username:
wayland:
depends_on:
weston:
condition: service_healthy
image: <your-username>/gst_example
volumes:
- /tmp:/tmp
- /sys:/sys
- /dev:/dev
restart: on-failure
After filling it, send it to your module using scp
:
$ scp docker-compose.am62.yaml torizon@<SoM-ip>:/home/torizon
Now enter your module using SSH:
$ ssh torizon@<SoM-ip>
Now you can launch by using the command:
# docker-compose -f docker-compose.am62.yaml up