URL Video Display Using QThread
-
I am trying to run a video coming from a url feed but I want to implement it using QThread. I tried a few logic but failed.
Any suggestions how to do it.
Here is the code I am trying to convert to QThread#!/usr/bin/env python3
import os, sys
from PyQt5 import QtWidgets
from PyQt5.QtCore import QLibraryInfo, pyqtSignal, QUrl, QTimer
from PyQt5.QtWidgets import QDialog, QApplication
from PyQt5.uic import loadUi
from PyQt5.QtGui import QImage
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContentos.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = QLibraryInfo.location(
QLibraryInfo.PluginsPath
)class WindowPop(QDialog):
ImageUpdate = pyqtSignal(QImage)def __init__(self): super(WindowPop, self).__init__() loadUi('WindowPop.ui', self) try: self.media_player = QMediaPlayer(None, QMediaPlayer.VideoSurface) self.media_player.setVideoOutput(self.video_label) media_content = QMediaContent(QUrl("rtsp://192.168.4.218:5000/test")) self.media_player.setMedia(media_content) self.timer = QTimer(self) #self.timer.timeout.connect(self.update_video_label) self.timer.start(0) # Set the update interval in milliseconds self.media_player.stateChanged.connect(self.on_state_changed) self.media_player.play() except Exception as e: print(e) def on_state_changed(self, state): if state == QMediaPlayer.StoppedState: print("Media player stopped")
app=QApplication(sys.argv)
mainwindow=WindowPop()
widget=QtWidgets.QStackedWidget()
widget.addWidget(mainwindow)
widget.show()
app.exec_() -
@J-Hilk Ok but when I was trying to get Video feed for two different UI (created using the same logic), in two different PC, there was latency in the video varying from 15 seconds to even two minutes.
I am using RTSP protocol, I don't think there has to be issue but I might not know its basics too.
Any suggestion or logic to develop the GUI in such a way that the latency decreases in both the UI? -
@vidyul
If you have "latency in the video varying from 15 seconds to even two minutes" what do you think attempting to use another thread would achieve? Do you think your main UI thread is so busy that it cannot service video updates for anything from 15 seconds to 2 minutes? Assuming not, then you have a problem elsewhere. -