Friday, November 28, 2014

Using Linux as a Video Kiosk (and wrestling with VGA monitor detection)

After too many times of VLC crashing on a public video display, I decided to try the combination of Xubuntu and mplayer. After installing Xubuntu, I created the following shell script and added it to the startup through the Sessions and Startup preference panel:

mplayer -fs ~/Videos/Display.wmv -loop 0

Which will ask mplayer to play the video full screen and loop it forever.

Then I modified the settings in the Light Locker to never turn off the display, and disabled power monitoring in Power Manager. I also disabled all desktop pop-up notifications using the following command:

sudo apt-get remove notify-osd

This worked great except for two things: Xfce would only allow a max resolution of 1024x768 on any VGA connected display, which caused mplayer to play the widescreen video with bars on the top or bottom. So I tried this:

mplayer -fs -aspect 4:3 ~/Videos/Display.wmv -loop 0

...which filled the screen so the problem wasn't obvious. But the 4:3 aspect ratio would be problematic in any instance where Xfce did detect and use a widescreen resolution.
I knew the LCD panels could handle 1920x1080@60Hz, so I modified the script to use xrandr to specify, assign, and set a custom mode. Then it looked like this:

xrandr --newmode "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync
xrandr --addmode VGA1 "1920x1080_60.00"
xrandr --output VGA1 --mode "1920x1080_60.00"
sleep 1
mplayer -fs -aspect 16:9 ~/Videos/Display.wmv -loop 0

I added the sleep 1 between the resolution switch and launching the video because I was worried that mplayer might get confused otherwise. This worked great, and because all of the video displays in question are going to support 1920x1080@60Hz, I could use this anywhere. I decided to force a 16:9 aspect ratio to ensure it would fill the screen, even if we changed the video.
Then I rebooted. The script ran, but the resolution did not change, and I was back to the black bars in mplayer. It occurred to me that xrandr was trying to change the resolution to soon after the initialization of Xfce, so I added sleep 5:

sleep 5
xrandr --newmode "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync
xrandr --addmode VGA1 "1920x1080_60.00"
xrandr --output VGA1 --mode "1920x1080_60.00"
sleep 1
mplayer -fs -aspect 16:9 ~/Videos/Display.wmv -loop 0

That worked perfectly, even on a reboot. The lesson here to is to give the GUI time to load before changing the resolution.

No comments: