OpenCV and GStreamer on iMX8QM MEK

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

OpenCV and GStreamer on iMX8QM MEK

跳至解决方案
2,882 次查看
sebadavalle
Contributor I

Hi I need help capturing MP4 videos using openCV and GSTREAMER.

Environment:

Board: i.MX8 Quad Max MEK
Linux: NXP i.MX Release Distro 5.4-zeus imx8qmmek 

This is the way I'm playing back MP4 the videos:

 

 

 

gst-launch-1.0 filesrc location=/home/LH.mp4 ! video/quicktime ! aiurdemux ! queue ! h264parse ! v4l2h264dec ! imxvideoconvert_g2d ! queue ! waylandsink 

 

 

 

So based on that I built the following pipeline for VideoCapture function:

 

 

 

cv::VideoCapture LHcap("filesrc location=/home/LH.mp4 ! video/quicktime ! aiurdemux ! queue ! h264parse ! v4l2h264dec ! imxvideoconvert_g2d ! queue ! appsink", cv::CAP_GSTREAMER)

 

 

 


But, the frames captured has only 2 channel and all OpenCV conversion functions fails.

 

 

 

cv::Mat img;
LHcap >> img;
cout <<  img.channels() << endl;

 

 

 


So i tried another pipeline

 

 

 

filesrc location=/home/LH.mp4 ! decodebin ! videorate ! video/x-raw,framerate=1/1 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink

 

 

 


using this pipeline, the captured images have 3 channels and the type is well recognized (CV_8UC3), BUT, if I save one of the frames, I can see the image is broken

(See attached)

Does anybody knows how to capture mp4 videos using opencv and GSREAMER?

Thanks

Seba.-

0 项奖励
回复
1 解答
2,862 次查看
sebadavalle
Contributor I

I was able to make it work..

 

const std::string pipeline = "filesrc location=/home/videos/RH-yuv420-slow.mp4 ! video/quicktime ! aiurdemux ! queue ! h264parse ! v4l2h264dec ! imxvideoconvert_g2d ! capsfilter caps=\"video/x-raw,format=UYVY,width=1392,height=512\" ! videoconvert ! queue ! appsink";

cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);

 


The key part is: 

! capsfilter caps=\"video/x-raw,format=UYVY,width=1392,height=512\" ! videoconvert

were you are specifying the capture format.

On the other had, for USB camera capture... you need to specify the  device ID (you can check the device ID using v4l2-ctl --list-devices ) and the preferred Capture API backends to use; in this case cv::CAP_GSTREAMER.

 

const int camID = 3;
cv::VideoCapture CAMcap(camID, cv::CAP_GSTREAMER);





 

在原帖中查看解决方案

0 项奖励
回复
1 回复
2,863 次查看
sebadavalle
Contributor I

I was able to make it work..

 

const std::string pipeline = "filesrc location=/home/videos/RH-yuv420-slow.mp4 ! video/quicktime ! aiurdemux ! queue ! h264parse ! v4l2h264dec ! imxvideoconvert_g2d ! capsfilter caps=\"video/x-raw,format=UYVY,width=1392,height=512\" ! videoconvert ! queue ! appsink";

cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);

 


The key part is: 

! capsfilter caps=\"video/x-raw,format=UYVY,width=1392,height=512\" ! videoconvert

were you are specifying the capture format.

On the other had, for USB camera capture... you need to specify the  device ID (you can check the device ID using v4l2-ctl --list-devices ) and the preferred Capture API backends to use; in this case cv::CAP_GSTREAMER.

 

const int camID = 3;
cv::VideoCapture CAMcap(camID, cv::CAP_GSTREAMER);





 

0 项奖励
回复