简体   繁体   English

Gstreamer + OpenCV h264 编码和解码图像变形问题

[英]Gstreamer + OpenCV h264 Encoding&Decoding İmage Deformation Problem

Hardware: Apalis IMX8 CPU(SOM) and Sensoray model-1012 video frame grabber硬件:Apalis IMX8 CPU(SOM) 和 Sensoray model-1012 视频帧采集器

I am trying to save analog video with h264 coding and play it.我正在尝试使用 h264 编码保存模拟视频并播放。 The code has 3 parts.代码有 3 部分。 Reading camera, saving video with coding and playing video with decoding.读取摄像头,编码保存视频,解码播放视频。

The problem i am facing is on decoding part.我面临的问题是解码部分。 When i decode and show video it corrupts.当我解码并显示视频时,它会损坏。

How i read analog video(Works fine):我如何阅读模拟视频(工作正常):

cap = cv::VideoCapture(" v4l2src device=/dev/video4 ! video/x-raw, format=(string)YUY2, width=(int)720, height=(int)480, framerate=30/1, interlace-mode=interleaved ! deinterlace fields=1 method=2 ! videoconvert ! appsink ",cv::CAP_GSTREAMER);

How i compress and save video(Works fine):我如何压缩和保存视频(工作正常):

cv::VideoWriter fixedVideo;
QString pipeTmp =  "appsrc ! videoconvert ! v4l2h264enc ! h264parse ! qtmux ! filesink location="+ FixedIMG_recordName +" sync=false ";
std::string pipe = pipeTmp.toUtf8().constData();
isOpen = fixedVideo.open(pipe , cv::CAP_GSTREAMER, (double)30, cv::Size(720,480), true);

How i decode and open video( DOESNT Work Fine ):我如何解码和打开视频(不工作正常):

cv::VideoCapture cap_reader;
QString pipeTmp = " filesrc location=" + device + " ! qtdemux ! h264parse ! video/x-h264, width=720, height=480 ! v4l2h264dec ! videoconvert ! appsink ";
std::string pipe = pipeTmp.toUtf8().constData();
cap_reader.open(pipe , cv::CAP_GSTREAMER);

when i open cap_read pipe line to play same video from gstreamer command line pipe it works fine with some warnings.当我打开 cap_read 管道从gstreamer 命令行管道播放相同的视频时,它可以正常工作,但有一些警告。 I put the GST_DEBUG output in log.txt Pipe line:我把 GST_DEBUG 输出放在log.txt管道中:

GST_DEBUG=3 gst-launch-1.0 -v filesrc location=test.mp4 ! qtdemux ! h264parse ! 'video/x-h264, width=720, height=480, framerate=30/1' ! v4l2h264dec ! videoconvert ! autovideosink

When i open the video from VLC it also works fine.当我从 VLC 打开视频时,它也能正常工作。 But when i open the video from VideoCapture and the pipeline that i gave above it corrupts.但是当我从 VideoCapture 打开视频时,我上面给出的管道损坏了。 The corrupted image example .损坏的图像示例 损坏的图像示例

There is no problem in compression.压缩没有问题。 When you decode mp4 file, you should use "imxvideoconvert_g2d".当您解码 mp4 文件时,您应该使用“imxvideoconvert_g2d”。

Decode pipeline should be filesrc location=" + device + " !解码管道应该是 filesrc location=" + device + " ! qtdemux ! h264parse ! h264解析! video/x-h264, width=720, height=480 !视频/x-h264,宽度=720,高度=480! v4l2h264dec ! v4l2h264dec ! imxvideoconverter_g2d ! imxvideoconverter_g2d ! video/x-raw,format=UYVY,width=720,height=480 !视频/x-raw,格式=UYVY,宽度=720,高度=480! videoconvert !视频转换! appsink应用程序接收器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM