[英]Grey Video frames when using OpenCV Videocapture with GStreamer C++
Hey, I am new to Gstreamer and want to send a video that is captured from a camera and manipulated with OpenCV over a.network to the receiving part.嘿,我是 Gstreamer 的新手,想通过 a.network 将从摄像机捕获并使用 OpenCV 处理的视频发送到接收部分。 The receiving part then read it and displays it.然后接收部分读取它并显示它。 This shall be done in real-time.这应实时完成。 It basically works with the code/gstreamer settings below however as soon a frame is dropped (at least I think this is the reason) the video get corrupted in form of grey parts (attached picture).它基本上适用于下面的代码/gstreamer 设置,但是一旦帧丢失(至少我认为这是原因),视频就会以灰色部分的形式损坏(附图)。
OpenCV Sending Part: OpenCV 发送部分:
cv::VideoWriter videoTransmitter("appsrc ! videoconvert ! videoscale ! x264enc ! rtph264pay config-interval=1 pt=96 ! udpsink host=192.168.168.99 port=5000", cv::VideoWriter::fourcc('H', '2', '6', '4'), 10, videoTransmitter_imageSize, true);
OpenCV Receiving part: OpenCV 接收部分:
cv::VideoCapture videoReceiver("udpsrc port=5000 ! application/x-rtp ! rtpjitterbuffer ! rtph264depay ! avdec_h264 ! videoconvert ! appsink", cv::CAP_GSTREAMER);
It basically works but I often get grey parts in the video which then stay for a bit until the video is displayed correctly.它基本上可以工作,但我经常在视频中看到灰色部分,然后停留一段时间直到视频正确显示。 I guessed it happens always when a frame is dropped due to the transmission.我猜它总是在由于传输而丢失帧时发生。 However, how can I get rid of these grey/corrupted frames?但是,我怎样才能摆脱这些灰色/损坏的框架? Any Hints?任何提示? Any Gstreamer parameters I need to set to tune result?我需要设置任何 Gstreamer 参数来调整结果吗? Is there a better way to stream a video with opencv over.network?有没有更好的方法来 stream 与 opencv over.network 的视频?
Any help is appreciated!任何帮助表示赞赏!
No, there isn't any mechanism in Gstreamer to detect corrupted frames, because this doesn't make sense.不,Gstreamer 中没有任何机制来检测损坏的帧,因为这没有意义。
In most modern video codec, frame aren't sent in full anymore, but split in slices (meaning only a small part of the frame).在大多数现代视频编解码器中,帧不再完整发送,而是分成几片(意味着只有帧的一小部分)。 It can takes multiple intra packets (each containing multiple slices) to build a complete frame, and this is a good thing, because it makes your stream more resilient to errors, and allow multithreaded decoding of the slices (for example).它可以采用多个内部数据包(每个数据包包含多个切片)来构建一个完整的帧,这是一件好事,因为它使您的 stream 对错误更具弹性,并允许对切片进行多线程解码(例如)。
In order to achieve what you want, you have multiple solutions:为了实现你想要的,你有多种解决方案:
GOP - 1
frames (you must decode them, but you can't use them, they might be corrupted), you'll need a way to detect the error, see point 1 or 2 above.这将允许在错误后通过丢弃GOP - 1
帧来恢复(你必须解码它们,但你不能使用它们,它们可能已损坏),你需要一种检测错误的方法,请参见上面的第 1 点或第 2 点. For x264enc
the parameter is called key-int-max
.对于x264enc
,该参数称为key-int-max
。 You might want to try also intra-refresh=true
so the broken frame effect upon error will be shorter.您可能还想尝试intra-refresh=true
,这样错误时的破帧效果会更短。 The downside is an increase in bandwidth for the same video quality.缺点是相同视频质量的带宽增加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.