美文网首页
YUV和webrtc::VideoFrame之间生成转换

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

作者: 大飞_2048 | 来源:发表于2020-04-18 18:07 被阅读0次

    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

    相关文章

      网友评论

          本文标题:YUV和webrtc::VideoFrame之间生成转换

          本文链接:https://www.haomeiwen.com/subject/ikrwvhtx.html