Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Play Video using Gstreamer and QML
Forum Updated to NodeBB v4.3 + New Features

Play Video using Gstreamer and QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qt5.13.2qmlquick2gstreamer1.0video output
3 Posts 2 Posters 672 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.
  • V Offline
    V Offline
    vicky_mac
    wrote on last edited by vicky_mac
    #1

    Hi,

    I am trying to play video in QML using gstreamer with app sink. The video is playing but i have few concerns listed below:

    **1. Hardware five YUV NV12 format decoded frame which i converting to RGB using OpenVC. Need other suitable options if available.

    1. While running the application i see the memory consumed by the application is increasing overtime and finally crashes due to huge memory usage. Need to know why it's happening.

    2. Sometime the playback hangs for no reason,**

    Please find below program for reference:

    //Class to pull decoded data from Gstreamer pipeline
    int ImageProvider::width=1920;
    int ImageProvider::height=1080;
    GstSample* ImageProvider::sample =nullptr;
    GstBuffer* ImageProvider::sampleBuffer=nullptr;
    GstMapInfo ImageProvider::bufferInfo;
    cv::Mat ImageProvider::rgbMat(height + height/2,width,CV_8UC3,cv::Scalar(0,0,255));
    cv::Mat ImageProvider::yuvMat(height + height/2,width,CV_8UC1,cv::Scalar(0,0,255));
    cv::Mat ImageProvider::scaledMat(300,500,CV_8UC3,cv::Scalar(0,0,255));
    ImageProvider::ImageProvider(QObject *parent)
    {
        m_image = QImage(500,300,QImage::Format_RGB888);
        m_image.fill(Qt::black);
    }
    GstFlowReturn ImageProvider::newSample(GstAppSink *sink, gpointer gSelf)
    {
        ImageProvider* self = static_cast<ImageProvider* >(gSelf);
        sample = gst_app_sink_pull_sample(GST_APP_SINK(sink));
        if(sample != NULL)
        {
            sampleBuffer = gst_sample_get_buffer(sample);
            if(sampleBuffer != NULL)
            {
                gst_buffer_map(sampleBuffer, &bufferInfo, GST_MAP_READ);
                yuvMat = cv::Mat(height + height/2,width,CV_8UC1,bufferInfo.data);
                cv::cvtColor(yuvMat,rgbMat,cv::COLOR_YUV2RGB_NV12);
                cv::resize(rgbMat,scaledMat,cv::Size(500,300));
                self->m_image = QImage(scaledMat.data,scaledMat.cols,scaledMat.rows,QImage::Format_RGB888);
                if(self->m_image.isNull())
                {
                    qDebug() << "Image is null";
                }
                else
                {
                     emit self->imageChanged();
                }
                gst_buffer_unmap(sampleBuffer, &bufferInfo);
        }
        gst_sample_unref(sample);
    }
    return GST_FLOW_OK;
    }
    
    //QPaint class
     LiveVideoImage::LiveVideoImage(QQuickItem *parent)
    {
        m_image = QImage(500,300,QImage::Format_RGB888);
        m_image.fill(Qt::black);
    }
    
    void LiveVideoImage::setImage(const QImage &image)
    {
            m_image = image;
            if(m_image.size().width() > 0)
                update();
    }
    
    void LiveVideoImage::paint(QPainter *painter)
    {
                painter->drawImage(0,0,m_image);
    }
     
    
    // In main.cpp
        QQmlContext* context = engine.rootContext();
        qmlRegisterType<LiveVideoImage>("Test.VideoImage",1,0,"LiveImage");
    
    
    //QML File
    
    import Test.VideoImage 1.0
        Rectangle{
            width: 500
            height: 300
            id:videoPlayer
            x:parent.width*0.24
            y:parent.height*0.3
            LiveImage{
                width: 500
                height: 300
                image:LiveImageProvider.image
            }
        }
    

    Using Qt5.13.2
    @SGaist
    Please let me know if you need any other details

    V 1 Reply Last reply
    0
    • V vicky_mac

      Hi,

      I am trying to play video in QML using gstreamer with app sink. The video is playing but i have few concerns listed below:

      **1. Hardware five YUV NV12 format decoded frame which i converting to RGB using OpenVC. Need other suitable options if available.

      1. While running the application i see the memory consumed by the application is increasing overtime and finally crashes due to huge memory usage. Need to know why it's happening.

      2. Sometime the playback hangs for no reason,**

      Please find below program for reference:

      //Class to pull decoded data from Gstreamer pipeline
      int ImageProvider::width=1920;
      int ImageProvider::height=1080;
      GstSample* ImageProvider::sample =nullptr;
      GstBuffer* ImageProvider::sampleBuffer=nullptr;
      GstMapInfo ImageProvider::bufferInfo;
      cv::Mat ImageProvider::rgbMat(height + height/2,width,CV_8UC3,cv::Scalar(0,0,255));
      cv::Mat ImageProvider::yuvMat(height + height/2,width,CV_8UC1,cv::Scalar(0,0,255));
      cv::Mat ImageProvider::scaledMat(300,500,CV_8UC3,cv::Scalar(0,0,255));
      ImageProvider::ImageProvider(QObject *parent)
      {
          m_image = QImage(500,300,QImage::Format_RGB888);
          m_image.fill(Qt::black);
      }
      GstFlowReturn ImageProvider::newSample(GstAppSink *sink, gpointer gSelf)
      {
          ImageProvider* self = static_cast<ImageProvider* >(gSelf);
          sample = gst_app_sink_pull_sample(GST_APP_SINK(sink));
          if(sample != NULL)
          {
              sampleBuffer = gst_sample_get_buffer(sample);
              if(sampleBuffer != NULL)
              {
                  gst_buffer_map(sampleBuffer, &bufferInfo, GST_MAP_READ);
                  yuvMat = cv::Mat(height + height/2,width,CV_8UC1,bufferInfo.data);
                  cv::cvtColor(yuvMat,rgbMat,cv::COLOR_YUV2RGB_NV12);
                  cv::resize(rgbMat,scaledMat,cv::Size(500,300));
                  self->m_image = QImage(scaledMat.data,scaledMat.cols,scaledMat.rows,QImage::Format_RGB888);
                  if(self->m_image.isNull())
                  {
                      qDebug() << "Image is null";
                  }
                  else
                  {
                       emit self->imageChanged();
                  }
                  gst_buffer_unmap(sampleBuffer, &bufferInfo);
          }
          gst_sample_unref(sample);
      }
      return GST_FLOW_OK;
      }
      
      //QPaint class
       LiveVideoImage::LiveVideoImage(QQuickItem *parent)
      {
          m_image = QImage(500,300,QImage::Format_RGB888);
          m_image.fill(Qt::black);
      }
      
      void LiveVideoImage::setImage(const QImage &image)
      {
              m_image = image;
              if(m_image.size().width() > 0)
                  update();
      }
      
      void LiveVideoImage::paint(QPainter *painter)
      {
                  painter->drawImage(0,0,m_image);
      }
       
      
      // In main.cpp
          QQmlContext* context = engine.rootContext();
          qmlRegisterType<LiveVideoImage>("Test.VideoImage",1,0,"LiveImage");
      
      
      //QML File
      
      import Test.VideoImage 1.0
          Rectangle{
              width: 500
              height: 300
              id:videoPlayer
              x:parent.width*0.24
              y:parent.height*0.3
              LiveImage{
                  width: 500
                  height: 300
                  image:LiveImageProvider.image
              }
          }
      

      Using Qt5.13.2
      @SGaist
      Please let me know if you need any other details

      V Offline
      V Offline
      vicky_mac
      wrote on last edited by
      #2

      @vicky_mac any one?

      JoeCFDJ 1 Reply Last reply
      0
      • V vicky_mac

        @vicky_mac any one?

        JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #3

        @vicky_mac The old gstreamer versions have memory leaks. Which gstreamer version are you using? Try to upgrade to the latest gstreamer.
        Your Qt is old as well. Upgrade your Qt to at least 5.15.2.

        1 Reply Last reply
        0

        • Login

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