0

I'm trying to reproduce a video with sound in python Tkinter through VLC, but cannot run the file since I get an error when running the line import vlc.

I have python 3 at 32 bits, VLC player at 32 bits and installed it through pip install python-VLC, which was successful and then try to run the code and get this error:

File "C:/Users/momoh/Documents/GitHub/CNDH/CNDH.py", line 5, in <module>
    import vlc
  File "C:\Users\momoh\AppData\Local\Programs\Python\Python36-32\lib\site-packages\vlc.py", line 207, in <module>
    dll, plugin_path  = find_lib()
  File "C:\Users\momoh\AppData\Local\Programs\Python\Python36-32\lib\site-packages\vlc.py", line 163, in find_lib
    dll = ctypes.CDLL(libname)
  File "C:\Users\momoh\AppData\Local\Programs\Python\Python36-32\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found 

This is the code that I´m tryin to run: My imports:

import sys
import tkinter as tk           
from tkinter import font  as tkfont 
from PIL import ImageTk, Image
import vlc

and the class for the frame that has the video

class PageThree(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        self.grid_columnconfigure(0, weight=0)
        self.grid_columnconfigure(1, weight=1)
        self.grid_columnconfigure(2, weight=2)
        self.grid_columnconfigure(3, weight=1)
        self.grid_columnconfigure(4, weight=0)
        self.grid_rowconfigure(0, weight=0)
        self.grid_rowconfigure(1, weight=1)
        self.grid_rowconfigure(2, weight=2)
        self.grid_rowconfigure(3, weight=3)
        self.grid_rowconfigure(4, weight=2)
        self.grid_rowconfigure(5, weight=1)
        self.grid_rowconfigure(6, weight=6)

        self.configure(background="white")


        # Open the video source |temporary
        self.video_source = "assetsCNDH/prueba.mp4"

        # Canvas where to draw video output
        self.canvas = tk.Canvas(self, width= controller.winfo_screenwidth(),
                                height=controller.winfo_screenheight(), bg="black",
                                    highlightthickness=0)
        self.canvas.pack()

        # Creating VLC player
        self.instance = vlc.Instance()
        self.player = self.instance.media_player_new()

    def GetHandle(self):
        # Getting frame ID
        return self.winfo_id()

    def play(self, _source):
        # Function to start player from given source
        Media = self.instance.media_new(_source)
        Media.get_mrl()
        self.player.set_media(Media)

        # self.player.play()
        self.player.set_hwnd(self.GetHandle())
        self.player.play()

How do I get my video running?

2 Answers 2

5

Python-vlc is a binding of python to vlc program (or wrapper libraries). It is a way to run vlc program via python (python -> binding -> vlc). It will not run the vlc program itself so you need to do the following steps:

1)  download vlc program and install it in your machine
2)  restart your machine
3)  run notebook again

You may download and install vlc (64-bit) in this link: https://www.videolan.org/vlc/

Reference:

https://wiki.videolan.org/PythonBinding

quote:

Note that this only installs the python module itself, which depends on the availability of the libvlc libraries. You must also install VLC itself to get these libraries.

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

3 Comments

I have already installed VLC in the same bits version as my python. But it can't find it. How do I give it to the import?
What plugins are needed so I give the direct path?
Thanks for the answer, For me the 32bit version was not working even after adding its folder to the PATH environment variable, But installing the 64bit version solved the issue!
0

I ended up using subprocess to run VLC through the CLI.

import subprocess


comand = 'vlc --play-and-exit --no-video-deco --no-embedded-video -f --one-instance --no-playlist-enqueue  assetsCNDH\\directorio.mp4'
subprocess.run(comand, shell=True)

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.