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. How to overlay a text with an video (QVideoWiget)
Forum Updated to NodeBB v4.3 + New Features

How to overlay a text with an video (QVideoWiget)

Scheduled Pinned Locked Moved Unsolved Qt for Python
python
3 Posts 3 Posters 1.8k Views 2 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.
  • A Offline
    A Offline
    amaimon02
    wrote on last edited by
    #1

    I would like a text on a video. I use a QVideoWidget to play the video.

    from PyQt5 import QtCore, QtGui, QtWidgets, QtMultimedia
    
    from GUI import Ui_MainWindow
    
    class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
        def __init__(self, *args, **kwargs):
            QtWidgets.QMainWindow.__init__(self, *args, **kwargs)
            self.setupUi(self)
    
            self.mediaPlayer = QtMultimedia.QMediaPlayer(self)
            self.mediaPlayer.setVideoOutput(self.widget)
            # fileName = "/path/of/your/local_file"
            # url = QtCore.QUrl.fromLocalFile(fileName)
            url = QtCore.QUrl("http://clips.vorwaerts-gmbh.de/VfE_html5.mp4")
            self.mediaPlayer.setMedia(QtMultimedia.QMediaContent(url))
            self.mediaPlayer.play()
    
    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        w = MainWindow()
        w.show()
        sys.exit(app.exec_())
    
    JonBJ 1 Reply Last reply
    0
    • A amaimon02

      I would like a text on a video. I use a QVideoWidget to play the video.

      from PyQt5 import QtCore, QtGui, QtWidgets, QtMultimedia
      
      from GUI import Ui_MainWindow
      
      class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
          def __init__(self, *args, **kwargs):
              QtWidgets.QMainWindow.__init__(self, *args, **kwargs)
              self.setupUi(self)
      
              self.mediaPlayer = QtMultimedia.QMediaPlayer(self)
              self.mediaPlayer.setVideoOutput(self.widget)
              # fileName = "/path/of/your/local_file"
              # url = QtCore.QUrl.fromLocalFile(fileName)
              url = QtCore.QUrl("http://clips.vorwaerts-gmbh.de/VfE_html5.mp4")
              self.mediaPlayer.setMedia(QtMultimedia.QMediaContent(url))
              self.mediaPlayer.play()
      
      if __name__ == "__main__":
          import sys
          app = QtWidgets.QApplication(sys.argv)
          w = MainWindow()
          w.show()
          sys.exit(app.exec_())
      
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @amaimon02
      Google for qvideowidget text. There are a few hits, they will show if it can be done at all.

      1 Reply Last reply
      1
      • KH-219DesignK Offline
        KH-219DesignK Offline
        KH-219Design
        wrote on last edited by
        #3

        I have never used QVideoWidget, but based on some prior experience with different GUI frameworks, I would caution that your results may vary by operating system, and by whatever underlying video playback engine is ultimately responsible for getting the video pixels on the screen.

        I tried to do something like this a while ago, and on one platform the text window (a transparent window with opaque text) that I tried to place on top of the video window worked just fine. On another platform the text was barely noticeable. You could only notice it flicker into view occasionally, like some kind of subliminal messaging. I believe the reason for the unwanted "flicker behavior" on that system was due to the video engine constantly writing directly to the video card, bypassing any attempts at layering/compositing.

        www.219design.com
        Software | Electrical | Mechanical | Product Design

        1 Reply Last reply
        1

        • Login

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