avframe转bitmap

2020-07-02 15:46:02 浏览数 (2)

avframe转bitmap

代码语言:javascript复制
void saveBmp(AVFrame* frame,int bpp)
{
    BITMAPFILEHEADER bmpHeader = { 0 };
    bmpHeader.bfType = 0x4d42;
    bmpHeader.bfReserved1 = 0;
    bmpHeader.bfReserved2 = 0;
    bmpHeader.bfOffBits = sizeof(BITMAPFILEHEADER)   sizeof(BITMAPINFOHEADER);
    bmpHeader.bfSize = bmpHeader.bfOffBits   frame->width*frame->height*bpp / 8;
 
    BITMAPINFO bmpInfo = { 0 };
    bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmpInfo.bmiHeader.biWidth = frame->width;
    bmpInfo.bmiHeader.biHeight = -frame->height;  // 图像上下颠倒
    bmpInfo.bmiHeader.biPlanes = 1;
    bmpInfo.bmiHeader.biBitCount = bpp;
    bmpInfo.bmiHeader.biCompression = BI_RGB;
    bmpInfo.bmiHeader.biSizeImage = 0;
    bmpInfo.bmiHeader.biXPelsPerMeter = 100;
    bmpInfo.bmiHeader.biYPelsPerMeter = 100;
    bmpInfo.bmiHeader.biClrUsed = 0;
    bmpInfo.bmiHeader.biClrImportant = 0;

    std::ofstream fout("./build/Debug/out/output.bmp", std::ofstr

0 人点赞