通过这个link,我学会了如何将webrtc::VideoFrame转换为OpenCv Mat。修改了部分数据后,我想通过WebRTC以videoFrame(webrtc::I420Buffer)的形式发送回去。如何将OpenCV Mat转换为webrtc::VideoFrame?
rtc::scoped_refptr<webrtc::I420Buffer> MatToI420(cv::Mat& cvMat, const int buf_width, const int buf_height){
rtc::scoped_refptr<webrtc::I420Buffer> buffer;
buffer = webrtc::I420Buffer::Create(buf_width, buf_height, buf_width, (buf_width + 1) / 2, (buf_width + 1) / 2);
//Test. make it a black screen -> succeeded.
//webrtc::I420Buffer::SetBlack(buffer.get());
//This is not working yet.
//cv::Mat yuv;
//cv::cvtColor(cvMat, yuv, CV_BGRA2YUV_I420);
//const int conversionResult = libyuv::ConvertToI420(
// yuv.ptr(), CalcBufferSize(webrtc::VideoType::kARGB, buf_width, buf_height)
// , buffer->MutableDataY(), buffer->StrideY()
// , buffer->MutableDataU(), buffer->StrideU()
// , buffer->MutableDataV(), buffer->StrideV()
// , 0, 0
// , buf_width, buf_height
// , buf_width, buf_height
// , libyuv::kRotate0,
// libyuv::FOURCC_ARGB
//);
//strange video....
//buffer = webrtc::I420Buffer::Copy(
// buf_width, buf_height
// , cvMat.data, cvMat.cols
// , cvMat.data + cvMat.rows * cvMat.cols, cvMat.cols / 2
// , cvMat.data + cvMat.rows * cvMat.cols + ((cvMat.rows / 2) * (cvMat.cols / 2)), cvMat.cols / 2
//);
return buffer;
}
1条答案
按热度按时间4urapxun1#
这是一个有效的例子。试试看。