ffmpeg——vs集成ffmpeg相关开发

ffmpeg是强大且完全开源的音视频处理工具,下文主要说明在windows下vs开发工具集成ffmpeg进行相关开发工作


一、将ffmpeg相关的api放入工程



二、配置包含目录、引用目录、链接器等环境



三、动态链接库dll文件可以放到debug目录下




四、代码开发


比如,一个简单的求输入视频文件时长的函数


头文件:

extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
};

 

 


函数实现:

float getvideolen(string strInputVideo)
{
	float VideoLen =-1;
	AVFormatContext	*pFormatCtx=NULL;
	pFormatCtx = avformat_alloc_context();

	int nerrnum = avformat_open_input(&pFormatCtx,strInputVideo.c_str(),NULL,NULL);
	if( nerrnum!=0 )  
	{
		return -2;
	}
	nerrnum = avformat_find_stream_info(pFormatCtx,NULL);
	if( nerrnum<0 )  
	{
		return -3;
	}
	if (pFormatCtx->nb_streams >0)
	{
		if(pFormatCtx->duration >0)  
		{
			VideoLen= pFormatCtx->duration;
		}
		else
		{
			VideoLen= -4;
		}

	}
	else
	{
		VideoLen = -5;
	}

	avformat_close_input(&pFormatCtx);
	avformat_free_context(pFormatCtx);

	return VideoLen/1000000;           //ffmpeg返回的是微秒,转换成秒
}

主函数时记得要初始化av_register_all();

int main(int argc, char* argv[])
{
	av_register_all(); 	
	if(NULL==argv[1])
	{
		cout<<"No such Input file"<<endl;
		return -1;
	}
	float videolen=getvideolen(argv[1]);
	cout<<"videolen="<<videolen<<endl;
	return 0;
}


如果出现错误 fatal error C1189: #error :  missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS

 

 

 

在common.h文件头部加入以下定义


#ifdef __cplusplus
#define __STDC_CONSTANT_MACROS
#ifdef _STDINT_H
#undef _STDINT_H
#endif
# include "stdint.h"
#endif


#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif

 


运行截图:




完整项目工程包下载:http://download.csdn.net/download/sm9sun/9687608



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值