Starting GStreamer with systemd.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Starting GStreamer with systemd.

Jump to solution
285 Views
Patrick-Kim
Contributor II

There is an issue starting GStreamer with systemd.

Entering the following command produces an error message and the video doesn't appear.

Help me find a solution.

root@imx8mpevk:~# systemctl start myservice
root@imx8mpevk:~# systemctl status myservice
* myservice.service - test service
Loaded: loaded (/etc/systemd/system/myservice.service; disabled; preset: disabled)
Active: active (running) since Tue 2024-05-14 02:12:25 UTC; 7s ago
Main PID: 834 (myservice.sh)
Tasks: 2 (limit: 5574)
Memory: 5.1M
CGroup: /system.slice/myservice.service
|-834 /bin/bash /home/root/myservice.sh
`-841 sleep 10

May 14 02:12:25 imx8mpevk systemd[1]: Started test service.
May 14 02:12:25 imx8mpevk myservice.sh[834]: gst start!!
May 14 02:12:25 imx8mpevk myservice.sh[835]: Setting pipeline to PAUSED ...
May 14 02:12:25 imx8mpevk myservice.sh[835]: Failed to set pipeline to PAUSED.
May 14 02:12:25 imx8mpevk myservice.sh[835]: Setting pipeline to NULL ...
May 14 02:12:25 imx8mpevk myservice.sh[835]: Freeing pipeline ...

The same shell script works fine when executed in the console, I can see the video.

root@imx8mpevk:~# ./myservice.sh
gst start!!
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
[ 1033.191967] bypass csc
[ 1033.194381] input fmt YUV4
[ 1033.197096] output fmt YUYV
Redistribute latency...
0:00:00.8 / 99:99:99.

Here is my "myservice.service" and "myservice.sh" file.

myservice.service

[Unit]
Description=GStreamer
After=multi-user.target

[Service]
Type=simple
User=root
ExecStart=/home/root/myservice.sh
RemainAfterExit=yes
GuessMainPID=no

 

myservice.sh

#!/bin/bash

export XDG_RUNTIME_DIR=/run/user/0/
echo gst start!!
gst-launch-1.0 v4l2src device=/dev/video2 ! waylandsink

 

Please help!!

 

0 Kudos
Reply
1 Solution
225 Views
Patrick-Kim
Contributor II

Although no one was interested, I found a solution on my own and have summarized it here.

myprogram.service

[Unit]
Description=My Last Service
After=weston.service

[Service]
User=root
Environment="WAYLAND_DISPLAY=/run/wayland-0"
Environment="XDG_RUNTIME_DIR=/run/user/$(id -u root)"
ExecStart=/home/root/run.sh
Restart=on-failure
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

run.sh

echo Start GST!!

gst-launch-1.0 v4l2src device=/dev/video2 ! waylandsink

Register service

systemctl daemon-reload
systemctl enable myprogram.service

This way, it works well for me. When I reboot, the camera screen comes up automatically.

View solution in original post

0 Kudos
Reply
1 Reply
226 Views
Patrick-Kim
Contributor II

Although no one was interested, I found a solution on my own and have summarized it here.

myprogram.service

[Unit]
Description=My Last Service
After=weston.service

[Service]
User=root
Environment="WAYLAND_DISPLAY=/run/wayland-0"
Environment="XDG_RUNTIME_DIR=/run/user/$(id -u root)"
ExecStart=/home/root/run.sh
Restart=on-failure
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

run.sh

echo Start GST!!

gst-launch-1.0 v4l2src device=/dev/video2 ! waylandsink

Register service

systemctl daemon-reload
systemctl enable myprogram.service

This way, it works well for me. When I reboot, the camera screen comes up automatically.

0 Kudos
Reply