You are not logged in.

#1 2015-12-04 23:27:35

5591
Member
Registered: 2015-12-04
Posts: 2

Keep mplayer/ffmpeg/vlc running as a service

Okay, I'm running in circles now.

I'm trying to create a digital sign that boots from a flash drive into a modified archiso image to display a video stream.

Everything from boot to stream works great, but as soon as it loses connectivity the stream drops, the media player (i'm not tied to any in particular) exits and then nothing. I have a cron job that asks "are you running? no? okay start" every minute, but that seems like a hack. What I would ideally like to do is run a systemd service that handles the initial execution and future restarts.

Right now I have a very barebones service that runs and then restarts a script:

[Unit]
Description=Run video stream

[Service]
ExecStart=/usr/local/bin/stream.sh
Restart=always

[Install]
WantedBy=multi-user.target

stream.sh contains:

#!/bin/bash

export DISPLAY=:0

mplayer -fs [stream address]

The system setup is a bare archiso plus xorg, i3, and mplayer.

I was able to get all of the monitors on my dev machine to turn black with a cursor (and access to the now-invisible apps below) by prepending the mplayer command directly with DISPLAY=:0, but no video. I am able to get mplayer to play properly by sshing into the box as the same user and running the script as-is by hand. Everything is being ran as root (out of desperation).

This is the first time i've worked with creating systemd services, though I have googled and searched and rtfm-ed for a few days now. I may still be ignorant to something simple.

Does anyone have any ideas?


Thank you in advance!

Offline

#2 2015-12-05 12:39:35

esa
Member
Registered: 2011-12-29
Posts: 143
Website

Re: Keep mplayer/ffmpeg/vlc running as a service

You might want to try:

[service]
Type=oneshot
RemainAfterExit=yes

hth


Author of: TUI (Text User Interface for scripts), VHS (Video Handler Script, using ffmpeg) and YASSI (Yet Another Simple Script Installer)

Offline

#3 2015-12-05 12:42:45

c0mm0ner
Member
Registered: 2015-11-09
Posts: 93

Re: Keep mplayer/ffmpeg/vlc running as a service

Are there any error messages in the journal, when you try to start the unit?

Offline

#4 2015-12-05 15:14:32

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,304

Re: Keep mplayer/ffmpeg/vlc running as a service

I would use a user service not a system service.
I tested that service put in ~/.config/systemd/user :

$ cat videostream.service
[Unit]
Description=Run video stream

[Service]
ExecStart=/usr/bin/vlc http://teleclub.fr/gloubi.mp4
Restart=always

the line

export DISPLAY=:0

is no longer required, because the DISPLAY variable is already exported from /etc/X11/xinit/xinitrc.d/50-systemd-user.sh normally launched in the .xinitrc script.

I tested that with:
systemctl --user start videostream

If I quit vlc manually, it is restarted as expected.

To have the service starting after login, you need to enable it with:

systemctl --user enable videostream.

Offline

#5 2015-12-05 15:23:24

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: Keep mplayer/ffmpeg/vlc running as a service

Why even make this a service?  Just run it in a loop:

while :; do mplayer -fs [stream address]; done

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2015-12-07 16:13:02

5591
Member
Registered: 2015-12-04
Posts: 2

Re: Keep mplayer/ffmpeg/vlc running as a service

Yes! The user service was exactly what I needed, thank you berbae. I combined that with Trilby's while loop, thank you as well! I'll be impressed if this thing finds a way to stop running.

--

Dear future googler, binger, seeker of how to keep a video running, here is my service file. I'm not yet sure entirely of what I'm doing, but this worked:

~/.config/systemd/user/stream.service

[Unit]
Description=Run video stream

[Service]
ExecStart=
ExecStart=/opt/stream.sh
Restart=always
RestartSec=10

The RestartSec was important in my case, systemd seems to protect itself from endless loops of failure (mplayer gives up quickly after a dropped connection)


/opt/stream.sh

#!/bin/bash

mplayer -fs [url]

Enable:

$ systemd enable --user stream.service

I don't want to be spreading misinformation, so if anyone would like to add to this please do - I just hate to end this thread with "Now it works, okay bye"

Thanks again!

Last edited by 5591 (2015-12-07 16:14:13)

Offline

Board footer

Powered by FluxBB