Can not import vlc to python program

…衆ロ難τιáo~ 提交于 2021-02-05 09:44:48

问题


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?


回答1:


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.




回答2:


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)


来源:https://stackoverflow.com/questions/56705830/can-not-import-vlc-to-python-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!