linux screensaver bash script to play random bits of movies in a 2x2 grid, great for longplays

Last updated on 13 years ago
acidzebra
Here is some bash code I wrote to make a playlist from all video files in a given folder (and subfolders), fill the screen with 4 mplayer screens playing the playlist in random order, and then randomly seek in a randomly chosen video/playlist every 15 seconds.

It makes for quite a spiffy 'screensaver' running on my MAME box. Don't know if anyone is running linux here, so yeah, YMMV. Anyhow, thought someone out there somewhere might have some use for it so here you are. I'm sure this could be written in a much more efficient way but I'm not really a programmer, I just pretend to be one on the internets and this is the bash scripting I know.

It is quite mesmerizing to watch. Or that might just be my short atten... ooh look a shiny!

#!/bin/sh
#
# mixvid.bash
# a shell script to display four videos from a random playlist
# and then perform random seeks both in the videos and the playlist itself
#
#
# ************************************************
# global variables, change these to fit your needs
# ************************************************
#
# this is the folder with your video files
videofolder=/mnt/arcade/video

# this is the width of your display in pixels
sizex=1024

# this is the height of your display in pixels
sizey=768

# these are the options to pass to mplayer
# if your videos don't show or are the wrong size etc
# run mplayer -vo help to see what the video out options are for your installation
# and try different ones
mplayeropts="-really-quiet -osdlevel 0 -cache 8192 -noborder -ss 25 -ao null -loop 0 -fixed-vo -slave"

# ***********************
# end of global variables
# ***********************

# remove any old playlists and create new ones
rm -f $videofolder/playlist*
cd $videofolder
find * | shuf > $videofolder/playlist1
for i in 2 3 4
do
cat $videofolder/playlist1 | shuf > $videofolder/playlist$i
done

# create the FIFOs we will use to control mplayer
for i in 1 2 3 4
do
mkfifo /tmp/mplayerfifo$i
done

# start up 4 instances of mplayer
counter=0
vidx=0
vidy=0
scalex=expr $sizex / 2
scaley=expr $sizey / 2
for y in 1 2
do
for x in 1 2
do
counter=expr $counter + 1
mplayer $mplayeropts -geometry $vidx:$vidy -vf scale=$scalex:$scaley -input file=/tmp/mplayerfifo$counter -playlist $videofolder/playlist$counter -shuffle &
vidx=expr $sizex / 2 + 1
done
vidx=0
vidy=expr $sizey / 2 + 1
done
sleep 30

# start infinite loop
while true; do
sleep 15

# generate random numbers to select a video and action to perform
RANGEA=4
video=$RANDOM
let "video %= $RANGEA"
video=expr $video + 1
RANGEB=7
action=$RANDOM
let "action %= $RANGEB"
action=expr $action + 1
case $action in
1)
  # jump random amount forward in playlist
  RANGEJ=700
  stepval=$RANDOM
  let "stepval %= $RANGEJ"
  stepval=expr $stepval + 1
  echo "pt_step $stepval 1" > /tmp/mplayerfifo$video
  sleep 2
  echo "seek 7 1" > /tmp/mplayerfifo$video
  ;;
2)
  # jump random amount backward in playlist
  RANGEJ=700
  stepval=$RANDOM
  let "stepval %= $RANGEJ"
  stepval=expr $stepval + 1
    echo "pt_step -$stepval 1" > /tmp/mplayerfifo$video
  sleep 2
  echo "seek 7 1" > /tmp/mplayerfifo$video
  ;;
[3-7])
  # jump to random point in video
  RANGES=80
  seekval=$RANDOM
  let "seekval %= $RANGES"
  seekval=expr $seekval + 5
  echo "seek $seekval 1" > /tmp/mplayerfifo$video
  ;;
esac
done
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.