#define READ_FRAME_RATE_GEP 4 #define READ_FRAME_RATE_TIMES 5 static int get_average_count(read_frame_info_t* frame_info) { int average_count = 0; int count_diff[READ_FRAME_RATE_GEP]; int time_diff[READ_FRAME_RATE_GEP]; int rates[READ_FRAME_RATE_GEP]; int i; for (i = 0; i < READ_FRAME_RATE_GEP; i++) { count_diff[i] = frame_info[i+1].read_frame_count-frame_info[i].read_frame_count; time_diff[i] = frame_info[i+1].read_frame_time-frame_info[i].read_frame_time; if (time_diff[i] > 0) rates[i] = count_diff[i] * 1000000 / time_diff[i]; } average_count = rates[0]*1 + rates[1]*1 + rates[2]*3 + rates[3]*5; return average_count / 10; } 如何将这段代码修改成计算可播放时间
时间: 2024-03-29 22:34:10 浏览: 55
如果要将这段代码修改成计算可播放时间,需要修改计算平均帧率的部分,改为计算可播放时间的长度。可以通过累加每个时间间隔的可播放时间长度,并进行加权平均来得到总的可播放时间长度。以下是修改后的代码:
```
#define READ_FRAME_RATE_GEP 4
#define READ_FRAME_RATE_TIMES 5
static int get_average_playable_time(read_frame_info_t* frame_info) {
int average_time = 0;
int time_diff[READ_FRAME_RATE_GEP];
int time_lengths[READ_FRAME_RATE_GEP];
int i;
for (i = 0; i < READ_FRAME_RATE_GEP; i++) {
time_diff[i] = frame_info[i+1].read_frame_time-frame_info[i].read_frame_time;
if (time_diff[i] > 0)
time_lengths[i] = time_diff[i] * (frame_info[i+1].playable_frame_count - frame_info[i].playable_frame_count) / (frame_info[i+1].read_frame_count - frame_info[i].read_frame_count);
}
average_time = time_lengths[0]*1 + time_lengths[1]*1 + time_lengths[2]*3 + time_lengths[3]*5;
return average_time / 10;
}
```
在这段代码中,我们通过累加每个时间间隔内的可播放时间长度来得到总的可播放时间长度,并进行加权平均。其中,`playable_frame_count`表示该时间间隔内可播放的帧数,`read_frame_count`表示该时间间隔内读取的帧数。最后返回的是总的可播放时间长度的平均值。
阅读全文