eyllanesc / QtExamples

Translations of the official Qt examples into PyQt5 (also PySide2) and more. :bowtie: :octocat:
GNU General Public License v3.0
52 stars 11 forks source link

How can I put text on a video using pyqt5? #1

Closed hirios closed 4 years ago

hirios commented 4 years ago

If possible, could you give me an example of how to overlay text or QFrame over a video? In my script I use QVideoWidget for playback.

Thanks in advance !!

eyllanesc commented 4 years ago

@hirios You can use QGraphicsVideoItem as I show in this example ScreenShot

hirios commented 4 years ago

Omg, that was exactly what I wanted. QT is incredible, you are incredible !! Thank you very much!!

fuedgabriel commented 4 years ago

I was also looking for that. Could you create a simpler example? I used qt desiner to create the interface and used a QVideoWidget to play the video. I also used your stackoverflow code:


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_())
eyllanesc commented 4 years ago

@fuedgabriel I don't understand what you mean by a simpler code, my example is simple: Use items on top a QGraphicsVideoItem.