在mingw下编译mplayer,ID_LENGTH输出结果为0.00,同样从网上下载的binary文件则正常,由于对mplayer不太熟悉,在网上也找了些资料,也没有眉目,只好自己从源代码中啃吧
在slickedit+gdb的帮助下,static void av_update_stream_timings(AVFormatContext *ic)得到时间duration,跟踪到mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(mpctx->demuxer));时,发现返回值是成149.465,却打印成0.00,再跟踪mp_msg,并做了一下测试,把mp_msg简化了测试
/********************************************/
#include
#include
#include
#if defined(__MINGW32__) || defined(__CYGWIN__)
#include
#endif
using namespace std;
#define MSGL_WARN 2
#define MSGSIZE_MAX 2048
void mp_msg(int mod, int lev, const char *format, ... ){
va_list va;
char tmp[MSGSIZE_MAX];
FILE *stream = lev <= MSGL_WARN ? stderr : stdout;
static int header = 1;
va_start(va, format);
vsnprintf(tmp, MSGSIZE_MAX, format, va);
va_end(va);
tmp[MSGSIZE_MAX-2] = '\n';
tmp[MSGSIZE_MAX-1] = 0;
header = tmp[strlen(tmp)-1] == '\n' || tmp[strlen(tmp)-1] == '\r';
fprintf(stream, "%s", tmp);
fflush(stream);
}
int main (int argc, char *argv[])
{
float fl=2.566545445F;//or 2.566545445f
double dl=265.5651445;
double len=149.649;
printf("%f,%e,%g,%.7f,%.02lf,%.02f\n",fl,dl,dl,dl,len,len);
mp_msg(1, 1, "ID_LENGTH=%.2lf\n", len);
mp_msg(1, 1, "ID_LENGTH=%.02f\n", len);
cout << "hello world" << endl;
return(0);
}
红色部分出现差异,为什么vsnprintf(tmp, MSGSIZE_MAX, format, va)会出问题,查了MSCN,原来暂时没有找到,有明白的欢迎留言指出或邮件()联系
/*****************************************************/
附:printf的输出格式
#include "stdafx.h"
#include
int main()
{
//for int
int i=30122121;
long i2=309095024l;
short i3=30;
unsigned i4=2123453;
printf("%d,%o,%x,%X,%ld,%hd,%u\n",i,i,i,i,i2,i3,i4);//如果是:%l,%h,则输不出结果
printf("%d,%ld\n",i,i2);//试验不出%ld和%d之间的差别,因为long是4bytes
printf("%hd,%hd\n\n\n",i,i3);//试验了%hd和%d之间的差别,因为short是2bytes
//for string and char
char ch1='d';
unsigned char ch2=160;
char *str="Hello everyone!";
printf("%c,%u,%s\n\n\n",ch1,ch2,str);//unsigned char超过128的没有字符对应
//for float and double,unsigned and signed can not be used with double and float
float fl=2.566545445F;//or 2.566545445f
double dl=265.5651445;
double len=149.649;
long double dl2=2.5654441454;
//%g没有e格式,默认6位包括小数点前面的数,
//%f没有e格式,默认6位仅只小数点后面包含6位
//%e采用e格式,默认6位为转化后的小数点后面的6位
printf("%f,%e,%g,%.7f,%.02lf\n",fl,dl,dl,dl,len);
printf("%f,%E,%G,%f\n",fl,dl,dl,dl);//%F is wrong
printf("%.8f,%.10e\n",fl,dl);
printf("%.8e,%.10f\n\n\n",fl,dl);
//for point
int *iP=&i;
char *iP1=new char;
void *iP2;//dangerous!
printf("%p,%p,%p\n\n\n",iP,iP1,iP2);
//其他知识:负号,表示左对齐(默认是右对齐);%6.3,6表示宽度,3表示精度
char *s="Hello world!";
printf(":%s: \n:%10s: \n:%.10s: \n:%-10s: \n:%.15s: \n:%-15s: \n:%15.10s: \n:%-15.10s:\n\n\n",
s,s,s,s,s,s,s,s);
double ddd=563.908556444;
printf(":%g: \n:%10g: \n:%.10g: \n:%-10g: \n:%.15g: \n:%-15g: \n:%15.10g: \n:%-15.10g:\n\n\n",
ddd,ddd,ddd,ddd,ddd,ddd,ddd,ddd);
//还有一个特殊的格式%*.* ,这两个星号的值分别由第二个和第三个参数的值指定
printf("%.*s \n", 8, "abcdefgggggg");
printf("%*.*f \n", 3,3, 1.25456f);
return 0;
}