yuv转bmp

#ifdef   _INTERFACE_H
#error   _INTERFACE_H has be  exsisted
#else
#define  _INTERFACE_H

#include "stdafx.h"//类型定义在这个文件中
#include "stdlib.h"
#include "windows.h"
void SaveYUV(AVFrame *picture, int width, int height,int iFrame) 
#pragma once

#ifndef _WINGDI_
#define   _WINGDI_

typedef struct tagBITMAPFILEHEADER 
{        
	WORD    bfType;     
	DWORD   bfSize;            
	WORD    bfReserved1;            
	WORD    bfReserved2;            
	DWORD   bfOffBits;  
} BITMAPFILEHEADER, FAR *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER;   


typedef struct tagBITMAPINFOHEADER
{ 
		DWORD      biSize;
		LONG       biWidth;
		LONG       biHeight;
		WORD       biPlanes; 
		WORD       biBitCount;
		DWORD      biCompression;
		DWORD      biSizeImage; 
		LONG       biXPelsPerMeter;
		LONG       biYPelsPerMeter;
		DWORD      biClrUsed;
		DWORD      biClrImportant;   
} BITMAPINFOHEADER, FAR *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER;  

#endif
#endif


void SaveYUVS(uint8_t* yuv, int width, int height, int iFrame) 
{
	FILE *pFile;
	char szFilename[32];
	int y;
	sprintf(szFilename, ".\yuv\rotate%d_%d_%d.yuv", iFrame, width, height);  	pFile=fopen(szFilename, "ab+");
	if(pFile == NULL)
	   return;

	fwrite(yuv,sizeof(char),width * height*3/2,pFile);// 	
	fflush(pFile);
	fclose(pFile);
}


#if 1
picture->data[0] += picture->linesize[0] * (pAVCodecCtx->height - 1);    
picture->linesize[0] *= -1;    
picture->data[1] += picture->linesize[1] * (pAVCodecCtx->height / 2 - 1);    
picture->linesize[1] *= -1;    
picture->data[2] += picture->linesize[2] * (pAVCodecCtx->height / 2 - 1);    
picture->linesize[2] *= -1;    
//转换图像格式,将解压出来的YUV420P的图像转换为BRG24的图像
int PictureSize=avpicture_get_size (PIX_FMT_BGR24, pAVCodecCtx->width, pAVCodecCtx->height); 
uint8_t* buf = (uint8_t*)av_malloc(PictureSize);   
avpicture_fill ( (AVPicture *)pFrameRGB, buf, PIX_FMT_BGR24, pAVCodecCtx->width, pAVCodecCtx->height);   
SwsContext* pSwsCtx = sws_getContext (pAVCodecCtx->width,pAVCodecCtx->height,pAVCodecCtx->pix_fmt,pAVCodecCtx->width,pAVCodecCtx->height,PIX_FMT_BGR24,SWS_BICUBIC,NULL, NULL, NULL);  
sws_scale (pSwsCtx,picture->data,picture->linesize,0,pAVCodecCtx->height,pFrameRGB->data,pFrameRGB->linesize);    
SaveAsBMP (pFrameRGB,pAVCodecCtx->width,pAVCodecCtx->height, count, 24);    
av_free(buf);
sws_freeContext(pSwsCtx);
#endif
原文地址:https://www.cnblogs.com/welen/p/3666190.html