ffmpeg主函数入口及添加自己的日志函数

1    入口函数

在ffmpeg.c中的main函数

2   添加日志函数

添加自己的日志函数,可以打印文件名、函数名、行号,方便定位问题。

在log.h添加

#define isLinux 1
#if isLinux
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/time.h>
#include <pthread.h>
#endif

void logWrite(const char *FileName,const char *FuncName,int Line,long ThreadID,int Type,const char* format,... );

#define myLog(Type,format,args...) \
    logWrite( __FILE__,__FUNCTION__ ,__LINE__,pthread_self(),Type,format,##args)


在log.c中添加

static void GetTime(struct tm *newtime)
{
    if(NULL == newtime)
	{
		return ;
	}
	
    struct tm *newtimeTemp=NULL;
    time_t aclock;

	aclock=time(NULL);
    newtimeTemp=localtime(&aclock);
	newtimeTemp->tm_year += 1900;
	newtimeTemp->tm_mon += 1;
    memcpy(newtime,newtimeTemp,sizeof(struct tm));
	
    return ;
}


void logWrite(const char *FileName,const char *FuncName,int Line,long ThreadID,int Type,const char* format,... )
{
#define MAX_LOG_MSG_Size 514
#define FileNameSize 50
#define FuncNameSize 30

	char LogMsg[MAX_LOG_MSG_Size]={0};
	char LogMsgFormat[MAX_LOG_MSG_Size]={0};
	char FilenameTemp[FileNameSize]={0};
	struct tm CurTime;
	va_list arg_ptr;
	va_start(arg_ptr,format);
    memset(&CurTime, 0x0,sizeof( CurTime ));
	(void)GetTime(&CurTime);
	//文件名 char *strrchr(const char *str, char c);
	char *pStar=NULL;
	if( NULL != (pStar = strrchr(FileName,'/')))
	{
		 pStar = pStar + 1; 
	}
	else
	{
		 pStar = FileName;
	}
	strncpy( FilenameTemp , pStar ,FileNameSize-1  );
	vsnprintf(LogMsg, sizeof(LogMsg)-1, format,arg_ptr);
	snprintf(LogMsgFormat,sizeof(LogMsgFormat)-1, 
		"%lu|%4d-%2d-%2d %2d:%2d:%2d|%s:%d|%s|%s",
		 ThreadID,
		 CurTime.tm_year,CurTime.tm_mon,CurTime.tm_mday,
		 CurTime.tm_hour,CurTime.tm_min,CurTime.tm_sec,
		 FilenameTemp,Line,FuncName,LogMsg);
	
	av_log(NULL, Type, "%s\n",LogMsgFormat);
	
	va_end(arg_ptr);
}



原生的ffmpeg的日志即为av_log,其实相当于把av_log再封装一下。











评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值