Starting GStreamer with systemd.

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

Starting GStreamer with systemd.

Jump to solution
2,407 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
2,347 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
2,348 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
%3CLINGO-SUB%20id%3D%22lingo-sub-1864953%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EStarting%20GStreamer%20with%20systemd.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1864953%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CSPAN%3EThere%20is%20an%20issue%20starting%20GStreamer%20with%20systemd.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EEntering%20the%20following%20command%20produces%20an%20error%20message%20and%20the%20video%20doesn't%20appear.%3C%2FP%3E%3CP%3EHelp%20me%20find%20a%20solution.%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3E%3CFONT%20size%3D%222%22%3Eroot%40imx8mpevk%3A~%23%20systemctl%20start%20myservice%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3Eroot%40imx8mpevk%3A~%23%20systemctl%20status%20myservice%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3E*%20myservice.service%20-%20test%20service%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3ELoaded%3A%20loaded%20(%2Fetc%2Fsystemd%2Fsystem%2Fmyservice.service%3B%20disabled%3B%20preset%3A%20disabled)%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EActive%3A%20active%20(running)%20since%20Tue%202024-05-14%2002%3A12%3A25%20UTC%3B%207s%20ago%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EMain%20PID%3A%20834%20(myservice.sh)%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3ETasks%3A%202%20(limit%3A%205574)%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EMemory%3A%205.1M%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3ECGroup%3A%20%2Fsystem.slice%2Fmyservice.service%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3E%7C-834%20%2Fbin%2Fbash%20%2Fhome%2Froot%2Fmyservice.sh%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3E%60-841%20sleep%2010%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3EMay%2014%2002%3A12%3A25%20imx8mpevk%20systemd%5B1%5D%3A%20Started%20test%20service.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EMay%2014%2002%3A12%3A25%20imx8mpevk%20myservice.sh%5B834%5D%3A%20gst%20start!!%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EMay%2014%2002%3A12%3A25%20imx8mpevk%20myservice.sh%5B835%5D%3A%20Setting%20pipeline%20to%20PAUSED%20...%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EMay%2014%2002%3A12%3A25%20imx8mpevk%20myservice.sh%5B835%5D%3A%20Failed%20to%20set%20pipeline%20to%20PAUSED.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EMay%2014%2002%3A12%3A25%20imx8mpevk%20myservice.sh%5B835%5D%3A%20Setting%20pipeline%20to%20NULL%20...%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EMay%2014%2002%3A12%3A25%20imx8mpevk%20myservice.sh%5B835%5D%3A%20Freeing%20pipeline%20...%3C%2FFONT%3E%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3EThe%20same%20shell%20script%20works%20fine%20when%20executed%20in%20the%20console%2C%20I%20can%20see%20the%20video.%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%222%22%3Eroot%40imx8mpevk%3A~%23%20.%2Fmyservice.sh%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%222%22%3Egst%20start!!%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%222%22%3ESetting%20pipeline%20to%20PAUSED%20...%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%222%22%3EPipeline%20is%20live%20and%20does%20not%20need%20PREROLL%20...%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%222%22%3EPipeline%20is%20PREROLLED%20...%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%222%22%3ESetting%20pipeline%20to%20PLAYING%20...%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%222%22%3ENew%20clock%3A%20GstSystemClock%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%222%22%3E%5B%201033.191967%5D%20bypass%20csc%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%222%22%3E%5B%201033.194381%5D%20input%20fmt%20YUV4%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%222%22%3E%5B%201033.197096%5D%20output%20fmt%20YUYV%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%222%22%3ERedistribute%20latency...%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%222%22%3E0%3A00%3A00.8%20%2F%2099%3A99%3A99.%3C%2FFONT%3E%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3EHere%20is%20my%20%22myservice.service%22%20and%20%22myservice.sh%22%20file.%3C%2FP%3E%3CP%3Emyservice.service%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%5BUnit%5D%0ADescription%3DGStreamer%0AAfter%3Dmulti-user.target%0A%0A%5BService%5D%0AType%3Dsimple%0AUser%3Droot%0AExecStart%3D%2Fhome%2Froot%2Fmyservice.sh%0ARemainAfterExit%3Dyes%0AGuessMainPID%3Dno%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3Emyservice.sh%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%23!%2Fbin%2Fbash%0A%0Aexport%20XDG_RUNTIME_DIR%3D%2Frun%2Fuser%2F0%2F%0Aecho%20gst%20start!!%0Agst-launch-1.0%20v4l2src%20device%3D%2Fdev%2Fvideo2%20!%20waylandsink%0A%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3EPlease%20help!!%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1877864%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Starting%20GStreamer%20with%20systemd.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1877864%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EAlthough%20no%20one%20was%20interested%2C%20I%20found%20a%20solution%20on%20my%20own%20and%20have%20summarized%20it%20here.%3C%2FP%3E%3CP%3Emyprogram.service%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3E%5BUnit%5D%3CBR%20%2F%3EDescription%3DMy%20Last%20Service%3CBR%20%2F%3EAfter%3Dweston.service%3C%2FP%3E%3CP%3E%5BService%5D%3CBR%20%2F%3EUser%3Droot%3CBR%20%2F%3EEnvironment%3D%22WAYLAND_DISPLAY%3D%2Frun%2Fwayland-0%22%3CBR%20%2F%3EEnvironment%3D%22XDG_RUNTIME_DIR%3D%2Frun%2Fuser%2F%24(id%20-u%20root)%22%3CBR%20%2F%3EExecStart%3D%2Fhome%2Froot%2Frun.sh%3CBR%20%2F%3ERestart%3Don-failure%3CBR%20%2F%3EStandardOutput%3Djournal%3CBR%20%2F%3EStandardError%3Djournal%3C%2FP%3E%3CP%3E%5BInstall%5D%3CBR%20%2F%3EWantedBy%3Dmulti-user.target%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3Erun.sh%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3Eecho%20Start%20GST!!%3C%2FP%3E%3CP%3Egst-launch-1.0%20v4l2src%20device%3D%2Fdev%2Fvideo2%20!%20waylandsink%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3ERegister%20service%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3Esystemctl%20daemon-reload%3CBR%20%2F%3Esystemctl%20enable%20myprogram.service%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3EThis%20way%2C%20it%20works%20well%20for%20me.%20When%20I%20reboot%2C%20the%20camera%20screen%20comes%20up%20automatically.%3C%2FP%3E%3C%2FLINGO-BODY%3E