xuv's notebook

Side notes, howtos and random bits of information related to Julien Deswaef's projects

User Tools

Site Tools


projects:raspi_video_loop

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
projects:raspi_video_loop [2013/05/27 13:42] – [Future?] Julien Deswaefprojects:raspi_video_loop [2015/03/25 04:06] (current) – [OMXplayer] Julien Deswaef
Line 1: Line 1:
 ====== Raspberry Pi Video Loop ====== ====== Raspberry Pi Video Loop ======
  
-For a video installation by [[http://pinksyrup.com/|PinkSyrup]], I was asked to configure a Raspberry Pi to play a HD 1080p 48s video in a perfect loop at startup. Although, this seems to be an easy task, we ran into some problems and found some temporary solutions. The page here discribes my learning process.+For a video installation by [[http://pinksyrup.com/|PinkSyrup]], I was asked to configure a Raspberry Pi to play a HD 1080p 48s video in a perfect loop at startup. Although, this seems to be an easy task, we ran into some problems and found some temporary solutions. This page here was mostly describing my learning process.
  
-===== XBMC =====+But after a year, there has been a lot of development going on everywhere. And now there is multiple solutions available. Although the one and only that would make everyone happy is not working (yet).  
  
-XBMCa media center that has been adapted for the Rapsberry Pi seemed a nice starting point to get a video loopingBut although it works great as a media centerit doesn't offer the video loop feature we hoped for. And it also loads unnecessary interfaces and menus we didn't need for this project. So we switched to a default Raspbian OS.+**First question: does your video needs sound or not?**\\ 
 +If it does not have soundjump immediatly to the [[#hello_video | hello_video]] solution. It's the quick and easy one that has been working since day one. 
 + 
 +If you need soundthen there is multiple ways with different results and coding styles: [[#bash_scripting|Bash scripting]], [[#python_scripting|Python]] or [[#openframeworks_ofxomxplayer|C++]].
  
  
 ===== OMXplayer ===== ===== OMXplayer =====
  
-Omxplayer is the default video player for the RasPi, but it doesn't have a "loop" option (yet).+Omxplayer is the default video player for the RasPi.
  
 The advantage of the OMXplayer is that you don't need to start an X server to play a video. It fully uses the GPU capabilites of the Raspi, which makes it a fast and reliable player for full HD video. It also plays sound with the video. The advantage of the OMXplayer is that you don't need to start an X server to play a video. It fully uses the GPU capabilites of the Raspi, which makes it a fast and reliable player for full HD video. It also plays sound with the video.
  
-The "no loop" feature has been a problem for many users (just search for "OMXplayer loop" and you'll find countless forum posts). Many have opted for a bash script that checks if the omxplayer has finished playing and then relaunch it. But this raises 2 problems. First, you have about a one second delay between each loop. Second, the terminal is visible during that delay, which is quite visually disturbing. That second problem is often "solved" by turning terminal font colors to black. But this isn't pretty, anyway.+OMXPlayer has "loop" option.
  
-==== Future? ====+  omxplayer --loop  video.mp4 
 +   
 +But (still not | or yes | or partly see issue [[https://github.com/popcornmix/omxplayer/issues/187|#187]]) working with this version: 
 +   
 +  Build date: Sat, 22 Mar 2014 20:58:15 +0000 
 +  Version   : 39e6342 [master] 
 +   
 +Developpment happens here: https://github.com/popcornmix/omxplayer
  
-I hope that in the near future, omxplayer will have that loop feature added to it. Which will solve many of these crude hacks. Bendenoz has been working on a [[https://github.com/bendenoz/omxplayer/commit/cd47dbb47cfa1a2ef2d5a8ca3f80e1348a76fa49|fix]] to get the loop working. But I haven't had the time and energy to compile and test it. And it's been [[https://github.com/huceke/omxplayer/pull/135/commits|waiting for a merge since March 15, 2013]]+Bendenoz has been working on a [[https://github.com/bendenoz/omxplayer/commit/cd47dbb47cfa1a2ef2d5a8ca3f80e1348a76fa49|fix]] to get the loop working. But I haven't had the time and energy to compile and test it. 
  
-There seems to be a custom build of Benedoz solution + other features at http://pasky.or.cz/dev/omxplayer/+Until this "loop" option is working in the official version, we'll have to come with other tricks. 
 + 
 +**March 2015** : Visited back the repo, and it seems the loop option works now, with some limitations and some bugs as indicated by [[https://github.com/jvcleave/ofxOMXPlayer/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+loop|some issues]].  
 + 
 +==== Bash scripting ==== 
 + 
 +This script will start an instance of omxplayer and will watch it. When omxplayer has finished playing the video clip, a new instance playing the same clip is created. And so on...
  
-===== Hiding the terminal ===== 
-A prettier solution to hide the terminal has been suggested to me by Jakob Wierzba: 
 <code=bash> <code=bash>
-setterm -blank 1+#!/bin/sh 
 + 
 +SERVICE='omxplayer' 
 +while true; do 
 +if ps ax | grep -v grep | grep $SERVICE > /dev/null 
 +then 
 +echo "running" # >> /dev/null 
 +else 
 +omxplayer -o hdmi /path/to/your/video/file/video.mp4 & 
 + 
 +fi 
 +done
 </code> </code>
-This command tells the terminal to hide itself after 1 minute of inactivity. This means the terminal will be again visible when needed by just pressing a key. Way more usefull and convenient that settings fonts to black. 
-Insert this in your bash startup script. 
  
-===== hello_video example =====+But this raises 2 problems. First, you have about a one second delay between each loop. Second, the terminal is visible during that delay, which is quite visually disturbing. That second problem is often "solved" by hiding the terminal. 
 + 
 + 
 +==== Python scripting ==== 
 +Ellen has come with a pythonic solution. She describes it here: http://www.sundh.com/blog/2013/10/loop-videos-seamlessly-omxplayer/  
 + 
 +I have not taken the time to try it out. It uses pyomxplayer to control multiple instances of OMXPlayer started at once. The idea is that you would start one instance while maintaining another one on pause. Then watch the first instance and right before it reaches the end of the video, start the second one. And so on. 
 + 
 +===== openFrameworks + ofxOMXPlayer ===== 
 + 
 +[[http://www.openframeworks.cc|openFrameworks]] is a C++ framework for artists and coders. There is a version of it that you can install on RaspberryPi (with Raspbian). 
 + 
 +And [[https://github.com/jvcleave/ofxOMXPlayer|ofxOMXPlayer]] is an addon by Jason Van Cleave that brings the hardware accelerated video display to openFrameworks for RasPi. 
 + 
 +You will need to [[http://www.openframeworks.cc/setup/raspberrypi/Raspberry-Pi-Getting-Started.html|install a lot of libraries]] and take some time to compile openFrameworks. But the basic examples that come with ofxOMXPlayer addon all work and have a video loop function working. 
 + 
 +The advantage of using openFrameworks is that you can do more than just loop videos and have overlay text, logos, etc... But, though openFrameworks prepares a lot for its users, this requires some knowledge of C++. 
 + 
 +===== hello_video =====
 In the default installation of the Raspbian OS, you'll find many code examples written in C to start coding with the RasPi. Those examples are located at /opt/vc/src/hello_pi/ In the default installation of the Raspbian OS, you'll find many code examples written in C to start coding with the RasPi. Those examples are located at /opt/vc/src/hello_pi/
  
Line 52: Line 93:
  
 With the hello_video.bin file that is generated, you'll only be able to play videos encoded in h264 with no sound. But you'll have a perfect loop, with no gap. With the hello_video.bin file that is generated, you'll only be able to play videos encoded in h264 with no sound. But you'll have a perfect loop, with no gap.
 +
 +===== GStreamer =====
 +I've heard of a [[https://github.com/sailfishos/gst-omx|GST-OMX]] plugin for gstreamer. So it seems GStreamer would talk directly to the GPU and be a good candidate for video playback on the Raspi, with the added features that GStreamer can offer. I have yet to try this option. If you have some feedback, don't hesitate to fill the page with your findings.
 +
 +
 +===== Useful tricks =====
 +
 +==== Hiding the terminal ====
 +A prettier solution to hide the terminal has been suggested to me by Jakob Wierzba:
 +<code=bash>
 +setterm -blank 1
 +</code>
 +This command tells the terminal to hide itself after 1 minute of inactivity. This means the terminal will be again visible when needed by just pressing a key. Way more usefull and convenient that settings fonts to black.
 +Insert this in your bash startup script.
 +
 +You'll need to write this command in your /etc/rc.local file to work at startup.
 +
  
 ==== Transcoding a video to h264 ==== ==== Transcoding a video to h264 ====
-This hello_video example is quite strict on what type of video file can be played. If your video file is in a mp4 container, it won't play. The easiest solution to get a working file for me was to start with a list of jpeg files with a 1920 x 1080 resolution and to process it with ffmpeg. Here's the code that worked for me:+This [[#hello_video|hello_video]] example is quite strict on what type of video file can be played. If your video file is in a mp4 container, it won't play. The easiest solution to get a working file for me was to start with a list of jpeg files with a 1920 x 1080 resolution and to process it with ffmpeg. Here's the code that worked for me:
  
 <code bash> <code bash>
Line 82: Line 140:
 sudo reboot sudo reboot
 </code> </code>
- 
-You're done ;) 
  
  
    
  
projects/raspi_video_loop.1369654932.txt.gz · Last modified: 2013/05/27 13:42 by Julien Deswaef