QGraphicsVideoItem not working with GStreamer media source
-
Good afternoon,
I'm having some trouble using a QGraphicsVideoItem with a GStreamer pipeline as source.
I'm trying to show the video on a QMdiSubWindow, and using a QVideoWidget it works, but i need to draw some boxes on top on the video and followed this forum topic.
Using a local file instead of the GStreamer pipeline shows the video with no problems.
To avoid an XY problem, TLDR: trying to draw rectangles on top of a video inside of a QMdiSubWindow whose source is a GStreamer pipeline.
Here's the code for my subclassed subwindow
videoSubWindow::videoSubWindow(int shmID, int width, int height, QWidget* parent): QMdiSubWindow(), shmID(shmID), player(nullptr), videoWidget(nullptr) { std::cerr << __func__ << "\n"; std::string playerLaunch = "gst-pipeline: shmsrc socket-path=/tmp/shm" + std::to_string(shmID) + " ! video/x-raw, format=(string)I420, width=(int)" + std::to_string(width) + ", height=(int)" + std::to_string(height) + ", framerate=(fraction)30/1 ! queue ! xvimagesink name=qtvideosink"; videoWidget = new roiVideoWidget(this); scene = new QGraphicsScene(videoWidget); item = new QGraphicsVideoItem; videoWidget->setScene(scene); scene->addItem(item); player = new QMediaPlayer; player->setVideoOutput(item); player->setMedia(QUrl(playerLaunch.c_str())); //player->setMedia(QUrl::fromLocalFile("testvideo.mp4")); setWidget(videoWidget); setAttribute(Qt::WA_DeleteOnClose); }Thanks in advance for any help.
PS: Using Qt 5.12 on Ubuntu 20.04 and GCC 10
-
Good afternoon,
I'm having some trouble using a QGraphicsVideoItem with a GStreamer pipeline as source.
I'm trying to show the video on a QMdiSubWindow, and using a QVideoWidget it works, but i need to draw some boxes on top on the video and followed this forum topic.
Using a local file instead of the GStreamer pipeline shows the video with no problems.
To avoid an XY problem, TLDR: trying to draw rectangles on top of a video inside of a QMdiSubWindow whose source is a GStreamer pipeline.
Here's the code for my subclassed subwindow
videoSubWindow::videoSubWindow(int shmID, int width, int height, QWidget* parent): QMdiSubWindow(), shmID(shmID), player(nullptr), videoWidget(nullptr) { std::cerr << __func__ << "\n"; std::string playerLaunch = "gst-pipeline: shmsrc socket-path=/tmp/shm" + std::to_string(shmID) + " ! video/x-raw, format=(string)I420, width=(int)" + std::to_string(width) + ", height=(int)" + std::to_string(height) + ", framerate=(fraction)30/1 ! queue ! xvimagesink name=qtvideosink"; videoWidget = new roiVideoWidget(this); scene = new QGraphicsScene(videoWidget); item = new QGraphicsVideoItem; videoWidget->setScene(scene); scene->addItem(item); player = new QMediaPlayer; player->setVideoOutput(item); player->setMedia(QUrl(playerLaunch.c_str())); //player->setMedia(QUrl::fromLocalFile("testvideo.mp4")); setWidget(videoWidget); setAttribute(Qt::WA_DeleteOnClose); }Thanks in advance for any help.
PS: Using Qt 5.12 on Ubuntu 20.04 and GCC 10
Nevermind, i fixed it, just had to update to Qt5.15 to get access to the video surface of the QGraphicsVideoItem and update the videosink to autovideosink.
Here is my solution's codevideoSubWindow::videoSubWindow(int shmID, int width, int height, QWidget* parent): QMdiSubWindow(), shmID(shmID), player(nullptr), videoWidget(nullptr) { std::cerr << __func__ << "\n"; std::string playerLaunch = "gst-pipeline: shmsrc socket-path=/tmp/shm" + std::to_string(shmID) + " ! video/x-raw, format=(string)I420, width=(int)" + std::to_string(width) + ", height=(int)" + std::to_string(height) + ", framerate=(fraction)30/1 ! queue ! videoconvert ! autovideosink"; scene = new QGraphicsScene(videoWidget); videoWidget = new roiVideoWidget(scene, this); videoItem = new QGraphicsVideoItem; scene->addItem(videoItem); player = new QMediaPlayer; player->setVideoOutput(videoItem->videoSurface()); player->setMedia(QUrl(playerLaunch.c_str())); player->play(); setWidget(videoWidget); setAttribute(Qt::WA_DeleteOnClose); } -
P Pl45m4 referenced this topic on