I'm trying to use libyuv::NV12ToI420Rotate to do it, but it's not working.
1. How to input data (YUV420 Planar) into the libyuv::NV12ToI420Rotate().
2. What is crop_x /crop_y and how to use it?
Thank you.
Here is my code.
bool QueueVideoCapturer::CaptureCustomFrame(const shared_ptr<CaptureFrame>& cf) {
if (!running_) {
return false;
}
int width = GetCaptureFormat()->width;
int height = GetCaptureFormat()->height;
int fourcc = GetCaptureFormat()->fourcc;
if(cf) {
if(start_rtc_timestamp==-1) {
start_rtc_timestamp = cf->rtc_timestamp;
}
// Currently, |fourcc| is always I420 or ARGB.
// TODO(fbarchard): Extend SizeOf to take fourcc.
uint32_t size = 0u;
if (fourcc == cricket::FOURCC_ARGB) {
size = width * 4 * height;
} else if (fourcc == cricket::FOURCC_I420) {
size = FrameSizeOf(width, height);
} else {
return false; // Unsupported FOURCC.
}
if (size == 0u) {
return false; // Width and/or Height were zero.
}
rtc::scoped_refptr<webrtc::I420Buffer> buffer(webrtc::I420Buffer::Create(cf->width, cf->height));
int crop_x;
int crop_y;
int crop_width;
int crop_height;
const uint8_t* y_plane = (const uint8_t*)(cf->frame.get_data());//(YUV420 Planar)
const uint8_t* uv_plane = y_plane + width * height;
int uv_width = (width + 1) / 2;
crop_x &= ~1;
crop_y &= ~1;
libyuv::NV12ToI420Rotate(
y_plane + (width * crop_y + crop_x), width,
uv_plane + uv_width * crop_y + crop_x, width, buffer->MutableDataY(),
buffer->StrideY(),
// Swap U and V, since we have NV21, not NV12.
buffer->MutableDataV(), buffer->StrideV(), buffer->MutableDataU(),
buffer->StrideU(), crop_width, crop_height,
static_cast<libyuv::RotationMode>(0));
this->OnFrame(webrtc::VideoFrame(buffer, webrtc::kVideoRotation_0, cf->rtc_timestamp * 1000), cf->width, cf->height);
}
return true;
}