OpenCV - Gstreamer pipeline

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

OpenCV - Gstreamer pipeline

跳至解决方案
9,672 次查看
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 项奖励
1 解答
9,220 次查看
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/

在原帖中查看解决方案

4 回复数
9,221 次查看
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,639 次查看
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,637 次查看
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 项奖励
9,655 次查看
iaingalloway
NXP Employee
NXP Employee

We'll check on this.