前言
仅供参考。
基于0.7.6版本的来做的,较高版本好像也没对这一块做啥修改。
方案一(简单易实现)
找到compute_target_delay的调用位置。
delay = compute_target_delay(ffp, last_duration, is); if(ffp->pf_playback_rate < 0.5) delay = delay / ffp->pf_playback_rate;
方案二(复杂并且还有难解决的问题)
开启AVFILTER
#define CONFIG_AVFILTER 1
#define FFP_AVFILTER_PLAYBACK_RATE 1
解除setpts的限制
由FFP_AVFILTER_PLAYBACK_RATE宏所包含
#ifdef FFP_AVFILTER_PLAYBACK_RATE
if (fabsf(ffp->pf_playback_rate) > 0.00001 &&
fabsf(ffp->pf_playback_rate - 1.0f) > 0.00001) {
char setpts_buf[256];
float rate = 1.0f / ffp->pf_playback_rate;
//rate = av_clipf_c(rate, 0.5f, 2.0f); //注释掉该行限制解除
av_log(ffp, AV_LOG_INFO, "vf_rate=%f(1/%f)\n", ffp->pf_playback_rate, rate);
snprintf(setpts_buf, sizeof(setpts_buf), "%f*PTS", rate);
INSERT_FILT("setpts", setpts_buf);
}
#endif
重置video filters
低倍数和恢复1倍数时重置video filters
void ffp_set_playback_rate(FFPlayer *ffp, float rate)
{
if (!ffp)
return;
ffp->pf_playback_rate = rate;
ffp->pf_playback_rate_changed = 1;
if(ffp->pf_playback_rate < 0.5 || ffp->pf_playback_rate == 1.0){
ffp->vf_changed = 1;
}
}
画面许久才刷新一帧(异常)
compute_target_delay函数计算的delay异常(经avfilter后,frame->pts有概率出现异常的状态)
限制delay的值:不大于当前fps所对应的两帧间隔时间。
if (!isnan(diff) && fabs(diff) < AV_NOSYNC_THRESHOLD) {
if (diff <= -sync_threshold)
delay = FFMAX(0, delay + diff);
else if (diff >= sync_threshold && delay > AV_SYNC_FRAMEDUP_THRESHOLD)
delay = delay + diff;
else if (diff >= sync_threshold)
delay = 2 * delay;
// wolf-herd modify
if(ffp->is && ffp->is->video_st){
double fps = av_q2d(ffp->is->video_st->avg_frame_rate);
delay = FFMIN(1/(fps * ffp->pf_playback_rate),delay);
}
}
seek操作异常
暂时没有想到方法修复该问题。
网友评论