Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsVideoItem not working with GStreamer media source

QGraphicsVideoItem not working with GStreamer media source

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 570 Views
  • 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.
  • X Offline
    X Offline
    Xavier Bento
    wrote on last edited by Xavier Bento
    #1

    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

    X 1 Reply Last reply
    0
    • X Xavier Bento

      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

      X Offline
      X Offline
      Xavier Bento
      wrote on last edited by
      #2

      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 code

      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 ! 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);
      }
      
      1 Reply Last reply
      2
      • Pl45m4P Pl45m4 referenced this topic on

      • Login

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