UDP Video Streaming into QMediaPlayer (Qt6.6)
-
I am trying to stream video feed into QMediaPlayer and I am having a hard time.
Specs
QT 6.6
PySide6 (6.6.0)OS Tried
Ubuntu 22.04.3 LTS (running on arm64 - macOS (m1 MacBook Pro)- vmware fusion)
MacOs Ventura (m1 MacBook pro)I am using the following code,
from PySide6.QtMultimedia import QMediaPlayer from PySide6.QtCore import QUrl, QTimer from PySide6.QtMultimediaWidgets import QVideoWidget from PySide6.QtWidgets import QWidget, QPushButton, QVBoxLayout class VideoViewer(QWidget): def __init__(self): super(VideoViewer, self).__init__() self.vid_layout = QVBoxLayout() self._get_video_btn = QPushButton("Get Video") self._get_video_btn.clicked.connect(self.play_video) self._player = QMediaPlayer() self._video_widget = QVideoWidget() self._player.setVideoOutput(self._video_widget) self.vid_layout.addWidget(self._get_video_btn) self.vid_layout.addWidget(self._video_widget) self.setLayout(self.vid_layout) def play_video(self): udp_source_url = "udp://127.0.0.1:1234/?udpsrc.caps=application/x-rtp,media=video,clock-rate=90000,encoding=H264,payload=26" # Replace with your actual UDP source URL media_content = QUrl(udp_source_url) self._player.setSource(media_content) # Play the video self._player.play()
Testing Stream
gst-launch-1.0 videotestsrc pattern=ball ! video/x-raw,width=640,height=480 ! x264enc ! rtph264pay ! udpsink host=127.0.0.1 port=5600 code_text
or simply to view webcam as a udp stream (
gst-launch-1.0 -v v4l2src device=/dev/video0 ! videoconvert ! video/x-raw,format=I420 ! x264enc tune=zerolatency ! rtph264pay ! udpsink host=127.0.0.1 port=5600
)I can view it fine using another gstreamer pipeline.
gst-launch-1.0 udpsrc port=5600 ! application/x-rtp ! rtpjitterbuffer ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink
I also tried switching backends.
os.environ['QT_MEDIA_BACKEND'] = 'gstreamer' or 'ffmpeg' os.environ['QT_DEFAULT_MEDIA_BACKEND'] = 'gstreamer' or 'ffmpeg'
I went through all the forum past q&a and have no luck. Has anyone managed to stream udp using Qmediaplayer? If so please let me know. Highly appreciated!
-
Hi,
Are you trying to use a custom GStreamer pipeline ? If so, it won't work with PySide6. The multimedia module has seen a big rewrite that removed that feature.
-
@SGaist What are the standard UDP specs that QMediaPlayer Can read?
at the moment I am trying to view this,
gst-launch-1.0 videotestsrc pattern=ball ! video/x-raw,width=640,height=480 ! x264enc ! rtph264pay ! udpsink host=127.0.0.1 port=5600 code_text
as a test stream. Final goal is to use a viewpro camera udp output.
I tried to find the formats that can stream via QMediaPlayer and didn't find much.