Skip to content

Instantly share code, notes, and snippets.

@sulincix
Created November 15, 2022 13:37
Show Gist options
  • Save sulincix/2699ab1b81d272e1d3b409dccf5bf778 to your computer and use it in GitHub Desktop.
Save sulincix/2699ab1b81d272e1d3b409dccf5bf778 to your computer and use it in GitHub Desktop.
PyQt5 rtsp viewer
#/usr/bin/env python3
from PyQt5.QtGui import QIcon, QFont
from PyQt5.QtCore import QDir, Qt, QUrl, QSize
from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
from PyQt5.QtMultimediaWidgets import QVideoWidget
from PyQt5.QtWidgets import (QApplication, QVBoxLayout, QWidget, QLabel)
# https://doc.qt.io/qtforpython-5/PySide2/QtMultimedia/QMediaPlayer.html
class VideoPlayer(QWidget):
def __init__(self, parent=None, link=""):
super(VideoPlayer, self).__init__(parent)
self.setWindowTitle("PyQt5 rtsp viewer")
label_1_text = "URL: "+link
label_1 = QLabel(label_1_text, self)
# setting the fixed height of window
self.setFixedHeight(400)
self.setFixedWidth(600)
self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface)
videoWidget = QVideoWidget()
layout = QVBoxLayout()
layout.addWidget(label_1)
layout.addWidget(videoWidget)
self.setLayout(layout)
self.mediaPlayer.setVideoOutput(videoWidget)
self.mediaPlayer.setMedia(QMediaContent(QUrl(link)))
self.mediaPlayer.play()
def closeEvent(self, event):
print("Good Bye ...")
self.mediaPlayer.stop()
event.accept()
#event.ignore()
if __name__ == '__main__':
# For Ctrl+C close in terminal
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
# Start Main
import sys
app = QApplication(sys.argv)
player = VideoPlayer(link="rtsp://161.9.194.183/1")
#player.resize(600, 400)
player.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment