无法将 vlc 导入 python 程序
Can not import vlc to python program
我正在尝试通过 VLC 在 python Tkinter 中重现带声音的视频,但无法 运行 文件,因为在 运行 导入行 import vlc 时出现错误.
我有 python 3 32 位,VLC 播放器 32 位并通过 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
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()
如何获取我的视频 运行ning?
Python-vlc 是 python 到 vlc 程序(或包装库)的绑定。这是通过 python (python -> binding -> vlc) 运行 vlc 程序的一种方式。它不会 运行 vlc 程序本身,因此您需要执行以下步骤:
1) download vlc program and install it in your machine
2) restart your machine
3) run notebook again
您可以在此link下载并安装vlc(64位):https://www.videolan.org/vlc/
参考:
https://wiki.videolan.org/PythonBinding
引用:
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.
我最终通过 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)
我正在尝试通过 VLC 在 python Tkinter 中重现带声音的视频,但无法 运行 文件,因为在 运行 导入行 import vlc 时出现错误.
我有 python 3 32 位,VLC 播放器 32 位并通过 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
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()
如何获取我的视频 运行ning?
Python-vlc 是 python 到 vlc 程序(或包装库)的绑定。这是通过 python (python -> binding -> vlc) 运行 vlc 程序的一种方式。它不会 运行 vlc 程序本身,因此您需要执行以下步骤:
1) download vlc program and install it in your machine
2) restart your machine
3) run notebook again
您可以在此link下载并安装vlc(64位):https://www.videolan.org/vlc/
参考:
https://wiki.videolan.org/PythonBinding
引用:
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.
我最终通过 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)