我不知道这种办法是否是是简单的,不过这样能加深对AMR的认识
int GetDuration(char* szFileName)
{
CFile file;
int duration = 0;
if(file.Open(szFileName, CFile::modeRead))
{
const unsigned char packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
int pos = 0;
pos += 6;
int lenth = file.GetSize();
char toc = '\0';
int framecount = 0;
unsigned char ft;
while (pos < lenth)
{
file.Seek(pos, CFile::begin);
if (1 != file.Read(&toc, 1))
{
duration = lenth > 0 ? ((lenth - 6) / 650) : 0;
file.Close();
break;
}
ft = (toc >> 3) & 0x0F;
pos += packed_size[ft] + 1;
framecount++;
}
duration = framecount * 20 / 1000;
file.Close();
}
return duration;
}
浙公网安备 33010602011771号