将ffmpeg视频帧数据转换为bmp结构
#include <windows.h>
static int av_create_bmp(char* filename,uint8_t *pRGBBuffer,int width,int height,int bpp)
{
BITMAPFILEHEADER bmpheader;
BITMAPINFO bmpinfo;
FILE *fp;
fp = fopen(filename,"wb");
if(!fp)return -1;
bmpheader.bfType = ('M'<<8)|'B';
bmpheader.bfReserved1 = 0;
bmpheader.bfReserved2 = 0;
bmpheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmpheader.bfSize = bmpheader.bfOffBits + width*height*bpp/8;
bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpinfo.bmiHeader.biWidth = width;
bmpinfo.bmiHeader.biHeight = 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;
fwrite(&bmpheader,sizeof(BITMAPFILEHEADER),1,fp);
fwrite(&bmpinfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);
fwrite(pRGBBuffer,width*height*bpp/8,1,fp);
fclose(fp);
return 0;
}
[编辑] 调用实例
//------------------------------------
img_convert((AVPicture *)pFrameRGB, PIX_FMT_BGR24,(AVPicture*)pFrame,
pCodecCtx->pix_fmt, pCodecCtx->width,pCodecCtx->height);
来自:http://www.ffmpeg.com.cn/index.php/%E5%B0%86ffmpeg%E8%A7%86%E9%A2%91%E5%B8%A7%E6%95%B0%E6%8D%AE%E8%BD%AC%E6%8D%A2%E4%B8%BAbmp%E7%BB%93%E6%9E%84
http://www.ffmpeg.com.cn/index.php/Ffmpeg%E4%B9%8BWin32
http://bbs.chinavideo.org/viewthread.php?tid=2378