Page 1 of 3 123 LastLast
Results 1 to 10 of 30

Thread: HOWTO: Play Videos as Screensaver

  1. #1
    Join Date
    Oct 2006
    Beans
    9

    Smile HOWTO: Play Videos as Screensaver

    Recently I wanted to play a video as my screensaver. Thinking this would be a simple job, I set about searching. After a little time I could not find anything about using gnome-screensaver to play videos. But this has been done with xscreensaver, so I set about lifting the solution to gnome-screensaver.

    What follows was adapted from the electric sheep project to use MPlayer to render the screensaver. Two files need to be created, one .desktop that is used by the gnome-screensaver and the other is a script to select a video launch MPlayer.

    Step 1)
    Code:
    sudo apt-get install mplayer
    Its a good idea to test mplayer on a video file,
    Code:
    mplayer yourvideo.file
    just to make sure it can render well enough. If there are problems it could be the case that a different video driver is required, specified with the -vo command line argument. See MPlayer doc for more info.

    Step 2)
    Create a new file in /usr/share/applications/screensavers/ called movie.desktop,
    Code:
    sudo touch /usr/share/applications/screensavers/movie.desktop
    Then as root enter into movie.desktop
    Code:
    [Desktop Entry]
    Encoding=UTF-8
    Name=Movie
    Comment=Plays Videos
    TryExec=movie.sh
    Exec=movie.sh
    StartupNotify=false
    Terminal=false
    Type=Application
    Categories=Screensaver;
    OnlyShowIn=GNOME;
    This will be used by gnome-screensaver and specifies that the script movie.sh should be run when the screensaver is launched.

    Step 3) - movie.sh
    There are a few choice that can be made, the script I now present has a list of video files and randomly chooses one, plays it then randomly selects another and continues. It should be fairly simple to modify to suit your own purposes.

    Create the script,
    Code:
    sudo touch /usr/lib/gnome-screensaver/gnome-screensaver/movie.sh
    make it executable
    Code:
    sudo chmod 755 /usr/lib/gnome-screensaver/gnome-screensaver/movie.sh
    enter the following
    NOTE: See bootch's comment below for a better way of writing this script.
    Code:
    #! /bin/bash
    
    ## setup MPlayer aruments, remove -nosound if you want the video
    ## to play sound. If you have to specify the video driver to use
    ## then add that to the list
    MPLAYERARGS="-nosound -nolirc -wid $XSCREENSAVER_WINDOW -nostop-xscreensaver -fs -really-quiet"
    
    ## add videos to this list, one will be chosen and played, note
    ## that wild cards can be used here
    VIDEOS=( "/path/to/vid.avi" 
            /path/with/wildcard/*avi)
    
    ## child pid, no need to modify
    CPID=0
    
    ## we handle SIGTERM and SIGINT here to kill the child
    ## if active then quit.
    function ex {
        if [ $CPID -gt 0 ] 
        then
    	kill -s 9 $CPID
        fi
        exit 0
    }
    trap ex SIGINT SIGTERM
    
    ## loop while video list is not empty
    while [ ${#VIDEOS[*]} -gt 0 ] 
    do
        ## pick a random video
        VIDEO=${VIDEOS["$RANDOM % ${#VIDEOS[*]}"]}
    
        ## play video
        mplayer $MPLAYERARGS "$VIDEO" &
        CPID=$!
        ## wait for video to finish
        wait $CPID
        ## if things went wrong then exit
        if [ $? -ne 0 ]
        then
    	exit 1
        fi
        CPID=0
    done
    Please be careful when copying the code that "#! /bin/bash" is at the beginning of the file (no white space).

    This script might look complicated, but most of the code is taken up with killing mplayer when the script is killed. This could have been simplified by the use of exec but then to get a different video the screensaver has to be restarted. In a great simplification of the above script would have only one video, which would loop. See
    Code:
    #! /bin/bash
    
    ## setup MPlayer aruments, remove -nosound if you want the video
    ## to play sound. If you have to specify the video driver to use
    ## then add that to the list
    MPLAYERARGS="-nosound -nolirc -wid $XSCREENSAVER_WINDOW -nostop-xscreensaver -fs -really-quiet"
    
    ## path to video
    VIDEO=/path/to/vid
    
    exec mplayer $MPLAYERARGS -loop 0 "$VIDEO"
    Step 4)
    Configure the script by entering videos into the list VIDEOS, to understand the syntax of the list see bash arrays (http://tldp.org/LDP/abs/html/arrays.html). Make sure that quotes are not used around paths with wild cards as this stops shell expansion.

    Finally go System -> Preferences -> Screensaver and select Movie from the list. Your movie should start playing in the preview window, if not make sure the above steps were followed.

    All Done.


    To test the script remove "-wid $XSCREENSAVER_WINDOW" and "-really-quiet" from the arguments, and run the script from a terminal to see error messages.
    Last edited by kazza; March 12th, 2010 at 09:46 AM.

  2. #2

    Re: HOWTO: Play Videos as Screensaver

    hi, thnx finally for posting this information.

    I made all the steps, (had a little problem, because somehow
    I didnt correctly copy-paste the whole text to the *.desktop file.

    thank You very much


    ssuuddoo
    Slovakia
    Last edited by ssuuddoo; December 30th, 2009 at 08:40 PM. Reason: success

  3. #3
    Join Date
    Jul 2008
    Location
    /home/Microsoft_Sucks
    Beans
    104

    Re: HOWTO: Play Videos as Screensaver

    I'm having a hard time with

    MPLAYERARGS="-nosound -nolirc -wid $XSCREENSAVER_WINDOW -nostop-xscreensaver -fs -really-quiet"




    The part that is giving me errors is:

    -wid $XSCREENSAVER_WINDOW


    the "$XSCREENSAVER_WINDOW" is doing it.

    I am using CentOS 5 and would have posted in the CentOS forums, but I used to use ubuntu so I decided to post here, since you created the script, I figured you'd know the script better than anyone else.


    So, how exactly do I define the variable $XSCREENSAVER_WINDOW


    Thanks,

    SSVegito888
    Last edited by SSVegito888; February 4th, 2010 at 03:39 PM.

  4. #4
    Join Date
    Mar 2010
    Beans
    1

    Re: HOWTO: Play Videos as Screensaver

    Thanks a lot for this HOWTO.

    Also to make the script a lot shorter but still have a random list of videos you can use the playlist function of MPlayer :

    The script :
    Code:
    #! /bin/bash
    
    ## setup MPlayer aruments, remove -nosound if you want the video
    ## to play sound. If you have to specify the video driver to use
    ## then add that to the list
    MPLAYERARGS="-nosound -nolirc -wid $XSCREENSAVER_WINDOW -nostop-xscreensaver -fs -really-quiet"
    
    exec mplayer $MPLAYERARGS -loop 0 -shuffle -playlist /path/to/playlist
    The playlist can be a simple text file with the path to a video file on each line.
    Last edited by bootch; March 10th, 2010 at 05:07 PM.

  5. #5
    Join Date
    May 2006
    Beans
    2

    Re: HOWTO: Play Videos as Screensaver

    Hey there,

    thanks for the script. Been trying to find a SaveHollywood equivalent for linux. I have a problem with your solution though.... it works well when I just preview the screensaver from the gnome-screensaver gui utility.... but when the screensaver actually starts when the computer is idle, it does not seem to work.... the screen fades to black and then it goes back to desktop and the screensaver never tries to kick in again.

    any ideas on how I might solve this or troubleshoot the issue?

    thanks

  6. #6
    Join Date
    Oct 2006
    Beans
    9

    Re: HOWTO: Play Videos as Screensaver

    Quote Originally Posted by SSVegito888 View Post
    I'm having a hard time with

    MPLAYERARGS="-nosound -nolirc -wid $XSCREENSAVER_WINDOW -nostop-xscreensaver -fs -really-quiet"




    The part that is giving me errors is:

    -wid $XSCREENSAVER_WINDOW


    the "$XSCREENSAVER_WINDOW" is doing it.

    I am using CentOS 5 and would have posted in the CentOS forums, but I used to use ubuntu so I decided to post here, since you created the script, I figured you'd know the script better than anyone else.


    So, how exactly do I define the variable $XSCREENSAVER_WINDOW


    Thanks,

    SSVegito888
    Hi SSVegito888,

    Firstly, I would have replied sooner if this was a new message as I get emailed not an edited old message that said you had solved the problem.

    The $XSCREENSAVER_WINDOW variable is defined by xscreensaver, also gnome-screensaver defines it for compatibility. Its purpose is to provide a window ID that the screen saver can draw onto.

    At a guess, the problem you are having appears to be that $XSCREENSAVER_WINDOW is not defined, so is reduced to nothing. An actual error message would be helpful.

    To test this I ran gnome-screensaver-preferances from the terminal and selected the script from the list, this way any output from the script was dumped to the terminal. At this point all that is required is a simple script that echos $XSCREENSAVER_WINDOW, if it is not defined then please look up for you system how the screen saver finds the correct window to draw onto.

    Best
    Kazza

  7. #7
    Join Date
    Oct 2006
    Beans
    9

    Re: HOWTO: Play Videos as Screensaver

    Quote Originally Posted by bootch View Post
    Also to make the script a lot shorter but still have a random list of videos you can use the playlist function of MPlayer

    ...

    The playlist can be a simple text file with the path to a video file on each line.
    A nice elegant solution, Ive added a note above for people to use this version instead.

    Also as a side issue, from a security perspective this is better as the playlist could be in the users home directory, thus they dont need root access to change the video list and each user can have there own playlist .

  8. #8
    Join Date
    Oct 2006
    Beans
    9

    Re: HOWTO: Play Videos as Screensaver

    Quote Originally Posted by hydrozen View Post
    any ideas on how I might solve this or troubleshoot the issue?
    Hi Hydrozen,

    Does it work in full screen from the gnome-screensaver-preferences dialog? If not then this would be a good place to start.

    To test, as mentioned above run gnome-screensaver-preferences from the terminal and look at the outputs.


    Also, there could be some issue with video drivers, does MPlayer work in full screen normally?

    Best,
    Kazza

  9. #9
    Join Date
    Mar 2010
    Beans
    1

    Re: HOWTO: Play Videos as Screensaver

    Have to try this but it looks complicated to me. Pardon for my ignorance. I just had my net installed. I'll try to do it. But expect me to keep asking questions everytime.
    Thanks for the tip, anyway.
    Last edited by khaye; March 12th, 2010 at 11:02 AM.

  10. #10
    Join Date
    May 2009
    Location
    los angeles, usa
    Beans
    194
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: Play Videos as Screensaver

    Yes!!

    I've been searching for a little while for GNOME video screensaver. Should have looked here first. I noticed that my wife's Vista computer - in the same home office as my Ubuntu laptop and desktop - plays videos on her standard photo screen saver, for those video files in our Photos directory.

    Now I can too!

    Thanks!!


    I used the second script and created a text file containing the videos in a folder. Works perfectly.
    kai
    The Content Management and Workflow Forum: http://www.ecmplace.com
    a turn signal is a statement, not a request

Page 1 of 3 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •