piplayer
Posts: 14
Joined: Thu Dec 13, 2012 8:03 pm
Location: Melbourne, Australia
Contact: Website

Using dbuscontrol.sh to control omxplayer

Thu Sep 11, 2014 6:28 am

I build omxplayer natively from source into:
~/omxplayer/omxplayer-dist/usr/bin
I copy dbuscontrol.sh from
into the same directory.

I ssh into the Pi and launch omxplayer from ~/omxplayer/omxplayer-dist/usr/bin with:
./omxplayer --loop /home/pi/smpte.mp4 --subtitles /home/pi/smpte.srt
I open a second terminal and ssh in again and navigate to the same directory and enter:
pi@Pi4 ~/omxplayer/omxplayer-dist/usr/bin $ ./dbuscontrol.sh pause
cat: /tmp/omxplayerdbus: No such file or directory
cat: /tmp/omxplayerdbus.pid: No such file or directory
Must have DBUS_SESSION_BUS_ADDRESS
However if I enter at the command line:
ps xaf | grep -i dbus
I see that a dbus session daemon appears active for omxplayer

pi@Pi4 ~/omxplayer/omxplayer-dist/usr/bin $ ps xaf | grep -i dbus
1967 ? Ss 0:00 /usr/bin/dbus-daemon --system
2357 pts/1 S+ 0:00 \_ grep --color=auto -i dbus
2225 ? Ss 0:00 dbus-daemon --fork --print-address 5 --print-pid 6 --session
I'd appreciate a leg up so I can start experimenting with dbus control of omxplayer via bash scripting.

gkreidl
Posts: 6307
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Using dbuscontrol.sh to control omxplayer

Thu Sep 11, 2014 8:27 am

If you compiled the latest version from source, the script won't work any more. The file names for the dbus interface in /tmp have been changed and now include the user name. You can fix it by replacing the 2 line on top:

Code: Select all

OMXPLAYER_DBUS_ADDR="/tmp/omxplayerdbus.${USER}"
OMXPLAYER_DBUS_PID="/tmp/omxplayerdbus.${USER}.pid"
See: https://github.com/popcornmix/omxplayer/pull/246
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

piplayer
Posts: 14
Joined: Thu Dec 13, 2012 8:03 pm
Location: Melbourne, Australia
Contact: Website

Re: Using dbuscontrol.sh to control omxplayer

Thu Sep 11, 2014 8:55 am

Thanks. You're a legend.

gkreidl
Posts: 6307
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Using dbuscontrol.sh to control omxplayer

Thu Sep 11, 2014 9:07 am

I'm using a modified version of that script (which allows controlling multiple instances of omxplayer) from omxplayerGUI. I'll also have to change that, if the new version becomes available. And I'll have to make sure it will run with different versions of omxplayer.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

aman
Posts: 11
Joined: Wed Oct 10, 2012 6:26 am

Re: Using dbuscontrol.sh to control omxplayer

Mon Dec 15, 2014 9:36 pm

Hi

I've tried to follow the above but get the following error
dbuscontrol.sh: 16: dbuscontrol.sh: Syntax error: redirection unexpected
Any ideas?

Thanks

Aman

gkreidl
Posts: 6307
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Using dbuscontrol.sh to control omxplayer

Mon Dec 15, 2014 11:08 pm

aman wrote:Hi

I've tried to follow the above but get the following error
dbuscontrol.sh: 16: dbuscontrol.sh: Syntax error: redirection unexpected
Any ideas?

Thanks

Aman
What did you exactly do?
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

aman
Posts: 11
Joined: Wed Oct 10, 2012 6:26 am

Re: Using dbuscontrol.sh to control omxplayer

Tue Dec 16, 2014 9:15 am

Hi

Thanks for your reply. I did the following:

All from Putty using user 'pi'
Omxplayer from 24 Oct 2014 downloaded from omxplayer.sconde.net
Apt-get upgrade/update & rpi-update done

wget https://raw.githubusercontent.com/popco ... control.sh (the raw file information of dbuscontrol)
changed lines 3 & 4 according to the instructions above
in a separate session: omxplayer video.mp4 -o hdmi
in original session: sh dbuscontrol.sh pause

Then I got the error above. The video was still running on the screen.

Thank you very much for your help.

Aman

gkreidl
Posts: 6307
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Using dbuscontrol.sh to control omxplayer

Tue Dec 16, 2014 10:03 am

If you do it this way, it doesn't work. I've just tried it.

Invoking "sh" doesn't work with redirection used in line 16 (and may more). Without "sh" the script doesn't return.

To run it from one SSH session is also not possible, because running omxplayer with a "&" at the end of the line doesn't start at all (from SSH connection at least).

But dbuscontrol.sh does work from SSH (without invoking 'sh'), if omxplayer is started on the Pi itself (terminal or command line).

Perhaps you should file an issue at https://github.com/popcornmix/omxplayer/issues
At least someone might provide an explanation for this behavior (and perhaps a workaround).
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

aman
Posts: 11
Joined: Wed Oct 10, 2012 6:26 am

Re: Using dbuscontrol.sh to control omxplayer

Tue Dec 16, 2014 10:40 am

Thanks.

I changed the permissions

Code: Select all

sudo chmod +rx  dbuscontrol.sh
and now run it without the initial sh.

It works!

Thanks again

Aman

piplayer
Posts: 14
Joined: Thu Dec 13, 2012 8:03 pm
Location: Melbourne, Australia
Contact: Website

Re: Using dbuscontrol.sh to control omxplayer

Sat Jul 25, 2015 2:26 am

Sending DBUS commands to omxplayer by using dbuscontrol.sh within a Python script is straightforward where the DBUS command emulates a keystroke action:

ie

os.system('dbuscontrol.sh hidesubtitles')

Ultimately I want to add the functionality in dbuscontrol.sh to select a specific subtitle index as is described in the omxplayer readme but not yet implemented.

In order to understand how to do this I am experimenting with those DBUS commands that allow a single integer parameter to be passed via dbuscontrol.sh to omxplayer.

These include recently added 'volume' and 'setalpha' and the older 'seek' but I cannot for the life of me find any documentation on the syntax of passing this integer to omxplayer via dbuscontrol.sh inside a Python script

I have tried:
os.system('dbuscontrol.sh volume 0')
os.system('dbuscontrol.sh volume(0)')
os.system('dbuscontrol.sh volume (0)')
os.system('dbuscontrol.sh volume[0]')
os.system('dbuscontrol.sh volume [0]')
os.system('dbuscontrol.sh volume,0')
os.system('dbuscontrol.sh volume:0')
os.system('dbuscontrol.sh volume;0')
os.system('dbuscontrol.sh volume'0'')
os.system('dbuscontrol.sh volume;"0"')

Utimately I'm working towards being able to do this os.system('dbuscontrol.sh selectsubtitle(1)') or whatever the correct syntax of the passing an integer through the two scripts is ...

Thanks in advance,

Mike

gkreidl
Posts: 6307
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Using dbuscontrol.sh to control omxplayer

Sat Jul 25, 2015 8:08 am

I'm using something like this (simplified here):

Code: Select all

def send_dbus(args):
    res = ''
    err = ''
    if self.omxprocess:
        try:
            db = subprocess.Popen(['dbuscontrol.sh']+args,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
            (res,err) = db.communicate()
        except:
            res = ''
        if err:
            res = ''
    return res
where args is a list of strings; the first one must be the command. Example:

Code: Select all

result = send_dbus(['setvideopos','100','100','900','550'])
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

piplayer
Posts: 14
Joined: Thu Dec 13, 2012 8:03 pm
Location: Melbourne, Australia
Contact: Website

Re: Using dbuscontrol.sh to control omxplayer

Sat Jul 25, 2015 11:52 am

Thanks mate,

I had a good look through your code before I posted to the forum but couldn't reverse engineer what you were doing back into the correct string.

Let's go back to basics:
How would you set the volume or transparency from the command line ?
pi@rowan ~ $ dbuscontrol.sh volume 0

just dumps the command list to the console ...

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Using dbuscontrol.sh to control omxplayer

Sat Jul 25, 2015 12:25 pm

Is it possible to get dbuscontrol.sh w/o downloading/unpacking/analyzing/building the whole omxplayer from source?
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

gkreidl
Posts: 6307
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Using dbuscontrol.sh to control omxplayer

Sat Jul 25, 2015 12:41 pm

Joe Schmoe wrote:Is it possible to get dbuscontrol.sh w/o downloading/unpacking/analyzing/building the whole omxplayer from source?
https://raw.githubusercontent.com/popco ... control.sh
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

gkreidl
Posts: 6307
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Using dbuscontrol.sh to control omxplayer

Sat Jul 25, 2015 12:44 pm

piplayer wrote:Thanks mate,

I had a good look through your code before I posted to the forum but couldn't reverse engineer what you were doing back into the correct string.

Let's go back to basics:
How would you set the volume or transparency from the command line ?
pi@rowan ~ $ dbuscontrol.sh volume 0

just dumps the command list to the console ...
dbuscontrol.sh setalpha 128
should work and make the video half transparent (I cannot test it because I'm using an extended version to allow control of multiple omxplayer instances).
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

User avatar
rpdom
Posts: 16998
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Using dbuscontrol.sh to control omxplayer

Sat Jul 25, 2015 12:45 pm

I think it is a bug in dbuscontrol.sh. I haven't got time to confirm it right now, but if you edit dbuscontrol.sh and change this bit

Code: Select all

volume)
volume=`dbus-send --print-reply=double --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Volume ${2:+double:}$2`
Change the --print-reply=double to --print-reply=literal that will make it work.

piplayer
Posts: 14
Joined: Thu Dec 13, 2012 8:03 pm
Location: Melbourne, Australia
Contact: Website

Re: Using dbuscontrol.sh to control omxplayer

Sat Jul 25, 2015 12:47 pm

Yep it's here https://github.com/popcornmix/omxplayer ... control.sh

but the problem has been solved off list.
I've been building omxplayer from source but was not fully specifying the path in my python script to the up to date version of dbuscontrol.sh in /home/pi/omxplayer
When I'm in there I can go ./dbuscontrol.sh volume 0 and that works :oops:
or in my script

os.system('/home/pi/omxplayer/dbuscontrol.sh volume 0')

gkreidl
Posts: 6307
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Using dbuscontrol.sh to control omxplayer

Sat Jul 25, 2015 1:16 pm

piplayer wrote:Yep it's here https://github.com/popcornmix/omxplayer ... control.sh

but the problem has been solved off list.
I've been building omxplayer from source but was not fully specifying the path in my python script to the up to date version of dbuscontrol.sh in /home/pi/omxplayer
When I'm in there I can go ./dbuscontrol.sh volume 0 and that works :oops:
or in my script

os.system('/home/pi/omxplayer/dbuscontrol.sh volume 0')
or move it to /usr/local/bin
(that's where kweb places its dbuscontrolm.sh, which takes one more argument to allow controlling multiple instances).
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

gkreidl
Posts: 6307
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Using dbuscontrol.sh to control omxplayer

Sat Jul 25, 2015 1:17 pm

rpdom wrote:I think it is a bug in dbuscontrol.sh. I haven't got time to confirm it right now, but if you edit dbuscontrol.sh and change this bit

Code: Select all

volume)
volume=`dbus-send --print-reply=double --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Volume ${2:+double:}$2`
Change the --print-reply=double to --print-reply=literal that will make it work.
That explains why I never got the volume command to work properly :-)
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer


piplayer
Posts: 14
Joined: Thu Dec 13, 2012 8:03 pm
Location: Melbourne, Australia
Contact: Website

Re: Using dbuscontrol.sh to control omxplayer

Tue Jul 28, 2015 7:43 am

@gkreidl I'm glad that by stumbling around in the dark I prompted @rpdom to shed some light on your problem. :)
Somebody should sort that out on github ...

@Douglas6 Thanks. However for a Python novice like me I would need to see some worked examples of using your module in a simple script as it isn't self-evident to me. (I'm one third of the way through 'Learning Python the Hard Way').

If you were going to provide same then using selectsubtitle would be most helpful to me - I don't suppose you have tested whether this actually works ? It is a pretty obscure use case and I don't even know for certain that the appropriate 'hooks' are actually in oxmplayer but I have at least proven that you can switch (on the fly) between multiple subtitle streams multiplexed into an .mkv file.

Butas torarin says here https://github.com/popcornmix/omxplayer ... -123558744
there is no (complete) mechanism to load multiple discrete srt files into omxplayer from the command line.

User avatar
renierD
Posts: 3
Joined: Sat Sep 19, 2015 11:15 am
Location: South Africa
Contact: Website

Re: Using dbuscontrol.sh to control omxplayer

Sat Sep 19, 2015 11:29 am

Hi guys

Hope I'm not jacking. Seems topic is not active anymore. Can anyone guide me to use dbuscontrol to determine whether OMX Player is active (assuming using the status command somehow). I'm thinking of using the duration or position for this, but I might be able to use the error message as well / in stead?

When I run dbuscontrol status while OMXPlayer is active it gives me Duration, Position AND Paused.
When OMXPlayer is not active I get the following error:

Code: Select all

Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.mpris.MediaPlayer2.omxplayer was not provided by any .service files
I want to be able to integrate this in a .sh script to see if OMXPlayer is busy playing a loop of music, where they all need to be stopped one by one, or using a IF status to see if I can avoid it if possible.

Thanks upfront
Pi is not only for guys.

Return to “Graphics, sound and multimedia”