[vlc-devel] Can't Embed VLC in Qt4/wx on OSX with PyQt4/wx and Python Bindings
olivier.aubert at liris.cnrs.fr
Thu Nov 26 00:07:35 CET 2009
> I have been trying to figure out how to embed VLC in a Qt-Widget on
> MacOS (Snow Leopard) using PyQt4 and the python-ctypes bindings. Two
> python applications I am developing use wxPython and Qt4,
> respectively, to embed a VLC player. On Windows and Linux, I was able
> to get it work by using the QWidget.winId() function (GetHandle() on
> wxPython) to get an HWND or XID to pass to VLC using the
> MediaControl.set_visual() method in the python-ctypes bindings.
Great. I was looking for someone who would contribute a basic
QtVLCWidget / WxVLCWidget (similar to what is already done for Gtk in
vlcwidget.py) for the python bindings. Please consider sharing your code
(preferably GPL-licenced) so that I can add it as example. Improvements
of the initialisation code of the python module for MacOS X are welcome
> As a python developer determined to use VLC, this strikes me as a
> serious issue for VLC adoption. The ability to easily embed VLC
> applications in MacOS using python could dramatically increase
> adoption among python developers who need a good media solution for OS
> X. I am looking forward to seeing if we can together try to fix this
> once and for all, and maybe even produce a guide for would be python
> developers wanting to use VLC on OS X.
If the problem is solved and integrated properly, there should be no
need to make a platform-specific guide. A generic one should do. BTW, as
you saw in some forum threads, it is a generic VLC issue rather than a
> o I have discovered that the crashing is the result of a problem with
> the macosx plugin (compiled from code in module/gui/macosx). For
> Grishenko and Goldeneye, this is used by default and crashes. Yellow
> Bastard seems to use minimal_macosx by default, and does not crash. I
> was able to verify this by recompiling Goldeneye, but disabling the
> compile of the macosx plugin (I edited module/gui/Makefile.am and
> removed macosx from the list of subdirectories to compile shortly
> before doing the final make for VLC). This forced Goldeneye to use
> minimal_macosx, and it resultedly played the video, but like Yellow
> Bastard, the video was NOT embedded.
> o Over on this thread (viewtopic.php?f=32&t=61157) Benjamin suggests
> that the crashing with macosx is the result of a problem with EyeTV.
> • In old versions of VLC (as late as 0.8.6), the Tribler team
> (http://www.tribler.org/trac/wiki/VlcMacHowto) noted that the
> inability to use VLC with python bindings on VLC was because VLC’s
> set_visual() expected an AGLDrawable surface, but wx, and apparently
> Qt, returns a ControlRef. Tribler issued a patch for the macosx plugin
> to cast a ControlRef as an AGLDrawable, and this apparently worked,
> since the Tribler client works on MacOS. Unfortunately, 0.8.6 is
> rather old, and it’s not of much use to me since I can’t compile it on
> Snow Leopard as the libraries are way out of date.
Maybe their patch should be ported to the new VLC version?
> Moreover, we should try to figure out how to do this for the newest
> VLC and the newer python-ctype bindings.
In any case, you should use the new libvlc API methods
MediaPlayer.set_nsobject or MediaPlayer.set_agl rather than
MediaContro.set_visual. The latter can be considered as deprecated,
since it relies on the now-deprecated libvlc_media_player_set_drawable
(look at the comment of this function in include/vlc/deprecated.h in the
git tree, it could help you figure out the problem).
> o I discovered that the patch done to voutgl.m in macosx could
> similarly be done on voutagl.m in minimal_macosx. Despite my hoping,
> this had no effect, and I’m not sure why (perhaps voutagl.m is not
> utilized by python-ctypes?).
python-ctypes is merely a wrapper around the C libvlc API. It is
automatically generated from include/vlc/*.h.
> • Working with minimal_macosx, I tried to see if there were any clever
> ways to get the video, which was at least playing, embedded in the
> window. I tried using the set_nsobject() method for vlc.MediaPlayer in
> the python-ctypes bindings (not MediaControl) to pass it an nsview
> from PyQt4. I’m not sure if I’m doing it wrong, or if it’s just not
Depending on how Qt handles window ids, you should use either
set_nsobject or set_agl. And if neither works, then they should be
drawable.nsobject is handled only in
gui/minimal_macosx/VLCOpenGLVoutView.m / video_output/opengllayer.m
and drawable.agl in gui/macosx/voutgl.m /
gui/minimal_macosx/voutagl.m / gui/minimal_macosx/voutgl.m
> At this point, I am at a total loss for what to do, and hope that
> someone out there knows how to do this. VLC, Python, PyQT/wxPython,
> and Mac OS X seem like the perfect combination of tools, yet getting
> them to work together has been a nightmare for me. I really don’t want
> to give up on VLC, partly because I know no other media application
> out there can do what I need it to. Based on the incomplete threads
> I’ve seen out there, I’m sure others are equally in need for this to
> work, so let’s see if we can finally put this issue to rest, once and
> for all.
Just for trolling, you can have a look at gstreamer, which has nice
python bindings too ;-)
But your patches to VLC will be more than welcome to fix this issue.
More information about the vlc-devel