Python-VLC Bindings

3.0.21203 · active · verified Fri Apr 17

Python-VLC provides Python bindings for the VLC media player. It allows developers to integrate VLC's powerful multimedia capabilities, such as playing audio and video, streaming, and capturing, directly into Python applications. The current version, 3.0.21203, is generally kept in sync with major VLC releases, reflecting VLC 3.x features. While releases aren't on a strict cadence, updates typically follow significant VLC player developments.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates initializing VLC, loading a media file, and playing it for a short duration. Remember to replace the placeholder media path with an actual file and ensure VLC media player is installed.

import vlc
import time
import os

# NOTE: You MUST have VLC media player installed on your system.
# For Windows: ensure VLC is installed and its directory (e.g., C:\Program Files\VideoLAN\VLC) is in your PATH.
# For Linux/macOS: VLC libraries are usually found automatically if installed via package manager.

# Create a VLC instance
instance = vlc.Instance(['--no-xlib'])

# Create a media player
player = instance.media_player_new()

# Path to a dummy video file for demonstration.
# Replace 'path/to/your/video.mp4' with an actual video file on your system.
# For testing, you can download a sample video or create a dummy file.
# Example: 'file:///home/user/Videos/test.mp4' or 'C:\Users\User\Videos\test.mp4'
media_file = os.environ.get('VLC_TEST_MEDIA_PATH', 'file:///path/to/your/video.mp4')

# Create a media object from the file
media = instance.media_new(media_file)

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

# Play the media
print(f"Attempting to play: {media_file}")
player.play()

# Wait for a few seconds to allow playback (adjust as needed)
time.sleep(5) 

# Stop the player
player.stop()
print("Playback stopped.")

view raw JSON →