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. Pyqt5 and Gstreamer, how to setup layout and draw over the video.
Forum Updated to NodeBB v4.3 + New Features

Pyqt5 and Gstreamer, how to setup layout and draw over the video.

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 4 Posters 4.1k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    spiderdab
    wrote on last edited by spiderdab
    #1

    Hi, I'm quite new to qt, but not to code. I need to play a Gstreamer pipeline in a window, with some buttons around and the possibility to draw and write text on the video (an ip camera stream).

    what I have working is just playing the video inside a window, but since the video is linked to the window by a WindowId, I cannot put it inside a layout to show other gui widgets.
    Any suggestion on how to solve that?

    my code:

    import sys
    import gi
    gi.require_version('Gst', '1.0')
    gi.require_version('GstVideo', '1.0')
    from gi.repository import GObject, Gst, GstVideo
    from PyQt5.QtWidgets import *
    
    Gst.init(sys.argv)
    
    
    class MainWindow(QMainWindow):
        def __init__(self, parent = None):
            super(MainWindow, self).__init__(parent)
    
            self.pipeline = Gst.parse_launch(
                'videotestsrc name=source ! videoconvert name = convert ! xvimagesink name=sink')  # xvimagesink, ximagesink
            self.source = self.pipeline.get_by_name("source")
            self.videoconvert = self.pipeline.get_by_name("convert")
            self.sink = self.pipeline.get_by_name("sink")
    
            self.display = QWidget()
    
            self.setGeometry(100, 100, 640, 480)
            self.setWindowTitle("Prova_gst_qt5")
    
            self.windowId = self.winId()
    
        def setup_pipeline(self):
    
            self.state = Gst.State.NULL
            self.source.set_property('pattern', 0)
    
            if not self.pipeline or not self.source or not self.videoconvert or not self.sink:
                print("ERROR: Not all elements could be created")
                sys.exit(1)
    
            # instruct the bus to emit signals for each received message
            # and connect to the interesting signals
            bus = self.pipeline.get_bus()
    
            bus.add_signal_watch()
            bus.enable_sync_message_emission()
            bus.connect('sync-message::element', self.on_sync_message)
    
        def on_sync_message(self, bus, msg):
            if msg.get_structure().get_name() == 'prepare-window-handle':
                msg.src.set_window_handle(self.windowId)
    
        def start_pipeline(self):
            self.pipeline.set_state(Gst.State.PLAYING)
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        window = MainWindow()
        window.setup_pipeline()
        window.start_pipeline()
        window.show()
        sys.exit(app.exec_())
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      If you are using a recent enough version of Qt, you might be able to simplify your code using a custom pipeline like describe here.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Y Offline
        Y Offline
        yossiovcharik
        wrote on last edited by
        #3

        I've tested the example ad it seems to be working fine.

        Do you, by any chance have similar example for QtQuick (QML) form?

        1 Reply Last reply
        0

        • Login

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