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再封装一下。