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

2020-04-18  本文已影响0人  大飞_2048

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);

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

上一篇下一篇

猜你喜欢

热点阅读