C ++ OpenCV获取编码的网络摄像头流 [英] c++ opencv get encoded webcam stream
问题描述
我目前正在从事一个项目,该项目从网络摄像头捕获视频并通过UDP发送编码后的流以进行实时流式传输.
I am currently work on a project that capture video from webcam and send the encoded stream via UDP to do a real time streaming.
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap(0); // open the video camera no. 0
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
while (1)
{
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
return 0;
}
有人说从 cap.read(frame)获得的帧已经是解码的帧,我不知道它是如何发生的以及何时发生的.我想要的是编码的帧或流.我应该怎么做才能得到它?我应该再编码一次吗?
Some people say that the frame get from cap.read(frame) is already the decoded frame,I have no idea how and when does that happen. And what I want is the encoded frame or stream. What should I do to get it? Should I encoded it back again?
推荐答案
According to the docs, calling VideoCapture::read()
is equivalent to calling VideoCapture::grab()
then VideoCapture::retrieve()
.
Retrieve
函数的文档说它确实对帧进行了解码.
The docs for the Retrieve
function say it does indeed decode the frame.
为什么不仅仅使用解码帧?大概在任何情况下,您都将在远端对其进行解码?
Why not just use the decoded frame; presumably you'd be decoding it at the far end in any case?
这篇关于C ++ OpenCV获取编码的网络摄像头流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!