Friday, August 10, 2012

Setting up OMXPlayer GUI on the Raspberry Pi (Updated)

This is a nice little trick to get OMXPlayer to work nice and pretty within the file manager so that the keypresses work and you don't need to use the command line. 

I got my Raspberry Pi in the mail and started setting it up as a  media server with my projector, external HDDs, and sound system.

You can do this in Arch Arm or in Raspbian Wheezy (It's easier in Wheezy since in Arch you have to get LXDE and omxplayer installed).

First thing, I noticed that the resolution auto-selection script didn't work properly with my projector.
I went into /opt/vc/bin and ran:
tvservice -d /home/pi/projector
edidparser /home/pi/projector /home/pi/available

Most of the options you need to change are in /boot/config.txt

This will give you the available resolutions. Each one has a code associated with it and is either a CEA code (hdmi_group=1) or a DMT code (hdmi_group=2). Then you can set the code with the hdmi_mode=? (I like hdmi_mode=15 and hmdi_mode=5).
Sometimes audio doesn't work over HDMI. If it doesn't, set hdmi_drive=2

Overclocking the Raspberry Pi is really easy, you can definitely get up to 850 MHz by adding this into the /boot/config.txt file:
arm_freq=855
sdram_freq=500

I got up to 1 GHz easily with the following options:
over_voltage=6
arm_freq=1000
sdram_freq=500
core_freq=500

I made the mistake of installing vlc. Don't! The ARM processor can't really handle it (unless overclocked and then it's still buggy).
Use omxplayer instead.

Unfortunately omxplayer is a command line tool and that can get bothersome. To easily get around this and use it, install xterm by running:

Note: You don't have to use xterm, you can use the built in lxterminal instead by replacing xterm with lxterminal in all the examples below. However, xterm allows for the nice fullscreen option that omxplayer messes up.

sudo apt-get install xterm

Then right click one of your avi files and select open with, then click custom command line tool, type in:
xterm -fullscreen -fg black -bg black -e omxplayer -o hdmi -r %f

and check the box saying always do this so you only have to double click on any avi file in the future and it will do the same thing.


This opens up omxplayer in a new terminal so the key presses, such as p (pause) and q (quit), work. It also opens it up in fullscreen (the -r flag and the -fullscreen flag for xterm). Note: The rest of the display goes to sleep after a while so if the screen is black when the movie quits, shake the mouse or press a key to wake it up.

Omxplayer Problems

For detail on issues and how to fix them, see here:
Updating Raspberry Pi packages, kernel, and firmware (also fixing omxplayer)

If you are having problems with the video not working or not showing or the screen locking, make sure your raspberry pi is up to date by running:
sudo apt-get update && sudo apt-get upgrade

**HELP my mouse and keyboard don't work  (SOLUTION)**
If it still doesn't work, you may need to upgrade your firmware (which is generally a good idea anyways) using:
sudo apt-get -y dist-upgrade
and also 
sudo rpi-update
The guide for updating your firmware can be found here:
https://github.com/Hexxeh/rpi-update

Also make sure your gpu_mem split is at a reasonable level such as 128/128 by adding the line
gpu_mem=128
in the /boot/config.txt file in the newer firmware versions

To be able to easily find and intelligently play videos automatically, see this page:
http://stevenhickson.blogspot.com/2013/03/playing-videos-intelligently-with.html

Omxplayer Key Bindings:

  • 1 Increase Speed
  • 2 Decrease Speed
  • j Previous Audio stream
  • k Next Audio stream
  • i Previous Chapter
  • o Next Chapter
  • n Previous Subtitle stream
  • m Next Subtitle stream
  • s Toggle subtitles
  • q Exit
  • Space or p Pause/Resume
  • - Decrease Volume
  • + Increase Volume
  • Left Seek -30
  • Right Seek +30
  • Down Seek -600
  • Up Seek +600

Check out my other Raspberry Pi Fixes/How tos:
http://stevenhickson.blogspot.com/2012/10/using-raspberry-pi-as-web-server-media.html
http://stevenhickson.blogspot.com/2012/10/fixing-raspberry-pi-crashes.html

Consider donating to further my tinkering.


Places you can find me

44 comments:

  1. You should warn people that overvolting may void the warranty and/or shorten the lifetime of the pi.

    ReplyDelete
  2. actually in this case it doesnt - they have a blog entry on the official forum that says overclocking to 1ghz is fine
    rb101

    ReplyDelete
  3. excellent guide, except on some videos it seems that my sound is a bit buggy. I've tried xbmc and the files play okay, but I dont like the way the system works right now. Any tips on getting the audio sounding better?

    ReplyDelete
    Replies
    1. Describe what you mean by buggy?
      It doesn't play at all or only sometimes?

      Are you outputting sound through the HDMI or through the stereo output?

      Delete
  4. This works really well for me, up until I go to quit the video. At that point it goes to a black screen that I cant get out of. The RP is definitely still functioning in some way but I cannot get the monitor to go back to the GUI or the terminal... Any idea what I'm doing wrong?

    ReplyDelete
    Replies
    1. Is that just the display going to sleep?
      Mine goes to sleep midway through the movie (it still finishes playing the movie) but afterwards goes black and I jiggle the mouse to wake it up.

      Are you controlling the pi via SSH or with a keyboard and mouse?

      Does the pause/resume command still work? This will help diagnose the problem.

      Delete
    2. Turns out you just need to update your firmware to fix this.
      See:
      http://stevenhickson.blogspot.com/2013/02/updating-your-raspberry-pi-packages.html

      Delete
  5. I get the same problem as JayBee black screen on exit that can't get out of, any thoughts?

    ReplyDelete
    Replies
    1. Is that just the display going to sleep?
      Mine goes to sleep midway through the movie (it still finishes playing the movie) but afterwards goes black and I jiggle the mouse to wake it up.

      Are you controlling the pi via SSH or with a keyboard and mouse?

      Does the pause/resume command still work? This will help diagnose the problem.

      Delete
    2. I had the same problem with the screen blanking out when the video ends and not being able to regain control of the screen (moving mouse, hitting ctrl+c didn't work. rebooting does).

      I tried updating the firmware and after rebooting the omxplayer would no longer display any video output (audio worked).

      Thoughts?

      Delete
    3. What does the omxplayer.log file say?
      Run the commands:
      vcgencmd version
      uname -a

      And post what all of that says. Did you test it on the same file?

      Delete
  6. Same as anom and Jaybee. Command is via keyboard and mouse. After the movie ends or using q to exit. None of the key command works nor mouse. Just sits there with black screen. I can SSH into it, run another code found on another forum and it works again. It doesn't look like the pi is frozen or crashed in anyway, just not able to display anything after movie end/quits.

    ReplyDelete
    Replies
    1. Interesting. Do you see the xterm terminal come up before you play the video?

      When you double click it, you should see xterm pop up in the background and then the video pop on top of it. As long as you don't select or click something else, the key buttons and quit should work properly.

      If people keep having trouble with this, I'm just going to make a real GUI version and distribute it sometime mid-late November.

      Delete
  7. Im get the black screen aswell can it be that i used lxterminal ?

    ReplyDelete
    Replies
    1. I have not tested it with the new version with lxterminal. I will and will let you know. In the main time. Maybe install xterm with sudo apt-get install xterm and try that. Hopefully you will have better luck. And if so, I'll have to change my instructions.

      Delete
    2. Works wit lxterminal but I use xterm for the extra options still

      Delete
  8. Using xterm as described in your blog post.

    Works great, playing files over network share and CPU is just cruising at 20% (stock speed!) plus keyboard commands work.

    However.....
    Same black screen issue.

    I see xterm appear before the file plays.
    Even after 5 seconds of playing a file and I press 'q' to quit it goes to black screen. Move mouse/press key but it doesn't return to the desktop. It sort of looks like the screen has been woken up - the backlight in the monitor adjusts itself as if it were about to come back - but remains on black/blank screen.

    ReplyDelete
    Replies
    1. Have you updated at all? Because this has not been an issue for me. I have the newest version and if you have the original or an older version maybe it messes up.
      Have you tried going to the command line and running:
      sudo apt-get update && sudo apt-get upgrade

      Delete
    2. All packages are up to date. I'm on Raspbian and omxplayer is version 0.2.1~git20120916~2612f1d7

      Guess I'll take this on to github to resolve.

      Thanks for the guide though :)

      Delete
    3. Ok so to close the loop on this, perhaps useful for others, my version of omxplayer wasn't the most up to date. Although it was part of the latest raspbian image and wasn't being updated with apt.

      Using this website I removed the old version and updated to the latest build.
      http://omxplayer.sconde.net/

      All works well.

      Delete
    4. Thanks, this has been bugging me and it's really good to know. It's strange that it wouldn't update to the new build using apt.
      I'll make a note of this so people will know.

      Delete
    5. I should have specified the difference between updating the packages and updating the firmware. I have added this now.

      http://stevenhickson.blogspot.com/2013/02/updating-your-raspberry-pi-packages.html

      Delete
  9. Thank you. This is great. I did not like Raspbmc. Raspbmc is great but I did not want a media server. I just wanted to play videos. VLC did not work for me either. This solution is perfect for me. Works great to.

    Something neat with the porting. If you are connected via VNC and send the output to HDMI then the video plays on the TV and not your client. When doing a show you can hide all the "magic" on your laptop.

    ReplyDelete
  10. Hello,

    I have a Problem with the resolution. Some videos look like on the picture.
    How can I fix it?

    http://www.abload.de/img/img_20130224_121612nmrs2.jpg

    Thanks for this tutorial, except of the resolution everything works finde! :)

    ReplyDelete
    Replies
    1. I have never seen this.
      Are you packages, firmware, and distro updated to the newest version?

      http://stevenhickson.blogspot.com/2013/02/updating-your-raspberry-pi-packages.html

      Does it do this when playing the same video on a different computer (to see if it is the video or omxplayer)

      Try running it without the -r flag and see.

      Delete
    2. Ok,

      I only did this: sudo apt-get update && sudo apt-get upgrade

      I will do the rest this evening and try again.
      The Videos are not the problem. Working fine on any other device.

      Thanks for the fast anwer. I will try it and tell you the result this evening.
      Thank you! :)

      Delete
    3. Hi

      I did the updating and tried other videos both 4:3 and 16:9 but still the same.
      No -r causes white stripes at bottom and top. Any other idea?

      Delete
    4. Did you do the distribution upgrade and the rpi-update as well?

      Delete
    5. Is there a place you can upload the video so I can test it on my system. What's your resolution set at?

      Delete
    6. Yes I did rpi-update. I will upload the Video when I´m at home this evening.
      I dont know the resolution. It worked fine when I plugged in the Monitor the first time so I didn´t care about the resolution.

      Delete
  11. I tried the custom command line entry and it did not work. how can I now remove the open with entry from the menu?

    thanks

    ReplyDelete
    Replies
    1. The command line should work if you do everything correctly.
      I'm not quite sure what you are asking but if you mean how to change the default entry, then open with a different program and set it to the default.

      Delete
  12. For me the video output is from HDMI but the sound through the stereo output, can you provide me the right command so the sound could play through stereo output?
    "xterm -fullscreen -fg black -e omxplayer -o hdmi -r %f" how this command should be written???

    ReplyDelete
    Replies
    1. I believe you just need to ignore the -o hdmi flag so it should be:
      "xterm -fullscreen -fg black -e omxplayer -r %f"

      For some versions of omxplayer the default audio output is hdmi so you need to change it to this:
      "xterm -fullscreen -fg black -e omxplayer -o local -r %f"

      Delete
    2. "xterm -fullscreen -fg black -e omxplayer -r %f"

      Above command worked well thx for the quick reply!!!

      Delete
  13. This comment has been removed by the author.

    ReplyDelete
  14. hi Steve.

    I'm having the following problem:

    I use raspbian and need to put some videos on loop ~.confg/autostart/loop.desktop

    in autostart, I created the following file:

    [Desktop Entry]
    Type = Application
    Name = OMXPlayer
    Exec = /home/pi/loop.sh


    loop.sh the scrip is thus:

    #!/bin/sh

    sleep 60

    # Get rid of the cursor so we do not see it When videos are running
    # setterm-cursor off

    # Set here the path to the directory containing your videos
    VIDEOPATH = "/home/pi/videos"

    # Normally you can leave this alone
    # SERVICE = "omxplayer -o hdmi"
    SERVICE = "fullscreen xterm-bg black-fg-black-and-omxplayer the hdmi-r"


    # Now for our infinite loop!
    while true;'s
             if ps ax | grep-v grep | grep $ SERVICE> /dev/null
             then
             sleep 1;
    else
             for entry in $ VIDEOPATH/*
             of
                     clear

    ######

    It initializes the video put the keyboard does not work in omxplayer. know what might be happening to not be responding?

    tks

    ReplyDelete
    Replies
    1. I'm honestly not sure what's going on with some parts of your script. If xterm is in the background and your omxplayer and firmware are up to date, the xterm -e flag should solve for the keyboard problem.
      (Note: If you press ALT-TAB while the video is playing, xterm won't have modal control and your keypresses won't go to it)
      I would use rpi-update and sudo apt-get update && sudo apt-get upgrade make sure your firmware and packages are up to date. If it still doesn't work, post your full script via pastebin or something and I will play with it.

      Delete
  15. sorry, did not explain right.

    the problem only occurs when I put the script to start at login.

    If I run manually, it works.

    may be missing something in ~.config/autostart/loop.desktop?

    [Desktop Entry]
    Type = Application
    Name = OMXPlayer
    Exec = /home/pi/loop.sh

    I did the update and it's still not working on the keyboard omxplayer.

    ReplyDelete
    Replies
    1. Interesting. I'm going to assume you rebooted and did everything properly especially since it runs properly when run manually. And if its run manually, why do you need to make the desktop entry? Just have your script run:
      xterm -fullscreen -fg black -bg black -e omxplayer -o hdmi -r $filename
      for every file in $VideoPath and then repeat.

      Sounds like a permission or environmental thing. Are you using cron @reboot? And if so there are two things you should do:
      1) run the script as the user pi in /etc/cron.d/yourscript
      and 2) set DISPLAY=:0 in /etc/cron.d/yourscript

      Ex:

      #!/bin/sh
      #
      # cron script to check dostruff.
      #
      # Written by Steven Hickson for the dostuff script.
      #
      DISPLAY=:0

      @reboot pi dostuff

      Delete
  16. pastebin search loop omxplayer
    First on the list

    Tks

    ReplyDelete
    Replies
    1. Its not working because you are running omxplayer as the command on the newest video instead of the xterm -e variant.
      I was able to make this work the following way:
      -------------------------------------------------
      /home/pi/loop.sh:
      #!/bin/bash

      VIDEOPATH="/media/Clips"
      COMMAND="xterm -fullscreen -fg black -bg black -e omxplayer -g -o hdmi -r "

      sleep 15

      while true ;
      do
      for f in $VIDEOPATH/* ;
      do
      $COMMAND "$f"
      done
      done


      -------------------------------------------------
      /etc/cron.d/loop:
      #!/bin/sh
      #
      # cron script loop.
      #
      # Written by Steven Hickson for the loop script.
      #
      DISPLAY=:0

      @reboot pi /home/pi/loop.sh


      -------------------------------------------------

      Delete
    2. worked the way I wanted. The problem now is that the sound is not coming out neither by audio nor for hdmi

      Delete
    3. At RCA + audio, the sound works. When I put the hdmi has no sound.
      Also the sound does not come out with the following configuration HDMI + Audio

      tks

      Delete