when i am trying to play a video with python-vlc in pyqt5 like
import vlc,sys
from PyQt5.QtWidgets import *
app = QApplication([])
window = QWidget()
window.resize(500,500)
window.show()
instance=vlc.Instance()
p=instance.media_player_new()
p.set_hwnd(window.winId())
p.set_media(instance.media_new(path_to_media))
p.play()
sys.exit(app.exec_())
It prints lot of errors in console like
[032ac2b0] direct3d11 vout display error: Direct3D11 could not be opened
[032ac2b0] direct3d11 vout display error: SetThumbNailClip failed: 0x800706f4
[0325de20] d3d11va generic error: D3D11CreateDevice failed. (hr=0x80004001)
[0325de20] d3d11va generic error: Failed to create device
[032ac2b0] direct3d9 vout display error: SetThumbNailClip failed: 0x800706f4
[032ad4f8] direct3d11 vout display error: Could not Create the D3D11 device. (hr=0x80004001)
[032ad4f8] direct3d11 vout display error: Direct3D11 could not be opened
[032ad4f8] direct3d11 vout display error: SetThumbNailClip failed: 0x800706f4
[0325e3c0] dxva2 generic error: FindVideoServiceConversion failed
[032ad4f8] direct3d9 vout display error: SetThumbNailClip failed: 0x800706f4
[032acee0] direct3d11 vout display error: Could not Create the D3D11 device. (hr=0x80004001)
[032acee0] direct3d11 vout display error: Direct3D11 could not be opened
[032acee0] direct3d11 vout display error: SetThumbNailClip failed: 0x800706f4
I want to capture one line from all those printed error.and that process has to run all time.cause i dont know when the error line will print. Is there any way ,that i can detect detect?
Edit For Review
I have successfully implemented what discussed in that forum and got the result after little bit modification.Here is the code
import vlc,sys
from PyQt5.QtWidgets import *
import ctypes
# Prepare `vsnprintf` function
if sys.platform.startswith('win'):
# Note: must use same version of libc as libvlc
vsnprintf = ctypes.cdll.msvcrt.vsnprintf
else:
libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('c'))
vsnprintf = libc.vsnprintf
vsnprintf.restype = ctypes.c_int
vsnprintf.argtypes = (
ctypes.c_char_p,
ctypes.c_size_t,
ctypes.c_char_p,
ctypes.c_void_p,
)
# Your callback here
@vlc.CallbackDecorators.LogCb
def log_callback(data, level, ctx, fmt, args):
# Skip if level is lower than warning
if level < 3:
return
# Format given fmt/args pair
BUF_LEN = 1024
outBuf = ctypes.create_string_buffer(BUF_LEN)
vsnprintf(outBuf, BUF_LEN, fmt, args)
# Print it out, or do something else
print('LOG: ' + outBuf.raw.replace(b"\x00",b"").decode())
# Set callback to the libvlc instance
app = QApplication([])
window = QWidget()
window.resize(500,500)
window.show()
instance=vlc.Instance()
instance.log_set(log_callback, None)
p=instance.media_player_new()
p.set_hwnd(window.winId())
p.set_media(instance.media_new(r"D:\Y2Mate.is - Starla Edney - Queen of Hearts (by Monoir) [Official Video]-o7c5LxzmZvs-480p-1636735291163.mp4"))
p.play()
sys.exit(app.exec_())
----OUTPUT-----
LOG: buffer too late (-95361 us): dropped
LOG: buffer too late (-73141 us): dropped
LOG: playback too late (74687): up-sampling
LOG: unsupported control query 3
But the problem arises when i use this inside a class because I want to use a pyqtsignal.
import vlc,sys,ctypes
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class logPrinter(QObject):
logerror=pyqtSignal() # I want to use a pyqtsignal after getting a specified error ,so i use Class
def __init__(self):
super().__init__()
@vlc.CallbackDecorators.LogCb
def log_callback(self,data, level, ctx, fmt, args):
# Skip if level is lower than warning
if level < 3:
return
# Format given fmt/args pair
BUF_LEN = 1024
outBuf = ctypes.create_string_buffer(BUF_LEN)
vsnprintf(outBuf, BUF_LEN, fmt, args)
# Print it out, or do something else
print('LOG: ' + outBuf.raw.replace(b"\x00",b"").decode())
# Set callback to the libvlc instance
class Window(QWidget):
def __init__(self):
super().__init__()
self.resize(500,500)
instance=vlc.Instance()
self.log_printer=logPrinter()
instance.log_set(self.log_printer.log_callback, None)
p=instance.media_player_new()
p.set_hwnd(self.winId())
p.set_media(instance.media_new(path_to_media))
p.play()
app = QApplication([])
window = Window()
window.show()
sys.exit(app.exec_())
Video is playing but it generating error continuously
Exception ignored on calling ctypes callback function: <function logPrinter.log_callback at 0x02B7BCD0>
TypeError: log_callback() missing 1 required positional argument: 'args'
Exception ignored on calling ctypes callback function: <function logPrinter.log_callback at 0x02B7BCD0>
TypeError: log_callback() missing 1 required positional argument: 'args'
Exception ignored on calling ctypes callback function: <function logPrinter.log_callback at 0x02B7BCD0>
TypeError: log_callback() missing 1 required positional argument: 'args'
I think using that log_callback() inside class causing error for mismatch in method arguments/parameters.