OpenCV - Gstreamer pipeline

cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCV - Gstreamer pipeline

130 Views
Contributor II

Hi all,

I am trying to open a pipeline and create a VideoWriter object with OpenCV:

VideoCapture cap(" v4l2src ! video/x-raw,framerate=30/1,width=1920,height=1080 ! vpuenc_h264 ! avimux ! appsink ",CAP_GSTREAMER);
if(!cap.isOpened()){
std::cout<<"VideoCapture not opened";
exit(-1);
}
VideoWriter writer(" appsrc ! filesink location=video.avi ",0,30,Size(1920,1080),true);

 

It compiles, but when executed on the board i get:

Screenshot from 2020-09-02 02-26-07.png

Seems to be creating the pipeline but it gets stuck there.

Do you have any idea what could be happening?

Regards

0 Kudos
3 Replies

97 Views
NXP Employee
NXP Employee

Hey Fabian,

 

It seems as if you just created a VideoWriter object, but you aren't writing to that object. Is the source code you supplied the entirety of what you've compiled?

You need to add the following to your code in a loop:

 

Mat frame;
cap.read(frame);
writer.write(frame);

 

95 Views
Contributor II

Hi!!

Right, the code i shared was not complete.

The complete code is:

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main()
{
      VideoCapture cap("v4l2src ! video/x-raw,framerate=30/1,width=1920,height=1080 ! vpuenc_h264 ! avimux ! appsink",CAP_GSTREAMER);
      if(!cap.isOpened()){
             cout<<"VideoCapture not opened";
             return -1;
       }
      VideoWriter writer("appsrc ! filesink location=video.avi",VideoWriter::fourcc('M','J','P','G'),15,Size(1920,1080),true);

      if(!writer.isOpened()){
             cout<<"VideoWriter not opened";
             return -1;
       }
       while(1){
              Mat frame;
              cap.read(frame);
              writer.write(frame);
              if(waitKey(1) == 27){
                     break;
               }
        }
        cap.release();
        writer.release();
        return 0;
}

 

0 Kudos

113 Views
NXP Employee
NXP Employee

We'll check on this.