IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Raspberry Pi – Video loop

    Ghislain Côté发表于 2014-11-17 07:52:37
    love 0

    Here is a nice week-end project, useful for automatic presentations, restaurant menus and waiting room video entertainment/marketing/information (my case).

    I used a 32″ TV with a Raspberry Pi B (512 Mb RAM), a Wifi Adapter and a 64 Gb SD card (40 $CND at Costco) to create a simple video looping device.

    My goal is simple, I want to use SFTP to upload videos in a folder, and have a simple Debian service loop and play each video file one by one.

    Since I am not always here to restart the service, a simple reboot of the Pi (by unplugging) should restart the whole thing. No technical knowledge required !

    Here is how I done it:

    1. Create nice corporate information slide deck
      • I suggest creating a visually interesting Powerpoint Presentation, with FULLY automated transitions and animation.
      • Test the presentation in Powerpoint.
      • Once it is perfectly tuned, export the Powerpoint to a MP4 video (sadly, only possible on Windows, not MAC OS)
    2. Setup the system
      • Install Raspbian with NOOBS on my 64Gb SD Card
      • Log-in with the pi user
      • If needed, setup wifi
        • type : startx
        • In LXDE, use the “Wifi” tool to setup the network
        • Exit LXDE
        • Reboot (sudo shutdown -r 0)
      • As a principle, I always upgrade the debian package and install vim (both are optional)
        • sudo aptitude upgrade
        • sudo aptitude install vim ctags
      • As we will use the CLI based Raspberry Pi Video player, omxplayer, there is no need for other software.
    3. Create the looping “application” (2 scripts and a folder)
      • Create a /home/pi/movies folder
      • Use your favorite SFTP client (ex: Mozilla) to push the corporate and other movie files to the Pi
      • Create the loop script (mine is named ~/declicTV/videoplayer.sh):
    4. mkdir /home/pi/declicTV
      cd /home/pi/declicTV
      vi videoplayer.sh

    The code is greatly inspired from here.
    I have made a few improvements:

    #!/bin/sh
    #first version from http://www.cenolan.com/2013/03/looping-video-playlist-omxplayer-raspberry-pi/
    
    # set here the path to the directory containing your videos
    VIDEOPATH="/home/pi/movies" 
    
    # you can normally leave this alone
    SERVICE="omxplayer"
    SERVICE_OPTS="-o hdmi -n 3 -b"
    
    # now for our infinite loop!
    while true; do
            if ps ax | grep -v grep | grep $SERVICE > /dev/null
            then
            sleep 1;
    else
            for file in $VIDEOPATH/*
            do
                    #debug
                    echo $SERVICE $SERVICE_OPTS "$file"
                    
                    #Display Files
                    $SERVICE $SERVICE_OPTS "$file"
            done
    fi
    done
    • Then, it is a simple matter of adding a script to init.d, just like explained here.
      • Don’t forget the update-rc.d part.
      • Here is my init.d declicTV script:
    #! /bin/sh
    # /etc/init.d/declicTV
    # taken from http://www.debian-administration.org/article/28/Making_scripts_run_at_boot_time_with_Debian
    
    # Some things that run always
    touch /var/lock/declicTV
    
    # Carry out specific functions when asked to by the system
    case "$1" in
      start)
        echo "Starting script declicTV "
        nohup /home/pi/declicTV/videoplayer.sh > /home/pi/declicTV/videoplayer.log &
        ;;
      stop)
        echo "Stopping script declicTV"
        killall -9 -r videoplayer.sh
        ;;
      *)
        echo "Usage: /etc/init.d/declicTV {start|stop}"
        exit 1
        ;;
    esac
    
    exit 0

    I hope this will be helpful to you !



沪ICP备19023445号-2号
友情链接