OpenCV - Gstreamer pipeline

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

OpenCV - Gstreamer pipeline

Jump to solution
9,660 Views
fabianmpa019
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
1 Solution
9,208 Views
fabianmpa019
Contributor II

Still not working this way, however, cross compiling OpeCV with Gstreamer and FFmpeg support, i am able to run scripts I had no been able to run on Navq and it seems is using Gstreamer caps. The instructions on how I achieved it are under my gitbook  https://hovergames.gitbook.io/hovergames2/

View solution in original post

4 Replies
9,209 Views
fabianmpa019
Contributor II

Still not working this way, however, cross compiling OpeCV with Gstreamer and FFmpeg support, i am able to run scripts I had no been able to run on Navq and it seems is using Gstreamer caps. The instructions on how I achieved it are under my gitbook  https://hovergames.gitbook.io/hovergames2/

9,627 Views
Landon_Haugh
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);

 

9,625 Views
fabianmpa019
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
9,643 Views
iaingalloway
NXP Employee
NXP Employee

We'll check on this.