Difference between revisions of "Old Python bindings"
Line 3: | Line 3: | ||
For a while, there has been a basic python binding for libvlc, that was used for streaming. A more complete (with a hopefully generic API that can be reused by other players) has been developped, based on the MediaControlAPI. | For a while, there has been a basic python binding for libvlc, that was used for streaming. A more complete (with a hopefully generic API that can be reused by other players) has been developped, based on the MediaControlAPI. | ||
− | [http://trac.videolan.org/vlc/browser/trunk/bindings/python python binding] | + | Sources are browsable from [http://trac.videolan.org/vlc/browser/trunk/bindings/python python binding] and a code sample can be found in [http://liris.cnrs.fr/advene/download/]. |
− | [http://liris.cnrs.fr/advene/download/] | ||
= Basics = | = Basics = | ||
Line 10: | Line 9: | ||
The vlc python module provides 2 main classes : MediaControl and Object. | The vlc python module provides 2 main classes : MediaControl and Object. | ||
− | vlc.MediaControl | + | vlc.Object provides a binding to the vlc object architecture. It allows to manipulate variables and configuration options, and explore the object hierrarchy. The vlcdebug.py script, located in the python bindings directory, wraps around the vlc.Object to provide an easier access to variables and objects (as illustrated in the code sample in [http://liris.cnrs.fr/advene/download/]). |
+ | |||
+ | vlc.MediaControl implements the MediaControlAPI. | ||
= Tips and tricks = | = Tips and tricks = | ||
Line 43: | Line 44: | ||
pass | pass | ||
return value | return value | ||
− | + | ||
vlcpath=get_registry_value('Software\\VideoLAN\\VLC','InstallDir') | vlcpath=get_registry_value('Software\\VideoLAN\\VLC','InstallDir') | ||
if vlcpath is None: | if vlcpath is None: |
Revision as of 19:12, 4 December 2005
Contents
Python binding documentation
For a while, there has been a basic python binding for libvlc, that was used for streaming. A more complete (with a hopefully generic API that can be reused by other players) has been developped, based on the MediaControlAPI.
Sources are browsable from python binding and a code sample can be found in [1].
Basics
The vlc python module provides 2 main classes : MediaControl and Object.
vlc.Object provides a binding to the vlc object architecture. It allows to manipulate variables and configuration options, and explore the object hierrarchy. The vlcdebug.py script, located in the python bindings directory, wraps around the vlc.Object to provide an easier access to variables and objects (as illustrated in the code sample in [2]).
vlc.MediaControl implements the MediaControlAPI.
Tips and tricks
Snapshot support
In order to get snapshot support, you have to activate the snapshot vout module through a clone video filter. The following code gives a way to achieve this :
mc=vlc.MediaControl([ "--vout-filter", "clone" ]) o=VLC.Object(0) o.config_set("clone-vout-list", "default,snapshot") o.config_set("snapshot-width", 320) o.config_set("snapshot-height", 200)
Note that all config options could have been given on the command line, but this illustrates the use of the vlc.Object API.
Win32 initialization
If the vlc module was not compiled with the exact same prefix as the VLC installation (e.g. c:\\Program Files\\Videolan), then it cannot find itself the installation directory (stored in the registry Software\VideoLAN\VLC\Path), and the MediaControl instanciation will fail with a message like "Cannot find interface plugins".
The workaround consists in changing directory to the VLC installation directory before instanciating the MediaControl object.
def get_registry_value (self, subkey, name): import _winreg value = None for hkey in _winreg.HKEY_LOCAL_MACHINE, _winreg.HKEY_CURRENT_USER: try: reg = _winreg.OpenKey(hkey, subkey) value, type_id = _winreg.QueryValueEx(reg, name) _winreg.CloseKey(reg) except _winreg.error: pass return value vlcpath=get_registry_value('Software\\VideoLAN\\VLC','InstallDir') if vlcpath is None: print "Cannot locate VLC installation directory" else: os.chdir(vlcpath) mc=vlc.MediaControl()