Control OMXPlayer from Python on the Raspberry Pi.
Make sure dbus is installed:
$ sudo apt-get install python-dbus
For someone who just wants to use the package:
$ python setup.py install
If you're feeling helpful, and decide to help develop the package:
$ python setup.py develop
There's also an Ansible playbook in devenv
which will set up a raspberry pi
with omxplayer-wrapper in develop mode (located at
/usr/src/omxplayer-wrapper
) which can be used by running ./devenv/deploy.sh
This will install via symlinks so that you can continue to work on it locally but import it from other python packages
from omxplayer import OMXPlayer
from time import sleep
file_path_or_url = 'path/to/file.mp4'
# This will start an `omxplayer` process, this might
# fail the first time you run it, currently in the
# process of fixing this though.
player = OMXPlayer(file_path_or_url)
# The player will initially be paused
player.play()
sleep(5)
player.pause()
# Kill the `omxplayer` process gracefully.
player.quit()
Playing a stream from a URL (e.g. a live RTMP or RTSP stream) works the same as with a file path, just change the "source" string parameter given to OMXPlayer
to a URL instead of a file path.
from omxplayer import OMXPlayer
from time import sleep
file_path_or_url = 'rtmp://192.168.0.1/live/test'
player = OMXPlayer(file_path_or_url)
# The player will initially be paused
player.play()
sleep(5)
player.pause()
# Kill the `omxplayer` process gracefully.
player.quit()
Choppy streaming over a slow connection? If you're connection isn't good
enough to support streaming, checkout urllib2
to download the file locally
prior to playing.
You can read the docs here: python-omxplayer-wrapper.rtfd.org