[vlc-devel] Can't Embed VLC in Qt4/wx on OSX with PyQt4/wx and Python Bindings

Ho Tuan tuan at post.harvard.edu
Wed Nov 25 22:41:47 CET 2009

Hello VLC Developers!

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. Unfortunately, it has not been so straightforward on OS X, and I
have spent the better part of two weeks trying to figure this out.

Looking around on Google, I have found various small threads that
incompletely address the issue, but no one has come up with a complete
solution, let alone for python. The closest thing I could find was this (
but that solution was hackish and doesn’t help much for python.

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.

So, allow me to share what I have discovered so far…

• The python ctypes purportedly supports Darwin, and it is possible to
direct vlc.py to find libvlc.dylib in the contests of VLC.app, but calling
vlc from a Qt or wxPython application results in one of two things,
depending on the VLC version. On Grishenko and Goldeneye, a black window
sized to the video, but NOT embedded in the desired Qt/wx window appears
briefly before the application simply crashes. In the terminal, a “Bus
Error” is reported and the OS X error report says that there was a “KERNEL
PROTECTION ERROR”. In the newest git version, Yellow Bastard, the video DOES
play, but in a floating window that is not properly embedded in the desired
Qt/wx window.

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
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. Moreover, we should try to figure out how to do this for the newest
VLC and the newer python-ctype bindings.

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?).

• 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 possible.

o With QWidget, I tried to pass QWidget.winId() to set_nsobject(), hoping
that the winId() was actually an nsview. It didn’t work, and it just caused
the python application to crash.

o With QMacCocoaViewContainer in PyQt4, I contained the QWidget inside the
QMacCocoaViewContainer and then tried to pass QMacCocoaViewContainer.winId()
to set_nsobject() and had the same crash as with QWidget.

o I tried to pass QMacCocoaViewContainer.cocoaView() (which apparently
returns an nsview) and I still got the same crash, but this time, the
terminal reports that an nsview has been autoreleased and is “leaking”

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.

Best Regards,
Jack Tuna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20091125/3bc14e75/attachment.html>

More information about the vlc-devel mailing list