无法将VLC导入python程序

时间:2019-06-21 14:55:42

标签: python windows tkinter vlc

我正在尝试通过VLC在python Tkinter中复制带有声音的视频,但是由于运行行导入vlc时出现错误,因此无法运行文件。

我有32位的python 3、32位的VLC播放器,并通过pip install python-VLC安装了它,成功了,然后尝试运行代码并得到此错误:

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 

这是我尝试运行的代码: 我的进口货:

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

以及具有视频的帧的类

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()

如何运行视频?

2 个答案:

答案 0 :(得分:0)

Python-vlc是python与vlc程序(或包装器库)的绑定。这是通过python运行vlc程序的一种方式(python->绑定-> vlc)。它不会运行vlc程序本身,因此您需要执行以下步骤:

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

您可以在以下链接中下载并安装vlc(64位):https://download.cnet.com/VLC-Media-Player-64-bit/3000-13632_4-75761094.html

参考:

https://wiki.videolan.org/PythonBinding

引用:

  

请注意,这只会安装python模块本身,具体取决于   关于libvlc库的可用性。您还必须安装VLC   本身以获得这些库。

答案 1 :(得分:0)

我最终使用子进程通过CLI运行VLC。

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)