Sunday, December 16, 2012

Running omxplayer from the command line easily using alias

Although I have previously written about running omxplayer via GUI, sometimes I like to control it via command line.
However, since I have my raspberry pi hooked up via HDMI and I like the show to be fullscreened, this requires typing:
omxplayer -r -o hdmi FILE
each time.
In order to make this easier we can use aliases. An alias lets you run a command with a shorter command. For instance:
ll is really an alias of ls - l

You can see what aliases you have by typing alias in the command line.
To temporarily add an alias you can use the command:
alias play='omxplayer -r -o hdmi'

However, I want to permanently add this. To do that, I'll edit /home/pi/.bash_aliases
you can do this using vim or nano. Simply add the line alias play='omxplayer -r -o hdmi' to this file.

Make sure you log out and log back in for this change to be made. Now we can just type: 

play FILE

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

Consider donating to further my tinkering.


Places you can find me

15 comments:

  1. I have several movies on a usbstick that I have mounted. I can see the files but I cannot play them. Someone suggested that I try omxplayer but I can't seem to get it to work. I am using remote desktop to access my RasPi. Do I have to connect to the hdmi in order for this to work?

    Thanks.

    ReplyDelete
    Replies
    1. Can you show me your omxplayer.log file? It's in the location you ran omxplayer.
      I'm not sure what remote desktop you are using. You can't run omxplayer through SSH since DISPLAY isn't set. I'm not sure about VLC.

      Delete
    2. I am using the windows remote desktop connection. I enter the IP address and a screen comes up with Xrdp Module sesman-Xvnc. I enter the credentials and then I tried to the command above "omxplayer -r -o hdmi Alex_Cross.mp4" and it says it can't find the file. If I go to cd/media/usbstick and then ls -l it shows that movie. Thanks for you help. I am not sure how to get a log but I don't think I am even getting that far because it can't find the file.????

      Delete
    3. You should go to the directory first using cd and then tab autocomplete.
      So
      cd /media/usbstick
      omxplayer -r -o hdmi Alex[TAB]
      the rest of the file will come up. Omxplayer will still log even if the file doesn't open. The log will be in the directory you ran omxplayer in.

      Another option is to set omxplayer to work in the GUI environment.
      You can do that using this link:
      http://stevenhickson.blogspot.com/2012/08/setting-up-omxplayer-gui-on-raspberry-pi.html

      Or you can set it up to auto-find and play videos using this link:
      http://stevenhickson.blogspot.com/2013/03/playing-videos-intelligently-with.html

      Delete
    4. Thanks Steven. Well I tried the first part omxplayer -r -o hdmi Alex[TAB] and when I hit enter, it came back with "have a nice day". I will try and get the log. I am going to try one of your other options...hopefully I will have more luck there. Thanks again for all the great info.

      Delete
    5. I think this is the log:

      00:00:00 T:0 DEBUG: DllBcm: Using omx system library
      00:00:00 T:0 DEBUG: DllOMX: Using omx system library
      00:00:00 T:0 DEBUG: DllAvFormat: Using libavformat system library
      00:00:00 T:0 DEBUG: DllAvUtilBase: Using libavutil system library
      00:00:00 T:0 DEBUG: DllAvCodec: Using libavcodec system library
      00:00:00 T:0 DEBUG: DllAvFormat: Using libavformat system library
      00:00:00 T:0 ERROR: COMXPlayer::OpenFile - av_probe_input_buffer Here Comes the Boom/


      I went to cd /media/usbstick and entered view omxplayer.log
      That is what it showed. Is that how you view the log? Sorry...for all the stupid questions...just another newbee.

      Delete
    6. It looks like you tried to open a folder called "Here Comes the Boom/" hence the slash at the end. You need to open something like a .mkv or .avi or .mp4 file.

      I tend to use cat to view a file. ex: cat omxplayer.log

      Questions are fine. That's why I post things. We will try to figure this out.

      I suggest trying the omxplayer GUI option I posted if it's not too complicated since then you won't have to worry about using the command line if you don't want to.

      Delete
    7. I think I see the problem. Even though I burn the movies as mp4 the software is saving them as a .m4v

      I tried to rename Alex_Cross.m4v to Alex_Cross.mp4 but it still doesn't work. So I guess I need to try and save them as mp4 before this will work.

      Once I do this, do I need to mount the usbstick? I did it on this one but I am not sure if I have to as they showed up right when I plug in the USB.

      Thanks again.

      Delete
    8. Yeah you can't just rename them, you have to go through a process of converting them. Depending on the codecs you have available with ffmpeg, m4v should work though. I currently play m4v files successfully on my Pi.

      You do need to mount the usb stick. You can do this with the mount command or do it through the GUI. If it is not mounted, omxplayer will not be able to find the file.

      Delete
    9. Hi ...it's me again. I deleted the files that I had on the usbstick and added different ones...specifically a few that were .mp4 When I ran them I got a response back "/usr/bin/omxplayer.bin: invalid option --'_'

      It did not product a log??? Not sure what to do now. Any help is appreciated.

      Thanks.

      Trisha

      Delete
    10. You have an invalid flag somewhere probably a - by itself. If your filename has special characters or spaces, you need to put it in quotes.
      Ex.

      omxplayer -r -o hdmi "Some - Location/Some Movie.mp4"

      Delete
    11. Sorry...I am so challenged. I have stored my movies in a folder: /media/usbstick

      so from that directory I ran the following:

      omxplayer -r-o hdmi"USB20FD/Before You Buy Video large-1760217335.mp4"

      and I still get the same error. This is exactly how the file is written if I do a ls -l on /media/usbstick folder.

      Thanks. Do I have the "Some - Location" incorrect?

      Delete
    12. you need a space between the -r and -o flag and the hdmi and "

      It should be:
      omxplayer -r -o hdmi "USB20FD/Before You Buy Video large-1760217335.mp4"

      The flags require spaces between them and the hdmi option is a flag option and should be seperated.

      Delete
    13. Hi...Thanks. Finally got it. I had to plug in my hdmi monitor to the Raspi and then I was able to see the movie. So now that I have it using the command line I can try your second piece with using the gui.

      From the command line how do I stop the movie that is playing?

      Thanks again for all of your help...this is awesome!

      Delete
    14. The q key should make omxplayer quit and the space bar will make it pause. All of the extra key bindings are listed on the bottom of the GUI page.

      Delete