oaubert / python-vlc

Python vlc bindings
GNU Lesser General Public License v2.1
393 stars 111 forks source link

macosx vout display error: No drawable-nsobject nor vout_window_t found, passing over #194

Open wmodes opened 3 years ago

wmodes commented 3 years ago

While this issue was closed for this very particular use case and versions, it was not solved for other mac users using other python versions.

I am using the following code:

# importing time and vlc
import time
import vlc

# method to play video
def video(source):

    # creating a vlc instance
    vlc_instance = vlc.Instance()

    # creating a media player
    player = vlc_instance.media_player_new()

    # creating a media
    media = vlc_instance.media_new(source)

    # setting media to the player
    player.set_media(media)

    # play the video
    player.play()

    # wait time
    time.sleep(10)

    # getting the duration of the video
    duration = player.get_length()

    # printing the duration of the video
    print("Duration : " + str(duration))

# call the video method
video("../data/070_SHARP_Titles_Flower_Titles.mp4")

Here is the result on MacOs Big Sur:

[00007fc99ec994c0] videotoolbox decoder: Using Video Toolbox to decode 'h264'
[00007fc99ec994c0] videotoolbox decoder: vt cvpx chroma: 420v
[00007fc99ecde330] caopengllayer vout display error: No drawable-nsobject found!
[00007fc99ecde330] macosx vout display error: No drawable-nsobject nor vout_window_t found, passing over.
[00007fc99f8b7af0] main video output error: video output creation failed
[00007fc99ec994c0] main decoder error: failed to create video output
[00007fc99ec994c0] videotoolbox decoder error: decoder failure, Abort.
[00007fc99ece5340] caopengllayer vout display error: No drawable-nsobject found!
[00007fc99ece5340] macosx vout display error: No drawable-nsobject nor vout_window_t found, passing over.
[00007fc99f8c54f0] main video output error: video output creation failed
[00007fc99ec994c0] main decoder error: failed to create video output
[h264 @ 0x7fc99f871a00] get_buffer() failed
[h264 @ 0x7fc99f871a00] thread_get_buffer() failed
[h264 @ 0x7fc99f871a00] decode_slice_header error
[h264 @ 0x7fc99f871a00] no frame!
[00007fc99ef32db0] caopengllayer vout display error: No drawable-nsobject found!
[00007fc99ef32db0] macosx vout display error: No drawable-nsobject nor vout_window_t found, passing over.
[00007fc99f0a84f0] main video output error: video output creation failed
[00007fc99ec994c0] main decoder error: failed to create video output
[h264 @ 0x7fc99f8b9000] get_buffer() failed
[h264 @ 0x7fc99f8b9000] thread_get_buffer() failed
[h264 @ 0x7fc99f8b9000] decode_slice_header error
[h264 @ 0x7fc99f8b9000] no frame!

And so on for every frame of the video. Oddly, I can hear the audio, but no video window is created. I crawled over the previously closed issue, and could not work out a solution.

mrJean1 commented 3 years ago

The video is not shown because there is no call to player.set_nsobject(obj) or player.set_xwindow(obj) to specify the window to display the video.

Take a look in the examples folder. The examples cocoavlc.py, pyobjvlc.py, tkvlc.py and wxvlc.py all call player.set_nsobject(obj) or player.set_xwindow(obj) where obj is a drawable object specific to the underlying windowing kit. Those examples all work on macOS Big Sur 11.6 (on Intel and Apple Silicon) with VLC 3.0.16, provided the required dependencies are installed.

Try using

     python  tkvlc.py  ../data/070_SHARP_Titles_Flower_Titles.mp4

since that works with recent Python versions which include Tcl/Tk.

wmodes commented 3 years ago

I understand that it is failing because it doesn’t open a window. On other platforms except Mac the window opens fine. If you look at the previous issue, there was a segfault in opening a tkinter window because of missing libraries that was never solved.

-- Wes Modes A Secret History of American River People http://peoplesriverhistory.us Pronouns: they/them

Sent from my Apple ][e

On Oct 15, 2021, at 9:46 PM, mrJean1 @.***> wrote:

 The video is not shown because there is no call to player.set_nsobject(obj) to specify the window to display the video.

Take a look in the examples folder. The examples cocoavlc.py, pyobjvlc.py, tkvlc.py and wxvlc.py all call player.set_nsobject(obj) where obj is a drawable object specific to the underlying windowing kit. Those examples all work on macOS Big Sur 11.6 (on Intel and Apple Silicon), provided the required dependencies are installed.

Try using

 python  tkvlc.py  ../data/070_SHARP_Titles_Flower_Titles.mp4

since that works with recent Python versions which include Tcl/Tk.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

mrJean1 commented 3 years ago

Correct, older versions of VLC on macOS (or MacOS) did open a window. However, recent VLC releases no longer do and make a call to player.set_nsobject(obj) or player.set_xwindows(obj) necessary. It is an issue in VLC, specificallly the libVLC library.

wmodes commented 3 years ago

I still get:

% python tkvlc.py
DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.
[00007fad0c4352b0] videotoolbox decoder: Using Video Toolbox to decode 'h264'
[00007fad0c4352b0] videotoolbox decoder: vt cvpx chroma: 420v
[00007fad0d945d80] caopengllayer vout display error: No drawable-nsobject found!
[00007fad0d945d80] macosx vout display error: No drawable-nsobject nor vout_window_t found, passing over.
[00007fad088cc6f0] main video output error: video output creation failed
[00007fad0c4352b0] main decoder error: failed to create video output
[00007fad0c4352b0] videotoolbox decoder error: decoder failure, Abort.
[00007fad0d93fd10] caopengllayer vout display error: No drawable-nsobject found!
[00007fad0d93fd10] macosx vout display error: No drawable-nsobject nor vout_window_t found, passing over.
[00007fad0894d4f0] main video output error: video output creation failed
[00007fad0c4352b0] main decoder error: failed to create video output
[h264 @ 0x7fad0a914600] get_buffer() failed
[h264 @ 0x7fad0a914600] thread_get_buffer() failed
[h264 @ 0x7fad0a914600] decode_slice_header error
[h264 @ 0x7fad0a914600] no frame!
[00007fad0d947bf0] caopengllayer vout display error: No drawable-nsobject found!
[00007fad0d947bf0] macosx vout display error: No drawable-nsobject nor vout_window_t found, passing over.
[00007fad079f52f0] main video output error: video output creation failed
[00007fad0c4352b0] main decoder error: failed to create video output
[h264 @ 0x7fad0a926200] get_buffer() failed
[h264 @ 0x7fad0a926200] thread_get_buffer() failed
[h264 @ 0x7fad0a926200] decode_slice_header error
[h264 @ 0x7fad0a926200] no frame!
[00007fad0d93ff40] caopengllayer vout display error: No drawable-nsobject found!
[00007fad0d93ff40] macosx vout display error: No drawable-nsobject nor vout_window_t found, passing over.
[00007fad0894d4f0] main video output error: video output creation failed
[00007fad0c4352b0] main decoder error: failed to create video output
[h264 @ 0x7fad0a903400] get_buffer() failed
[h264 @ 0x7fad0a903400] thread_get_buffer() failed
[h264 @ 0x7fad0a903400] decode_slice_header error
[h264 @ 0x7fad0a903400] no frame!
% python tkvlc.py -v    
tkvlc.py: 20.05.04 (tkinter 8.5 N/A)
% python --version
Python 3.7.10

I'm developing for the raspian (which works fine), but would like to do my development on my Mac if possible.

mrJean1 commented 3 years ago

What are the python-vlc, VLC and macOS versions? Try

   python vlc.py -v

Can't duplicate any of those messages with Python 3.7.6, tkvlc.py 20.12.10, python-vlc 3.0.1218, VLC 3.0.16 on macOS 11.6 Big Sur (aka 10.16):

% python3.7 tkvlc.py 
[00007f8ea26bfc90] videotoolbox decoder: Using Video Toolbox to decode 'h264'
[00007f8ea26bfc90] videotoolbox decoder: vt cvpx chroma: 420v

% python3.7 tkvlc.py -v
tkvlc.py: 20.12.10 (tkinter 8.6 /Library/Frameworks/Python.framework/Versions/3.7/lib/libtk8.6.dylib)

% python3.7 vlc.py -v
vlc.py: 3.0.12118 (Tue Apr 20 20:46:07 2021 3.0.12)
LibVLC version: 3.0.16 Vetinari (0x3001000)
LibVLC compiler: clang: warning: argument unused during compilation: '-mmacosx-version-min=10.7' [-Wunused-command-line-argument]
Plugin path: /Applications/VLC.app/Contents/MacOS/plugins
Python: 3.7.6 (64bit) macOS 10.16

Likewise for Python 3.8.10, 3.9.6 and 3.10.0 with same tkvlc.py, python-vlc and VLC on the same macOS. All these Python builds are straight downloads from Python.org.

rkeniger commented 3 years ago

This issue is definitely occurring for me also. The tkvlc.py example presents a window but video frames don't play and I see the same errors as @wmodes.

I'm using Python 3.10, but I'm on Monterey (macOS 12.0.1). I suspect it could be a Monterey issue?

mrJean1 commented 3 years ago

The tkvlc.py 20.05.04 from the python-vlc/examples folder works with Python 3.10.0 and 3.9.6 (both macOS 64-bit universal2) natively on amd64 Apple-Silicon and with Python 3.8.10 and 3.7.6 (both macOS 64-bit Intel) in emulation on x86_64 Apple-Silicon macOS 11.6.1 Big Sur, but tested only with the latest release of VLC 3.0.16 Universal Binary and only with python-vlc.py 3.0.12118 and 3.0.12119. All cases, tkvlc.py uses the Tk/Tcl libraries (tkinter 8.6 /Library/Frameworks/Python.framework/Versions/3.{7,8,9,10}/lib/libtk8.6.dylib) included in the Python release.

Support of and testing on macOS Monterey is pending. In the mean time, what version of python-vlc and VLC are you using? Type

    python3  vlc.py  -v
    python3  tkvlc.py  -v

in a terminal window. In addition, what is the result of this Python line

    python3  -c  'import platform; print(platform.machine())'
rkeniger commented 3 years ago

Here's what I see:

vlc.py: 3.0.12118 (Tue Apr 20 20:46:07 2021 3.0.12)
LibVLC version: 3.0.16 Vetinari (0x3001000)
LibVLC compiler: clang: warning: argument unused during compilation: '-mmacosx-version-min=10.7' [-Wunused-command-line-argument]
Plugin path: /Applications/VLC.app/Contents/MacOS/plugins
Python: 3.10.0 (64bit) macOS 12.0.1
➜ python3 tkvlc.py -v 
tkvlc.py: 20.05.04 (tkinter 8.6 N/A)
➜ python3  -c  'import platform; print(platform.machine())'
arm64
mrJean1 commented 3 years ago

The line after

    python3  tkvlc.py  -v

should look something like

    tkvlc.py: 20.05.04 (tkinter 8.6 /Library/Frameworks/Python.framework/Versions/3.10/lib/libtk8.6.dylib)

and not

    tkvlc.py: 20.05.04 (tkinter 8.6 N/A)

meaning the Tcl/Tk libraries can't be found inside Python 3.10.

Make sure Python 3.10.0 is indeed the Universal one, since you're on Apple-Silicon natively.

rkeniger commented 3 years ago

Interesting. I'm able to use Tk even though that is returning N/A:

CleanShot 2021-11-03 at 09 19 40@2x
rkeniger commented 3 years ago

Also, I'm definitely on the Apple silicon version of Python:

➜ arch -x86_64 python3
arch: posix_spawnp: python3: Bad CPU type in executable
mrJean1 commented 3 years ago

Try

    python3  -c  'import tkinter; print(tkinter.__file__)'

Perhaps, Monterey comes with Python 3.10. Not sure, just a guess.

rkeniger commented 3 years ago
➜ python3  -c  'import tkinter; print(tkinter.__file__)'
/opt/homebrew/Cellar/python@3.10/3.10.0_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py
mrJean1 commented 3 years ago

That is the issue. tkvlc.py can't find the Tcl/Tk library in that Python installation. Please try

    python3  -c  'import sys; print(sys.prefix)'
rkeniger commented 3 years ago
➜ python3 -c 'import sys; print(sys.prefix)'          
/opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10
mrJean1 commented 3 years ago

That looks good. One more


    ls  -l  /opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/lib/libtk*
rkeniger commented 3 years ago

Interesting.

python-vlc/examples on  master via 🐍 system 
➜ ls -l /opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/lib/libtk*   
zsh: no matches found: /opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/lib/libtk*

python-vlc/examples on  master via 🐍 system 
➜ ls -l /opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/lib/      
total 0
lrwxr-xr-x    1 rob  admin     9  5 Oct 03:55 libpython3.10.dylib -> ../Python
drwxr-xr-x    6 rob  admin   192  3 Nov 09:16 pkgconfig
drwxr-xr-x  208 rob  admin  6656  3 Nov 09:16 python3.10

python-vlc/examples on  master via 🐍 system 
➜ ls -l /opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10/libtk* 
zsh: no matches found: /opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10/libtk*
mrJean1 commented 3 years ago

Python builds from Python.org include libtkX.Y.dylib in that directory. In the Homebrew version, things are different. Perhaps Homebrew installs Tcl/Tk somewhere else and Homebrew's Python finds that one. But tkvlc.py doesn't look there and may need to be enhanced to look in other places. Being able to get the libtk.X.Y.dylib is critical for tkvlc.py and vlc.py to play a video in a macOS window.

Another difference with universal Python 3.10 from Python.org is this: both architectures work, as expected of a universal build.

% arch -arm64 python3
Python 3.10.0 (v3.10.0:b494f5935c, Oct  4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D

% arch -x86_64 python3
Python 3.10.0 (v3.10.0:b494f5935c, Oct  4 2021, 14:59:20) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D

One final request. What does this show

    echo $LD_LIBRARY_PATH
    echo $LIBRARY_PATH

    python3  -c  'from ctypes.util import find_library; print(find_library("tk"))'

or maybe some Homebrew environment variable.

rkeniger commented 3 years ago

That's interesting about the homebrew version. Unfortunately, I have so many brew libraries that rely on the brew version of Python that I have to install it, and I've had major issues with pyenv on M1. I've got the official Python installer for macOS, but that installs Python in yet another location - it might be universal, though. I will try reworking my $PATH so I can try the official version.

Here's the output. I really appreciate your patience with this.

python-vlc/examples on  master via 🐍 system 
➜ echo $LD_LIBRARY_PATH

python-vlc/examples on  master via 🐍 system 
➜ echo $LIBRARY_PATH

python-vlc/examples on  master via 🐍 system 
➜ python3  -c  'from ctypes.util import find_library; print(find_library("tk"))'
/usr/lib/libtk.dylib
rkeniger commented 3 years ago

OK, I've tested now with the universal install from Python.org - and it works. So there's something screwy with the Homebrew Python config.

➜ python3 tkvlc.py -v
tkvlc.py: 20.05.04 (tkinter 8.6 /Library/Frameworks/Python.framework/Versions/3.10/lib/libtk8.6.dylib)
rkeniger commented 3 years ago
➜ which python3
/usr/local/bin/python3
➜ lipo -info /usr/local/bin/python3
Architectures in the fat file: /usr/local/bin/python3 are: x86_64 arm64 
mrJean1 commented 3 years ago

Unfortunately, that file name /usr/lib/libtk.dylib is returned by find_library('tk') but the file does not exist, at least on on my macOS:

python3 -c 'from ctypes.util import find_library; print(find_library("tk"))'
/usr/lib/libtk.dylib

sudo ls -l /usr/lib/libtk.dylib
Password:
ls: /usr/lib/libtk.dylib: No such file or directory

There must be a way to find out where Homebrew Python3 gets libtbX.Y.dylib form during import tkinter. Perhaps this

    python3 -v -c 'import tkinter'

and then look the the lines after these

...
Python 3.10.0 (v3.10.0:b494f5935c, Oct  4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
# /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__pycache__/__init__.cpython-310.pyc matches /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py
# code object from '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__pycache__/__init__.cpython-310.pyc'
# /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/__pycache__/enum.cpython-310.pyc matches /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/enum.py
# code object from '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/__pycache__/enum.cpython-310.pyc'
# /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/__pycache__/types.cpython-310.pyc matches /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/types.py
# code object from '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/__pycache__/types.cpython-310.pyc'
import 'types' # <_frozen_importlib_external.SourceFileLoader object at 0x100f3a440>
import 'enum' # <_frozen_importlib_external.SourceFileLoader object at 0x100f39300>
# extension module '_tkinter' loaded from '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload/_tkinter.cpython-310-darwin.so'
# extension module '_tkinter' executed from '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload/_tkinter.cpython-310-darwin.so'
import '_tkinter' # <_frozen_importlib_external.ExtensionFileLoader object at 0x100f3ae00>
...
rkeniger commented 3 years ago
# extension module '_tkinter' loaded from '/opt/homebrew/opt/python-tk@3.10/libexec/_tkinter.cpython-310-darwin.so'
# extension module '_tkinter' executed from '/opt/homebrew/opt/python-tk@3.10/libexec/_tkinter.cpython-310-darwin.so'
import '_tkinter' # <_frozen_importlib_external.ExtensionFileLoader object at 0x10126bee0>
# /opt/homebrew/Cellar/python@3.10/3.10.0_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__pycache__/constants.cpython-310.pyc matches /opt/homebrew/Cellar/python@3.10/3.10.0_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/constants.py
# code object from '/opt/homebrew/Cellar/python@3.10/3.10.0_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__pycache__/constants.cpython-310.pyc'
import 'tkinter.constants' # <_frozen_importlib_external.SourceFileLoader object at 0x1012f4160>
import 'tkinter' # <_frozen_importlib_external.SourceFileLoader object at 0x101268700>
mrJean1 commented 3 years ago

Doesn't show the loading of the libtkX.Y.dylib. And _tkinter is loaded from a different place /opt/homebrew/opt/python-tk@3.10/libexec/_tkinter.cpython_310_darwin.so.

So, libtkX.Y.dylib can be anywhere. Not sure what to do next.

No Tk mentioned here, but the name is python-tk@3.10, perhaps the Tcl/Tk libraries are linked into the Homebrew Python executable.

candymountain commented 3 years ago

I'm struggling with this as well. I'd love to use vlc to play a random list of movie at a time for a visual behaviour experiment so any sort of resolution would mean the world to me.

mrJean1 commented 3 years ago

@candymountain, if you used Homebrew to install Python with tkvlc.py, the path to the libtk.dylib is still the unresolved issue.

Otherwise, what are your versions of python-vlc, VLC, Python and macOS? Which python-vlc/examples do not work?

mrJean1 commented 3 years ago

The Homebrew site shows that python-tk is a separate install, separate from Python and separate from Tcl/Tk and the former depends on both the latter. The question remains, where does python-tk load the Tk library from?

@rkeniger please show the output of this command lines

    ls -l /opt/homebrew/opt/python-tk@3.10/libexec/
    ls -l /opt/homebrew/opt/python-tk@3.10/

    ls -l /opt/homebrew/opt/tcl-tk/libexec/
    ls -l /opt/homebrew/opt/tcl-tk/

The libtk8.6.dylib needed for tkvlc.py is likely somewhere among those. If not, please try this command line

    find /opt/homebrew -name libtk8.6.dylib
rkeniger commented 3 years ago
~ via 🐍 system 
➜ ls -l /opt/homebrew/opt/python-tk@3.10/libexec/
total 248
-rwxr-xr-x  1 rob  admin  125824  3 Nov 09:16 _tkinter.cpython-310-darwin.so

~ via 🐍 system 
➜ ls -l /opt/homebrew/opt/python-tk@3.10/
total 64
-rw-r--r--  1 rob  admin   1867  3 Nov 09:16 INSTALL_RECEIPT.json
-rw-r--r--  1 rob  admin  13925  5 Oct 03:55 LICENSE
-rw-r--r--  1 rob  admin  10138  5 Oct 03:55 README.rst
drwxr-xr-x  3 rob  admin     96  3 Nov 09:16 libexec

~ via 🐍 system 
➜ ls -l /opt/homebrew/opt/tcl-tk/libexec/
ls: /opt/homebrew/opt/tcl-tk/libexec/: No such file or directory

~ via 🐍 system 
➜ ls -l /opt/homebrew/opt/tcl-tk/
total 1440
-rw-r--r--   1 rob  admin  337092 31 Dec  2020 ChangeLog
-rw-r--r--   1 rob  admin    1334  3 Nov 09:09 INSTALL_RECEIPT.json
-rw-r--r--   1 rob  admin    7321 31 Dec  2020 README.md
drwxr-xr-x  15 rob  admin     480  2 Nov 09:44 bin
-rw-r--r--   1 rob  admin  377078 31 Dec  2020 changes
drwxr-xr-x  49 rob  admin    1568 31 Dec  2020 include
drwxr-xr-x  26 rob  admin     832  2 Nov 09:44 lib
-rw-r--r--   1 rob  admin    2255 31 Dec  2020 license.terms
drwxr-xr-x   3 rob  admin      96 31 Dec  2020 share

~ via 🐍 system 
➜ find /opt/homebrew -name libtk8.6.dylib
/opt/homebrew/Cellar/tcl-tk/8.6.11_1/lib/libtk8.6.dylib
mrJean1 commented 3 years ago

Thank you. Attached is a tkvlc.py version hacked for your @rkeniger Homebrew installation. Please try to run that with Homebrew's python.

tkvlcHomebrew.zip

Any chance that this tkvlc.py files could be tested, just to make sure that it does work.

jumpers775 commented 3 years ago

hey so im having this issue too, read through the chat here and tried that tkvlcHomebrew.py, and it is not working for me.It is returning the following repeatedly. Audio still works.

[0000000127ca3120] caopengllayer vout display error: No drawable-nsobject found!
[0000000127ca3120] macosx vout display error: No drawable-nsobject nor vout_window_t found, passing over.
[0000000132e72ef0] main video output error: video output creation failed
[0000000132719cd0] main decoder error: failed to create video output
[h264 @ 0x132ddec00] get_buffer() failed
[h264 @ 0x132ddec00] thread_get_buffer() failed
[h264 @ 0x132ddec00] decode_slice_header error
[h264 @ 0x132ddec00] no frame!

I am using macOS 11.6 on m1.

mrJean1 commented 3 years ago

We've reached the end of the rope, unfortunately. The root cause is two-fold:

1) How to find the libtkX.Y.dylib loaded by tkinter in Python in a Homebrew environment.

2) Duplicating the Homebrew environment to reproduce the problem.

Without 2), it is impossible to resolve 1) and without 1) tkvlc.py can not display a video on recent macOS versions.

Nbelles commented 2 years ago

Hello,

I also was having the same issue as @rkeniger where the example was unable to show video onscreen despite the audio playing just fine. I also have installed python via homebrew and had very similar outputs to all the commands typed in a terminal. I wanted to follow up that I was able to install Python 3.11 via the download link on the main Python.org website. Using this python install allowed me to get the tkvlc.py example working as expected. I would like to get this working with homebrew's python though so I tried out the example python script for homebrew but it wasn't perfect out of the box. I had to search my computer for the libtk8.6.dylib because it wasn't in the same place as you had provided in the script. Instead, mine was located in /usr/local/Cellar/tcl-tk/8.6.12_1/lib/libtk8.6.dylib and put that in the script. When I ran it I got a printout (shown below) to the terminal with some warnings about the fact that there were two instances of the .dylib found (the one from homebrew and and the one from my new install of Python 3.11 from the website) but the video actually played properly. I should have tried the homebrew script option before installing Python 3.11 from the website but I was able to temporarily move the Python 3.11 folder location to a new location so that I could test without it and the homebrew script you provided worked without any warnings or errors as before when pointing to the .dylib from my homebrew install. So it seems like this is possible going forward if possible to just point to the .dylib file as you have done in the homebrew script you provided. I would love to see this continued to be worked on if possible.

objc[55323]: Class TKNSString is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/libtk8.6.dylib (0x105cc7678) and /usr/local/Cellar/tcl-tk/8.6.12_1/lib/libtk8.6.dylib (0x106f28ba0). One of the two will be used. Which one is undefined.
objc[55323]: Class TKApplication is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/libtk8.6.dylib (0x105cc7e00) and /usr/local/Cellar/tcl-tk/8.6.12_1/lib/libtk8.6.dylib (0x106f28c18). One of the two will be used. Which one is undefined.
objc[55323]: Class TKContentView is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/libtk8.6.dylib (0x105cc8230) and /usr/local/Cellar/tcl-tk/8.6.12_1/lib/libtk8.6.dylib (0x106f28c68). One of the two will be used. Which one is undefined.
objc[55323]: Class TKBackgroundLoop is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/libtk8.6.dylib (0x105cc8468) and /usr/local/Cellar/tcl-tk/8.6.12_1/lib/libtk8.6.dylib (0x106f28cb8). One of the two will be used. Which one is undefined.
objc[55323]: Class TKMenu is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/libtk8.6.dylib (0x105cc8490) and /usr/local/Cellar/tcl-tk/8.6.12_1/lib/libtk8.6.dylib (0x106f28ce0). One of the two will be used. Which one is undefined.
objc[55323]: Class TkService is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/libtk8.6.dylib (0x105cc8508) and /usr/local/Cellar/tcl-tk/8.6.12_1/lib/libtk8.6.dylib (0x106f28d58). One of the two will be used. Which one is undefined.
objc[55323]: Class TKPanel is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/libtk8.6.dylib (0x105cc8620) and /usr/local/Cellar/tcl-tk/8.6.12_1/lib/libtk8.6.dylib (0x106f28da8). One of the two will be used. Which one is undefined.
objc[55323]: Class TKDrawerWindow is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/libtk8.6.dylib (0x105cc8670) and /usr/local/Cellar/tcl-tk/8.6.12_1/lib/libtk8.6.dylib (0x106f28df8). One of the two will be used. Which one is undefined.
objc[55323]: Class TKWindow is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/libtk8.6.dylib (0x105cc86c0) and /usr/local/Cellar/tcl-tk/8.6.12_1/lib/libtk8.6.dylib (0x106f28e48). One of the two will be used. Which one is undefined.

Thanks for your help! @mrJean1

mrJean1 commented 2 years ago

@Nbelles, thank you for following up and posting the summary. Two questions:

1) Would it be worthwhile to enhance the tkvlc.py example to load the Homebrew Tk library? For example, if env var TKVLC_LIBTK is defined, try loading the Tk library from that path?

2) Are the Homebrew libraries for Python 3.11 and Tk built as universal2, i.e. for M1, M2 native?

Nbelles commented 2 years ago

@mrJean1

To provide a quick background on how I got here to this specific GitHub issue, I started by posting on PySimpleGUI about an issue I encountered when running one of their pieces of example code where they integrate a VLC playback frame into their PySimpleGUI window (very similar to what your example code does but using their interface which is essentially a wrapper for tkinter). (Github Issue). They were initially unsure what the issue was but came to the conclusion that it might be related to something else outside of their codebase. This led me to looking around into the python-vlc interface and how it is expected to be used and found the example code here. I then tried running it and ran into the same issue mentioned above. This was two instances of not being able to run example code so I started looking into the issues on this repo and found this specific issue and followed through the discussion and problem solving that was done above. Realistically I would like to get back to being able to use tkinter (or PySimpleGUI) and python-vlc natively to playback a YouTube livestream in a window on a Mac (which has python only installed through homebrew).

Now, in response to your questions:

  1. Looking through the tkvlc.py example, honestly I'm quite lost through most of the code as someone who hasn't really used tkinter much before (and thus why I was hoping to start with PySimpleGUI). It is a lot of code to do something seemingly so simple. I wouldn't even know where to start to be able to add the modifications that are shown in this discussion to the provided example so I definitely think that would be a useful addition. Now that I have found a way to get video working in tkinter, I will share this discussion with them so that they can see an example of vlc and tkinter working properly and potentially help them modify their code to work like this does while keeping the same wrapper functions they have that make the interface significantly more approachable for people less experienced with creating interfaces in tkinter. (Currently, even after installing Python 3.11 from the website as suggested here, their example code throws some errors. I will post there shortly so you can see the errors that I'm still experiencing if by chance the vlc window errors are related to the codebase here).
  2. To be honest, I'm really not sure what universal2 means or how you define native either but the computer I have been doing this testing on is a macOS Catalina 10.15.7 Intel-based iMac. If you need any more information about the machine I've been testing on, feel free to ask me to run specific commands on my machine, happy to help provide as much information about my setup as I can!
mrJean1 commented 2 years ago

@Nbelles, I'm not familiar with PySimpleGUI, but the demo VLC player seems to be the only place where VLC and Tk are referenced. And there, the setting of player.set_xwindow and player.set_hwnd are incorrect for macOS.

I'd more than happy to shoehorn a code snippet from tkvlc.py into PySimpleGUI, but the question is where? In that demo VLC player or somewhere else?

Nbelles commented 2 years ago

@mrJean1, thanks for taking a look at that. I had a feeling (from looking at other examples across the internet) that the player.XXX setting was incorrect and even tried a couple other variations I had found but ultimately didn’t find anything that worked for me.

As for an example that works with PySimpleGUI, if you are able to create one that uses the PySimpleGUI and still is cross-platform for Windows, Mac, and Linux, then I think that the demo VLC player would be the best place to do that. From what I can tell, it doesn’t seem like their example has explicit support for macOS so any information you can provide there would be greatly appreciated. I’m not a maintainer on their codebase but based on what I have seen from their codebase and documentation, I think they try to keep everything they do as widely compatible as possible (one of the primary features of PySimpleGUI). If the example you were able to come up with using PySimpleGUI only works on macOS, then maybe creating a new demo file would be best.

Just my thoughts and maybe they would suggest something different but if you were able to create something, I would be happy to make sure that it finds its way into their codebase/documentation somewhere so it doesn’t go to waste. Thanks for your help and support!

mrJean1 commented 2 years ago

Attached is a zip file with an improved tkvlc.py file and a new file psgvlc.py, the PySimpleGUI VLC demo modified for macOS. Please check whether these work better in your environment.

This tkvlc.py checks env variable TKVLC_LIBTK_PATH which should contain one or more paths for the libtkX.Y.dylib library. Set TKVLC_LIBTK_PATH to the fully qualified path of the Homebrew Tk lib file. Make sure that X.Y matches the tkinter.TkVersion in the python release you are using.

Instead of copying the macOS code from tkvlc.py and shoehorning that into the demo, psgvlc.py simply imports tkvlc.py when on macOS to get to the required function. That way, any macOS modifications in tkvlc.py will be accessible to psgvlc.py as well.

Once this works, both files will be added to pyhon-vlc/examples. And psgvlc.py could be submitted to PySimpleGUI as well. __ PS) After that, another enhancement to tkvlc.py might be: find the Tk lib in the Homebrew basement. Not sure whether that can be made to work reliably, but it is worth a try.

issue194v2.zip

mrJean1 commented 2 years ago

Attached is an other, different zip file containing the same psgvlc.py file as above, but a tkvlc.py enhanced to try to find the libtkX.Y.dylib in the Homebrew directory /opt/local/Cellar/..... If you have a chance, please try this combination on your enviroment as follows and without setting env variable TKVLC_LIBTK_PATH ...

% python3 tkvlc.py -v

The output should look like this, especially important is the line starting with libTk: ...

tkvlc.py: 22.11.05
tkinter: 8.6
libTk: /Library/Frameworks/Python.framework/Versions/3.11/lib/libtk8.6.dylib  <-------
vlc.py: 3.0.12119 (Mon May 31 18:25:17 2021 3.0.12)
libVLC: 3.0.16 Vetinari (0x3001000)
plugins: /Applications/VLC.app/Contents/MacOS/plugins
Python: 3.11.0 (64bit) macOS 13.0 arm64

Thank you in advance for your effort.

tkvlcHb1.zip

Nbelles commented 2 years ago

Alright, this is some good progress! Thanks again for spending time on this, it is greatly appreciated @mrJean1.

I believe line 83 of tkvlc.py is missing a percent sign and should read: tk = 'no %s found, use %%s' % (tk,). The first time I ran it (without setting env variable but using python 3.11 website install) I got this at first:

/Users/nathaniel/Downloads/issue194/tkvlc.py:83: SyntaxWarning: 'str' object is not callable; perhaps you missed a comma?
  tk = 'no %s found, use %%s' (tk,)

but I was looking at the window and not the terminal though and didn't see this error until later and just assumed it didn't recognize my click or something so I added a file path to load again and tried clicking play and it started playing video for the first time. I then looked at the terminal to close the window and noticed the error that had been printed out to the screen. Just a little odd behavior but was able to get it working.

As for setting the environment variable and temporarily moving the python 3.11 install out of the way, I end up using python 3.10 that was installed via homebrew and we get video playback!

Some notes: I have previously not been able to run this example script so I don't know what the expected look of the example was but when first starting to play the video I do notice a couple things:

Nbelles commented 2 years ago

I will try the new code you just posted in a moment but I did want to add some insight to asking brew directly for the location of the tcl-tk install. From what I have found you can do something like brew info tcl-tk and it will print a bunch of info:

==> tcl-tk: stable 8.6.12 (bottled) [keg-only]
Tool Command Language
https://www.tcl-lang.org
/usr/local/Cellar/tcl-tk/8.6.12_1 (3,045 files, 51.8MB)
  Poured from bottle on 2022-11-04 at 09:48:21
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/tcl-tk.rb
License: TCL
==> Dependencies
Required: openssl@1.1 ✔
==> Caveats
The sqlite3_analyzer binary is in the `sqlite-analyzer` formula.

tcl-tk is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have tcl-tk first in your PATH, run:
  echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc

For compilers to find tcl-tk you may need to set:
  export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
  export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"

For pkg-config to find tcl-tk you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"

==> Analytics
install: 66,841 (30 days), 205,337 (90 days), 1,838,621 (365 days)
install-on-request: 9,378 (30 days), 30,415 (90 days), 287,738 (365 days)
build-error: 104 (30 days)

This you can then parse to get the address from the fourth line.

You can also do something like brew --cellar tcl-tk to get the folder of the package in the cellar /usr/local/Cellar/tcl-tk. You could then find it within this folder similar to what you made a comment about in the new code you just posted.

mrJean1 commented 2 years ago

My apologies for that missing % sign. The issue194v2.zip file uploaded later fixed that.

Correct, tkvlc.py behaves oddly because it tries to keep the video frame and buttons together somehow. The main thing to make sure is that the video is displayed with audio.

Try running the psgvlc.py. Important, keep both the psgvlc.py and tkvlc.py files in the same directory.

By default, Homebrew installs tcl-tk and the libtkX.Y.dylib file in a directory like /opt/local/Cellar/tcl-tk/X.Y*/lib/libtkX.Y.dylib. Correct? Or is it /usr/local/Cellar/...? Or both? __ PS) I tried installing Homebrew tcl-tk, but that failed: my Apple development environment is not up to date and most dependencies are missing. A project for another day.

Nbelles commented 2 years ago

Running your most recent code, tkvlcHb1 I get the following output:

tkvlc.py: 22.11.05
tkinter: 8.6
libTk: no libtk8.6.dylib found, use TKVLC_LIBTK_PATH
Nbelles commented 2 years ago

It seems like there are a bunch of possible locations that it could be found but I think a lot of them are symlinked to the same location. From my understanding the default install location is /usr/local/Cellar though. I just looked in my /opt folder and there isn't anything in it. No local folder or anything.

mrJean1 commented 2 years ago

Thank you. So, it is not /opt/local/Cellar/... (; Another update is forthcoming ... here is attempt #2, which tries both /opt/... and /usr/...

tkvlcHb2.zip

Nbelles commented 2 years ago

Hmmm seems like it still gives the same output as before and can't find the path...

Nbelles commented 2 years ago

My full path to the .dylib file is: /usr/local/Cellar/tcl-tk/8.6.12_1/lib/libtk8.6.dylib

mrJean1 commented 2 years ago

Ah, it is .../lib/libtk8.6.dylib ;) Attempt #3, hopefully the final one.

tkvlcHb3.zip

Nbelles commented 2 years ago

There we are!

tkvlc.py: 22.11.05
tkinter: 8.6
libTk: /usr/local/Cellar/tcl-tk/8.6.12_1/lib/libtk8.6.dylib
mrJean1 commented 2 years ago

Great! Thank you! One more thing, is the video playing with that tkvlc.py and/or psgvlc.py and that tkvlc.py?

Nbelles commented 2 years ago

Seems like it works out of the box now at least on this computer. The video is working properly when using psgvlc.py and tkvlc.py separately.

I'm gonna try it on another Mac I have real quick to see if it provides a similar result (despite having a very different python install setup).