YUV和webrtc::VideoFrame之间生成转换

1、VideoFrame 到YUV

void  SaveVideoFrameToFile(const webrtc::VideoFrame& frame, std::string file)   
{   
    rtc::scoped_refptr 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 yuv_buffer(new rtc::RefCountedObject(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);

https://blog.csdn.net/chinabinlang/article/details/97760589?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-8&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-8

你可能感兴趣的:(YUV和webrtc::VideoFrame之间生成转换)