保存webrtc::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);
    }
}

反复调用该函数可以将一系列的帧存入到文件中,然后使用YUVViewer等工具打开视频文件查看。

你可能感兴趣的:(WebRTC源码分析,Webrtc,VideoFrame,YUV文件)