4

I am hoping that someone can help with a Python bindings output question (using vlc.py)

I have a basic test script that uses vlc.py which runs but does not play the video.

import vlc

def setup_player(filename):
    vlc_instance = vlc.Instance('--no-audio', '--fullscreen')
    player = vlc_instance.media_player_new()
    media = vlc_instance.media_new(filename)
    player.set_media(media)
    print media.get_mrl() # File location to get title 
    print player.get_length() #Time duration of file -1 means there is no   media
    print player.get_state() #Player's state
    player.play()

setup_player('foo.mp4')

This outputs

file:///Users/admin/Sites/pythontest/foo.mp4
-1
State.NothingSpecial

I am unsure where to install the vlc.py module and hoping someone can help. I'm on MacOs, VLC 2.0.9, Python 2.7.3. Running python through the terminal.

At the moment I have the vlc.py module in the same directory as my test script - and outside of the VLC.app directories and although the script is executing without errors it isn't playing the video or returning any parameters about the specified mp4 file.

Apologies for a banal question! Any help very gratefully received.

2 Answers 2

4

It seems that the player.play() function is not blocking, but instead returns immediately.

If the Python script then terminates, the player is destroyed right after it has been created.

If you look at the example player in vlc.py, it has a while True loop at the very end that basically reads key presses over and over again in order to implement a simple user interface.

So if you simply add

while True:
    pass

at the end of your function, it should continue playing (terminate with CTRL+C until you implement some sort of user input handling).

As for "installing" the script: Unfortunately, the vlc.py module they provide is just that, a simple stand-alone Python module. It's not packaged as a setuptools distribution that you could just install with pip or easy_install like most other Python modules. That means you can (or rather have to) drop it into a location that will be in sys.path yourself.

The current working directory where you launch your script from works for that, but if you want a more permanent location you could drop it into your Python's site-packages (/Users/<your-username>/Library/Python/2.7/lib/python/site-packages for example if you're using the standard OS X framework Python).

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the advice about the installation of vlc.py. Using a while True: loop forced the video file to attempt to play, but it outputted a corrupt module: .. VLC.app/Contents/MacOS/lib/../plugins/libmacosx_plugin.dylib , so I am reinstalling vlc.
It seems that to simply test the vlc.py module you can use its built in player with $ python vlc.py /path/to/file.mp4 usefully documented here
@rod exactly - that's where I assumed you based your script on actually :)
@rod I get the same thing here - corrupt libraries, even though VLC itself is working fine (VLC 2.1.4, OS X 10.9.5). Video playback using the Python bindings currently doesn't work for me, audio works fine though.
re-installing vlc hasn't worked and it seems vlc.py hasn't been built for 64 bit architecture as per this post.
|
1

Since the API calls succeed, it means that the bindings work correctly. The problem here is rather that the macos x video output module is not able to instanciate its own window. It must be embedded in a native Cocoa widget. You can use the qt example from the vlc repository or use the x11 video output module, combined with the MacOS X X11 server (which has to be installed for recent versions of MacOS X).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.