FFmpeg中hevc ts文件seek花屏问题

调用FFmpeg库或者使用ffplay播放hevc编码的ts文件时,seek会花屏。会有如下的报错:

[hevc @ 000001e4e2292ac0] Could not find ref with POC 9 
[hevc @ 000001e4e2292ac0] Could not find ref with POC 8
[hevc @ 000001e4e2292ac0] Could not find ref with POC 7
[hevc @ 000001e4e2292ac0] Could not find ref with POC 11
[hevc @ 000001e4e2292ac0] Could not find ref with POC 3 
[hevc @ 000001e4e2292ac0] Could not find ref with POC 2
[hevc @ 000001e4e2292ac0] Could not find ref with POC 1
[hevc @ 000001e4e2292ac0] Could not find ref with POC 6
[hevc @ 000001e4e2292ac0] Could not find ref with POC 10
[hevc @ 000001e4e2292ac0] Could not find ref with POC 9
[hevc @ 000001e4e2292ac0] Could not find ref with POC 8
[hevc @ 000001e4e2292ac0] Could not find ref with POC 7
[hevc @ 000001e4e2292ac0] Could not find ref with POC 3 
[hevc @ 000001e4e2292ac0] Could not find ref with POC 2
[hevc @ 000001e4e2292ac0] Could not find ref with POC 1
[hevc @ 000001e4e2292ac0] Could not find ref with POC 0

测试了一下release版本ffmpeg-4.2.1以及master分支的代码,这个问题还存在。
这个问题好像一直存在,不过没有人给FFmpeg提交过patch。可能是解决起来比较简单吧。

这个问题的主要原因是返回的hevc的keyframe的pos不正确。

解决办法:
需要在libavformat/mpegts.c中,针对video stream是hevc的情况,在return dts和pos的条件中增加keyframe的判断。是否keyframe可以从parser->key_frame得到。

返回正确的keyframe的pos和dts之后,seek时设置seek_flags为AVSEEK_FLAG_BACKWARD,就不会再花屏了。
这样对播放过程中的seek操作,还有一些根据keyframe信息进行切片的操作等等就都正常了。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值