计算视频文件(包含PCR)播放带宽的方法
2013-02-28 10:43
686 查看
通过对码流播放卡的分析,以及对公式的对照,对实际计算播放视频文件所用带宽的方法进行了分析(附件中,带有c语言的实现)
分析如下:
关键是最后计算带宽的公式:
PCRdelta = (uint64_t) ((uint64_t)PCR1 - (uint64_t)PCR0);
bitRate = (double) ( ((double)(40608000000ULL)*((double)mpegPackets))/(double)(PCRdelta));
PCRdelta : 是相邻N个PCR的PCR差值
mpegPackets : 是相邻N个PCR,所包含的packet的数量(MPEG packet)
我们可以理解为: mpegPackets*188表示实际的数据
而PCRdelta表示播放这段实际数据,总需要播放的总数据量.
则: (mpegPackets*188)/PCRdelta : 单位实际播放的数据中所包含的有效(MPEG packet)数据量
而我们目前所使用的VP播放卡,要求了,DVB-ASI输出带宽必须是216Mb/s
所以就有 bitRate/216000000 = (mpegPackets*188)/PCRdelta
因此得到 bitRate = (double) ( ((double)(40608000000ULL)*((double)mpegPackets))/(double)(PCRdelta));
所以,按照目前这样分析,播放同一个包含pcr的视频文件,如果播放的DVB-ASI输出总带宽不同,则播放视频文件所分配的带宽也应该不同.
////////////////////////////////////////////////////////////////////////
//
// This routine extracts the bitrate from the content file.
// The content file must contain PCRs
//
////////////////////////////////////////////////////////////////////////
double getBitRate(FILE *fp)
{
// variables used to get bit rate from content file
uint64_t PCR0 = 0, PCR1 = 0;
uint64_t PCRdelta;
double bitRate = 0;
uint32_t mpegPackets = 0;
uint32_t gotPCR = 0;
unsigned char m2tTmp[256];
int length;
unsigned int PID = 0;
//used to control "." output
int sync = 0;
printf(" Scanning content file for bit rate ");
for (;;) {
length = fread(m2tTmp, sizeof(uint8_t), 188, fp);
if(length != 188) break;
mpegPackets++;
if (sync % 1200 == 0 ) {
//show user something while we loop
printf(".");
//force it out-may not otherwise appear in real time
fflush(stdout);
}
sync++;
// look for the sync byte
if(m2tTmp[0] != 0x47) {
printf("vpSendspts: data corruption in content file ");
fclose(fp);
exit(2);
}
// we are going to scan through the first 10 PCRs in this content.
// According to the specifications that will be on the order of
// every 40 milliseconds. We don't have to scan the whole file
// to get a good sense of its validity and bit rate.
// First see if the TS header indicates the presence of an
// adaptation field.
if(GET_DVBASI_ADAPT(m2tTmp) & 0x02) {
// Get the adaptation field and look for the presence of
// a PCR in the adaptation field
if(GET_DVBASI_ADAPTLENGTH(m2tTmp) == 0) {
printf("Zero length AF ");
continue;
}
if(GET_DVBASI_ADAPTFIELD(m2tTmp) & 0x10) {
// Get the initial PCR and reset the counter
if(gotPCR == 10) { // skip the first few, some times they are bad!
PID = GET_DVBASI_PID(m2tTmp);
GET_DVBASI_PCR(m2tTmp, PCR0);
mpegPackets = 0;
}
// Look for the 10th PCR in this content and
if((gotPCR > 20) && PID == GET_DVBASI_PID(m2tTmp)) {
GET_DVBASI_PCR(m2tTmp, PCR1);
PCRdelta = (uint64_t) ((uint64_t)PCR1 - (uint64_t)PCR0);
bitRate = (double) ( ((double)(40608000000ULL)*((double)mpegPackets))/(double)(PCRdelta));
break;
}
gotPCR++;
} // GET_DVBASI_ADAPTFIELD
} //GET_DVBASI_ADAPT
} // while read
//rewind file
rewind(fp);
fflush(fp);
return(bitRate);
}
filippo.le@gmail.com
分析如下:
关键是最后计算带宽的公式:
PCRdelta = (uint64_t) ((uint64_t)PCR1 - (uint64_t)PCR0);
bitRate = (double) ( ((double)(40608000000ULL)*((double)mpegPackets))/(double)(PCRdelta));
PCRdelta : 是相邻N个PCR的PCR差值
mpegPackets : 是相邻N个PCR,所包含的packet的数量(MPEG packet)
我们可以理解为: mpegPackets*188表示实际的数据
而PCRdelta表示播放这段实际数据,总需要播放的总数据量.
则: (mpegPackets*188)/PCRdelta : 单位实际播放的数据中所包含的有效(MPEG packet)数据量
而我们目前所使用的VP播放卡,要求了,DVB-ASI输出带宽必须是216Mb/s
所以就有 bitRate/216000000 = (mpegPackets*188)/PCRdelta
因此得到 bitRate = (double) ( ((double)(40608000000ULL)*((double)mpegPackets))/(double)(PCRdelta));
所以,按照目前这样分析,播放同一个包含pcr的视频文件,如果播放的DVB-ASI输出总带宽不同,则播放视频文件所分配的带宽也应该不同.
////////////////////////////////////////////////////////////////////////
//
// This routine extracts the bitrate from the content file.
// The content file must contain PCRs
//
////////////////////////////////////////////////////////////////////////
double getBitRate(FILE *fp)
{
// variables used to get bit rate from content file
uint64_t PCR0 = 0, PCR1 = 0;
uint64_t PCRdelta;
double bitRate = 0;
uint32_t mpegPackets = 0;
uint32_t gotPCR = 0;
unsigned char m2tTmp[256];
int length;
unsigned int PID = 0;
//used to control "." output
int sync = 0;
printf(" Scanning content file for bit rate ");
for (;;) {
length = fread(m2tTmp, sizeof(uint8_t), 188, fp);
if(length != 188) break;
mpegPackets++;
if (sync % 1200 == 0 ) {
//show user something while we loop
printf(".");
//force it out-may not otherwise appear in real time
fflush(stdout);
}
sync++;
// look for the sync byte
if(m2tTmp[0] != 0x47) {
printf("vpSendspts: data corruption in content file ");
fclose(fp);
exit(2);
}
// we are going to scan through the first 10 PCRs in this content.
// According to the specifications that will be on the order of
// every 40 milliseconds. We don't have to scan the whole file
// to get a good sense of its validity and bit rate.
// First see if the TS header indicates the presence of an
// adaptation field.
if(GET_DVBASI_ADAPT(m2tTmp) & 0x02) {
// Get the adaptation field and look for the presence of
// a PCR in the adaptation field
if(GET_DVBASI_ADAPTLENGTH(m2tTmp) == 0) {
printf("Zero length AF ");
continue;
}
if(GET_DVBASI_ADAPTFIELD(m2tTmp) & 0x10) {
// Get the initial PCR and reset the counter
if(gotPCR == 10) { // skip the first few, some times they are bad!
PID = GET_DVBASI_PID(m2tTmp);
GET_DVBASI_PCR(m2tTmp, PCR0);
mpegPackets = 0;
}
// Look for the 10th PCR in this content and
if((gotPCR > 20) && PID == GET_DVBASI_PID(m2tTmp)) {
GET_DVBASI_PCR(m2tTmp, PCR1);
PCRdelta = (uint64_t) ((uint64_t)PCR1 - (uint64_t)PCR0);
bitRate = (double) ( ((double)(40608000000ULL)*((double)mpegPackets))/(double)(PCRdelta));
break;
}
gotPCR++;
} // GET_DVBASI_ADAPTFIELD
} //GET_DVBASI_ADAPT
} // while read
//rewind file
rewind(fp);
fflush(fp);
return(bitRate);
}
filippo.le@gmail.com
相关文章推荐
- 计算视频文件(包含PCR)播放带宽的方法 PCR计算码率
- 计算视频文件(包含PCR)播放带宽的方法 PCR计算码率
- 计算视频文件(包含PCR)播放带宽的方法
- 计算视频文件(包含PCR)播放带宽的方法 PCR计算码率
- 计算视频文件(包含PCR)播放带宽的方法 PCR计算码率
- 计算视频文件(包含PCR)播放带宽的方法 PCR计算码率
- 计算视频文件(包含PCR)播放带宽的方法
- 计算视频文件(包含PCR)播放带宽的方法 PCR计算码率
- 如何计算 一个音视频文件 (.ts)文件 (包含pcr信息). 播放所使用的带宽
- 如何计算 一个音视频文件 (.ts)文件 (包含pcr信息). 播放所使用的带宽
- 如何计算 一个音视频文件 (.ts)文件 (包含pcr信息). 播放所使用的带宽
- 计算MP4文件播放时长的方法
- ios开发视频播放后台下载功能实现 :1,ios播放视频 ,包含基于AVPlayer播放器,2,实现下载,iOS后台下载(多任务同时下载,单任务下载,下载进度,下载百分比,文件大小,下载状态)(真机调试功能正常)
- MediaPlayer类可用于控制音频/视频文件或流的播放。关于如何使用这个类的方法还可以阅读VideoView类的文档。
- jsp播放视频文件的方法总结
- FLV视频文件无法播放 解决方法
- 网络视频带宽计算方法
- struts资源文件的配置及程序调试的方法-视频(包含所有中文乱码的解决方案)
- 数字网络视频的带宽计算方法
- mp3文件总播放时长计算方法