Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. URL Video Display Using QThread
Forum Updated to NodeBB v4.3 + New Features

URL Video Display Using QThread

Scheduled Pinned Locked Moved Solved Qt for Python
5 Posts 3 Posters 548 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vidyul
    wrote on last edited by
    #1

    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, QMediaContent

    os.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.HilkJ 1 Reply Last reply
    0
    • V vidyul

      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, QMediaContent

      os.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.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @vidyul you can't.

      QMediaPlayer as a GUI element has to live in the main thread.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      V 1 Reply Last reply
      1
      • J.HilkJ J.Hilk

        @vidyul you can't.

        QMediaPlayer as a GUI element has to live in the main thread.

        V Offline
        V Offline
        vidyul
        wrote on last edited by
        #3

        @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?

        JonBJ 1 Reply Last reply
        0
        • V vidyul

          @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?

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @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.

          V 1 Reply Last reply
          1
          • JonBJ JonB

            @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.

            V Offline
            V Offline
            vidyul
            wrote on last edited by
            #5

            @JonB Ok I will try to see my code and hardware that which one is giving that problem. Thanks for the help.

            1 Reply Last reply
            1
            • V vidyul has marked this topic as solved on

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved