通过FFmpeg将多媒体文件解码后保存成Bmp图像(YUV420 RGB32)

这篇博客介绍了如何在Linux环境下,利用FFmpeg库将多媒体文件解码后,将YUV420P格式的数据转换为RGB32,并保存为Bmp图像。内容详细阐述了转换过程,并提供了可编译运行的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考http://hi.baidu.com/mingxin505/item/52d6d1cda805d925a0b50a57,将其改为linux下可编译运行。可实现YUV420P与RGB32的互转。

/*   g++ -o test test.cpp -lavformat -lavcodec -lavutil -lz -lm -lpthread -lswscale  */

#include <string>
#include <cassert>
#include <iostream>
#include <sstream>
//#include <tchar.h>


extern "C"
{
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif
#include <libavutil/avutil.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavcodec/avcodec.h>
#include <stdlib.h>
#include <unistd.h>
};
//#pragma comment(lib, "avformat.lib")
//#pragma comment(lib, "avutil.lib")
//#pragma comment(lib, "avcodec.lib")
//#pragma comment(lib, "swscale.lib")
#pragma pack(1)
#define BOOL int
#define TRUE 1
#define FALSE 0
#define BI_RGB 0x0

char *itoa(int num,char *str,int radix) {
	/* 索引表 */
	char index[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	unsigned unum; /* 中间变量 */
	int i=0,j,k;
	/* 确定unum的值 */
	if(radix==10&&num<0) /* 十进制负数 */
	{
		unum=(unsigned)-num;
		str[i++]='-';
	} else unum=(unsigned)num; /* 其他情况 */
	/* 逆序 */
	do {
		str[i++]=index[unum%(unsigned)radix];
		unum/=radix;
	}while(unum);
	str[i]='\0';
	/* 转换 */
	if(str[0]=='-') k=1; /* 十进制负数 */
	else k=0;
	char temp;
	for(j=k;j<=(i-k-1)/2;j++)
	{
		temp=str[j];
		str[j]=str[i-j-1];
		str[i-j-1]=temp;
	}
	return str;
}

static AVFrame *alloc_picture(enum P
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值