1、VideoFrame 到YUV
void SaveVideoFrameToFile(const webrtc::VideoFrame& frame, std::string file)
{
rtc::scoped_refptr<webrtc::VideoFrameBuffer> vfb = frame.video_frame_buffer();
static FILE *fp = fopen(file, "wb+");
if (fp != NULL) {
fwrite(vfb.get()->GetI420()->DataY(), 1, frame.height() * frame.width(), fp);
fwrite(vfb.get()->GetI420()->DataU(), 1, frame.height() * frame.width() / 4, fp);
fwrite(vfb.get()->GetI420()->DataV(), 1, frame.height() * frame.width() / 4, fp);
fflush(fp);
}
}
2、YUV到VideoFrame
uint8_t *buffer_y = ref_frame->data = bufYuv;
uint8_t *buffer_u = buffer_y + stride_y * ref_frame->height;
uint8_t *buffer_v = buffer_u + stride_uv * ((ref_frame->height + 1)/2);
rtc::scoped_refptr<webrtc::I420Buffer> yuv_buffer(new rtc::RefCountedObject<webrtc::I420Buffer>(width, height));
memcpy((char *)yuv_buffer->MutableData(webrtc::PlaneType::kYPlane), buffer_y, size_y);
memcpy((char *)yuv_buffer->MutableData(webrtc::PlaneType::kUPlane), buffer_u, size_u);
memcpy((char *)yuv_buffer->MutableData(webrtc::PlaneType::kVPlane), buffer_v, size_v);
new webrtc::VideoFrame(yuv_buffer,0,0,webrtc::kVideoRotation_0);
网友评论