omxplayer play controls / input

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=38&t=7987

omxplayer play controls / input

 

58 posts   Page 1 of 3   123
by alanpich » Sat Jun 09, 2012 9:23 pm
I’m working on setting up a mediacentre controlled over http (through a smartphone web interface). Have successfully got omxplayer set up and running to play a video on command from the web server, however i can’t seem to find any way to interact with the player while its running.

Does omxplayer have any facility for user input (play/pause/fast-forward/volume etc) via a command or pipe input?

Posts: 9
Joined: Sat Jun 09, 2012 9:20 pm
by dom » Sat Jun 09, 2012 9:31 pm
You can ssh in to pi, and then the keypresses work for play/pause/skip.

However it would be nice to have a http interface for control like xbmc.

Moderator
Posts: 3563
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by alanpich » Sat Jun 09, 2012 10:39 pm
cheers for the speedy reply dom, but keypresses alone don’t seem to do anything… do i need to echo them to a display or a pipe or what? typing into an ssh shell alone wont/doesnt do anything surely?
Posts: 9
Joined: Sat Jun 09, 2012 9:20 pm
by dom » Sat Jun 09, 2012 11:17 pm
Yes, from ssh shell that launches omxplayer, typing ‘q’ will quit, left will skip backwards, right will skip forwards etc.
Moderator
Posts: 3563
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by alanpich » Sat Jun 09, 2012 11:40 pm
ah yes… not quite sure how i missed that… thnx…

next question… d’ya rekkon i could pipe that input into it from a different shell session?

Posts: 9
Joined: Sat Jun 09, 2012 9:20 pm
by KenT » Sun Jun 10, 2012 10:19 am
Tried controlling omxplayer using Putty on a Windows laptop, a Fedora/LXDE laptop, and also on the pi as localhost. However no success.

I can run the video and ^C stops it but it does no respond to keypresses while running. I am using the .deb version of omxplayer.

Any ideas what I might be doing wrong.

I’m trying to do something similar to Alan but I want to eventually use buttons attached to the GPIO for play and pause

Alan, could use a python or php ssh client package running from the webserver, I would use one to poll the GPIO.

Pi Presents – A display package for museums, visitor centres, and more
Download from http://pipresents.wordpress.com
Posts: 439
Joined: Tue Jan 24, 2012 9:30 am
Location: Hertfordshire, UK
by alanpich » Sun Jun 10, 2012 8:35 pm
OK managed to get input into omxplayer from a separate process, albeit by a rather convoluted method. If anyone has any ideas about improving/streamlining the process please let me know, as i cant help but feel this method is somewhat wasteful…

For reference this is the Debian img from the download page.

rPI boots up, autologin and starts a script process (lets call it runtime.php – i wrote it in php cos it’s what i know best)
The script process basically runs in an infinite loop, sleeping for half a second each time, checking a certain file (lets call it input.txt) for changes, and running functions based on the updated content…

A separate php script running on an apache server (for the web interface) sends commands to input.txt (e.g. play file, pause, ffwd, rewind)

Now the convoluted part… back in runtime.php, when a play command is received, it opens up an ssh shell via php-ssh2 to itself, and runs the omxplayer command through that. This means that there is a persistent connection to omxplayer to pass commands to.

Next, when a pause command is passed from the web server, via input.txt, to runtime.php, it then writes a ‘p’ to the ssh shell (which at this point is listening for omxplayer). This has the desired effect of pausing the player.

As I said, it works, but just seems over complicated. Plus i cant get the volume to work (but that might just be omx). I’ve attached an image of the process flow as best as i can describe it visually -

flowchart.jpg
Attempt at a process flow diagram
flowchart.jpg (59.52 KiB) Viewed 17752 times
Posts: 9
Joined: Sat Jun 09, 2012 9:20 pm
by ratherDashing » Tue Jun 12, 2012 1:51 am
I would love to see some more control over omxplayer. I hate that you have to start the video at the beginning and just keep on hitting the right key until you get to the part you wanted to watch. Very tedious.
Posts: 37
Joined: Tue Jun 05, 2012 3:00 am
by slackstone » Tue Jun 12, 2012 6:16 pm
I’m following this thread with interest. It would be great if you could pipe commands to the omxplayer. I’ve tried to echo “p” to /dev/tty which works but omxplayer doesn’t see the key. Someone on IRC gave the suggestion of using FIFO to accomplish this. Piping commands (keys) between processes is a move I’ve never done before so I’ve had no luck with this — yet. If anyone has a good idea on how to accomplish please share. (syntax sample)

Seems like there should be a simpler solution to what’s presented above.

Also, omxplayer on RPI is great! does a fine job at playing my collection.

User avatar
Posts: 1
Joined: Sat Jun 02, 2012 2:33 am
by joeh » Tue Jun 12, 2012 9:34 pm
Ok I had some success with the following (running standard debian image);

mkfifo /tmp/cmd

omxplayer -ohdmi mymedia.avi < /tmp/cmd

echo . > /tmp/cmd (Start omxplayer running as the command will initial wait for input via the fifo)

echo -n p > /tmp/cmd – Playback is paused

echo -n q > /tmp/cmd – Playback quits

Would really like to get this running via a simple web interface alongside airplay, I currently have shairport running on the standard debian image for audio streaming and would like to try getting airplay video (via airplayer.py) streaming to enable me to play videos off my NAS via a web interface or streaming services like iPlayer via an iPad.

Posts: 6
Joined: Tue Jun 12, 2012 9:29 pm
by alanpich » Wed Jun 13, 2012 7:12 am
Ahhh now thats the method i was looking for! Bugger all this ssh-to-self malarkey! Will be rewriting to version 2 this weekend then!

Easiest way to control over http would be set up a lamp server and use php to issue the shell commands via ajax requests from a browser. Working on my own implementation using a Sencha Touch SDK for a proper app styley ui =)

As for nas playback, the easiest solution i found was to use fusesmb (sudo apt-get install fusesmb). It will scan the local network for windows shares and mount all of them in a specified directory. That way omxplayer will be playing ‘local’ files and roberts-your-relative.

Posts: 9
Joined: Sat Jun 09, 2012 9:20 pm
by joeh » Wed Jun 13, 2012 9:05 am
Alanpich

Would love to look at your web interface if your willing to share !

Posts: 6
Joined: Tue Jun 12, 2012 9:29 pm
by alanpich » Wed Jun 13, 2012 9:31 am
Once it’s built i’ll post some screenies or a demo somewhere. It’s just ugly text/html atm till i got the control interface sorted.

I’ll see if i can put together an easy-install javascript/php for omxplayer

Posts: 9
Joined: Sat Jun 09, 2012 9:20 pm
by joeh » Wed Jun 13, 2012 6:03 pm
Ok here’s the the very basic scripts I put together based on using a fifo to control omxplayer it allows me to select a video from a form, play it then pause or stop playback from a web browser;

============= index.cgi ============
#!/bin/bash -e
echo “Content-type: text/html”
echo “”
echo “<html><body>”
echo “<h3>Movie Player</h3>”
echo “<br>”
echo “<form action=”/cgi-bin/check.cgi” method=”get”>”
echo “<select name=”movie”>”
for myfiles in /mnt/media/Videos/LowDef/*
do
video=$(basename “$myfiles”)
echo “<option>$video</option>”
done
echo “<input type=”submit” value=”Play” />”
echo “</select></form></body></html>”

================check.cgi=================
#!/bin/bash
movie=`echo “$QUERY_STRING” | sed -n ‘s/^.*movie=\([^&]*\).*$/\1/p’ | sed -e ‘s/+/ /g’`
movie=”/mnt/media/Videos/LowDef/$movie”
echo “Content-type: text/html”
echo “”
echo “<html><body>”
echo “<h3>Movie Player</h3>”
echo “<br>”
echo $movie
echo “<br>”
echo “<a href=”/cgi-bin/pause.cgi”>Pause</a>”
echo “<a href=”/cgi-bin/stop.cgi”>stop</a>”
echo “<a href=”/”>Home</a></body></html>”
/var/www/cgi-bin/movie2.sh “$movie” >&- &2>-&

==============movie2.sh==============
#!/bin/bash
echo $1 > /tmp/mylog
/var/www/cgi-bin/startplay.sh&
/usr/bin/omxplayer -ohdmi “$1″ </tmp/cmd

=============startplay.sh=============
#!/bin/sh
sleep 1
echo -n . >/tmp/cmd

===========stop.cgi==============
#!/bin/sh
echo -n q >/tmp/cmd

============pause.cgi===========
#!/bin/sh
echo -n p >/tmp/cmd

Posts: 6
Joined: Tue Jun 12, 2012 9:29 pm
by nommo » Wed Jun 13, 2012 6:45 pm
I like this :)

I’m also impressed with omxplayer, great quality & performance – I also love being able to control it via command line over SSH, but my family were less impressed by me getting them to press ‘p’ on my android phone :lol:

So I wondered about hacking together an android app to act as a GUI, but implementing a web interface would be much easier!

I’d also love to be able to hack the get_iplayer web-based PVR GUI to have a button to play recorded shows in omxplayer….

And then there’s youtube with yt/whitey… ;)

Early model B with Raspbian updating Xively (was Cosm) with CurrentCost Envi plus NAS, Get Iplayer, YT (whitey) and a general ssh linux playpen plus a 512MB model B with OpenElec.
Posts: 36
Joined: Sun Jun 10, 2012 10:17 am
Location: UK
by alanpich » Wed Jun 13, 2012 8:48 pm
nice n concise joeh… far simpler than my first attempt… will definitely be taking that on board.

for those who are interested, I plan to keep my web interface source on github at https://github.com/alanpich/rPImc

I will also be maintaining an installer script to make setup from scratch a breeze:https://github.com/alanpich/rPI-media-centre-installer

Posts: 9
Joined: Sat Jun 09, 2012 9:20 pm
by XavM » Thu Jun 21, 2012 10:54 pm
This is great !! I didn’t even think about using “< fifo” for controling omxplayer

@Joeh : Did you try to write an airplayer Media Backends for omxplayer using this fifo method ?

Posts: 35
Joined: Thu May 31, 2012 11:29 pm
by XavM » Fri Jun 22, 2012 8:48 am
Just a quick update for those who could be interested.

“Right arrow” and “Left arrow” allow you to “fast forward/backward” with omxplayer.

To simulate it using fifo to control omxplayer you can :

#Right arrow :
echo -n $’\x1b\x5b\x43′ > /tmp/cmd
#Left arrow :
echo -n $’\x1b\x5b\x44′ > /tmp/cmd

“forward/backward” work when playing from the local SDCard or a plugged USB Stick, but don’t when playing from “http://”

Works with either movies or mp3 (any thing you can feed omxplayer with I guess).

—-

There is many others keys that can control volume, subtitles, etc … <- See :
https://github.com/huceke/omxplayer/blo … player.cpp

Example :
z : m_tv_show_info = !m_tv_show_info;
1 : SetSpeed(m_av_clock->OMXPlaySpeed() – 1);
2 : SetSpeed(m_av_clock->OMXPlaySpeed() + 1);
j : m_omx_reader.SetActiveStream(OMXSTREAM_AUDIO, m_omx_reader.GetAudioIndex() – 1);
k : m_omx_reader.SetActiveStream(OMXSTREAM_AUDIO, m_omx_reader.GetAudioIndex() + 1);
etc …

I have not been able to use “+” and “-” for controlling volume
This has been added just a few days ago <- See : https://github.com/huceke/omxplayer/com … 24cb828ffe
The omxplayer binaries included in Wheezy must be older than that.

I will try recompiling it using dom’s (really really quick) instructions and tell you <- see : viewtopic.php?f=2&t=5061

Last time a tried this same set of instructions for compiling XBMC, I couldn’t pass the step : “make -C tools/rbp/depends all” ; <- see :
viewtopic.php?f=9&t=5037

I always had this error on the build machine :

make[2]: /usr/local/bcm-gcc/bin/arm-bcm2708-linux-gnueabi-g++: Command not found

That is odd, assuming that the file is there :

mxav@ubuntu:~/xbmc-rbp$ ll /usr/local/bcm-gcc/bin/arm-bcm2708-linux-gnueabi-g++
-rwxr-xr-x 1 mxav mxav 245260 2012-06-21 00:49 /usr/local/bcm-gcc/bin/arm-bcm2708-linux-gnueabi-g++*

Even more surprising, I get the same error if I launch it from the command line :

mxav@ubuntu:~/xbmc-rbp$ /usr/local/bcm-gcc/bin/arm-bcm2708-linux-gnueabi-g++
bash: /usr/local/bcm-gcc/bin/arm-bcm2708-linux-gnueabi-g++: No such file or directory

@dom : if you read this post and have 1 minute to show me the way, I would really appreciate :)

XavM

Posts: 35
Joined: Thu May 31, 2012 11:29 pm
by dom » Fri Jun 22, 2012 8:58 am
@XavM
I believe the Wheezy image does include the latest omxplayer mods.
Moderator
Posts: 3563
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by BenWiley4000 » Mon Jun 25, 2012 6:20 am
So I’m a bit confused– the controls actually work for me fine out of the box, but it seems like at the end of the video I’m testing, I can’t pause or rewind/fastforward anymore. it’s like it eventually stops listening to me. any ideas?
Posts: 100
Joined: Sun Jun 24, 2012 1:36 am
by dom » Mon Jun 25, 2012 8:48 am

BenWiley4000 wrote:So I’m a bit confused– the controls actually work for me fine out of the box, but it seems like at the end of the video I’m testing, I can’t pause or rewind/fastforward anymore. it’s like it eventually stops listening to me. any ideas?

I think that is a bug in omxplayer. I believe once the file has reached EOF, but buffered data is still playing out, the keys are ignored. For high bitrate files this is only a couple of seconds, but for low bitrate it can be much longer.
Please post an issue on omxplayer GitHub.

Moderator
Posts: 3563
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by BenWiley4000 » Mon Jun 25, 2012 2:08 pm

dom wrote:

BenWiley4000 wrote:So I’m a bit confused– the controls actually work for me fine out of the box, but it seems like at the end of the video I’m testing, I can’t pause or rewind/fastforward anymore. it’s like it eventually stops listening to me. any ideas?

I think that is a bug in omxplayer. I believe once the file has reached EOF, but buffered data is still playing out, the keys are ignored. For high bitrate files this is only a couple of seconds, but for low bitrate it can be much longer.
Please post an issue on omxplayer GitHub.

thanks much! I posted an issue, hopefully it will be resolved.

Posts: 100
Joined: Sun Jun 24, 2012 1:36 am
by XavM » Tue Jun 26, 2012 12:13 pm
“+” and “-” to adjust the volume :

The Debian Wheezy Beta image does not include the last version of OMXPlayer.

I have built OMXPlayer with the last version available on Github.

This version adds “Volume control” with “+” and “-” and a few other things <- See : https://github.com/huceke/omxplayer/commits/master

You can now “echo -n + > /tmp/cmd” and “echo -n – > /tmp/cmd” to adjust the volume.

- Dirty install :
wget https://dl.dropbox.com/s/9hoxtq1ebrhd9t … ist.tar.gz
tar zxvf ./omxplayer-dist.tar.gz

- Run :
LD_LIBRARY_PATH=omxplayer-dist/usr/lib/omxplayer ./omxplayer-dist/usr/usr/bin/omxplayer.bin -o hdmi ../big_buck_bunny_1080p_h264_ac3.mkv

It works for me … it should work for you.

(I am no Linux or Cross-Compile Guru and it took me some time to go to the end of the build process with no error; If you want to do it yourself see this post : viewtopic.php?p=67235#p67235 )

XavM

Posts: 35
Joined: Thu May 31, 2012 11:29 pm
by scape » Wed Jun 27, 2012 10:30 pm
this post may be useful, it talks about using xautomation to simulate key presses and mouse moves, as well as a series of combinations of those– rather handy I think

http://stackoverflow.com/a/5714298/1298523

Posts: 15
Joined: Wed Jun 27, 2012 12:09 pm
by dododude » Sun Jul 01, 2012 7:57 pm

joeh wrote:mkfifo /tmp/cmd
omxplayer -ohdmi mymedia.avi < /tmp/cmd
echo . > /tmp/cmd (Start omxplayer running as the command will initial wait for input via the fifo)

I have been absolutely happy with controlling omxplayer via screen. It will listen to the keys, even if you moved the screen session from the vt to an ssh login and vv. Of course this doesn’t give you the full and nice automation some are looking for :-)

Try this from any shell, either the VT (no X) or a lxterminal etc:

CODE: SELECT ALL
screen
omxplayer spam.mp4
<press cursor keys to jump>
<press 'Ctrl-A d' to detach the screen session, playback continues>

Then grab another terminal, or ssh into you pi and issue

CODE: SELECT ALL
screen -r  # resumed detached screen
<use cursor keys as before>

When playback has finished, use ‘Ctrl-D’ to finish screen.

hth,
D