As far as I know, MediaCodec
return output buffer of image in YUV420
and then you can process with it as you like to... But in my case I need to convert YUV420
in BGR
, it is quite expensive conversion.
So, question is if it is possible immediately (without conversion) get BGR
from MediaCodec
?
My code now
uint8_t *buf = AMediaCodec_getOutputBuffer(m_data.codec, static_cast<size_t>(status), /*bufsize*/nullptr);
cv::Mat YUVframe(cv::Size(m_frameSize.width, static_cast<int>(m_frameSize.height * 1.5)), CV_8UC1, buf);
cv::Mat colImg(m_frameSize, CV_8UC3);
cv::cvtColor(YUVframe, colImg, CV_YUV420sp2BGR, 3);
auto dataSize = colImg.rows * colImg.cols * colImg.channels();
imageData.assign(colImg.data, colImg.data + dataSize);
So, as you can see here
cv::Mat YUVframe(cv::Size(m_frameSize.width, static_cast<int>(m_frameSize.height * 1.5)), CV_8UC1, buf);
I am getting YUVframe
from codec buffer and then here
cv::cvtColor(YUVframe, colImg, CV_YUV420sp2BGR, 3);
I make conversion
Conversion take a lot of time. For me performance is critical.