The VLC media player is a free and open-source portable cross-platform media player software and streaming media server developed by the VideoLAN project. VLC is available for desktop operating systems and mobile platforms, such as Android, iOS, iPadOS, Tizen, Windows 10 Mobile, and Windows Phone.
We can use the VLC media player with the help of python as well, in order to install vlc module in python we will use the command given below
pip install python-vlc
Note: In order to use the vlc module in python, the user system should have vlc media player already installed on the machine.
Importing the VLC Module:
To import the VLC module use the following
import vlc
Fixing error that may occur while importing vlc module
1. If path is not added, the problem is that libvlc.dll is not in the PATH(System Variable). Just add the file libvlc.dll path to system variable, this file can be found in the vlc folder where it is installed
2. Wrong version of VLC, oftenly people download 32bits vlc’s version. This may cause some trouble if we have installed the 64 bits version of python. To fix that, we just need to reinstall the 64 bits vlc’s version.
3. Import os module prior to vlc module and register libvlc.dll using os.add_dll_directory(r’C:\Program Files\VideoLAN\VLC’).
Example 1: Playing Video using VLC
Python3
import vlc
media = vlc.MediaPlayer( "1.mp4" )
media.play()
|
Output :

Example 2: Here we will derive the duration of a video file using the VLC module.
Python3
import time, vlc
def video(source):
vlc_instance = vlc.Instance()
player = vlc_instance.media_player_new()
media = vlc_instance.media_new(source)
player.set_media(media)
player.play()
time.sleep( 0.5 )
duration = player.get_length()
print ( "Duration : " + str (duration))
video( "your_video.mp4" )
|
Output :
Duration : 5006