ffmpeg API<avformat_seek_file>注意事项

int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);

使用avformat_seek_file API接口后,媒体文件的读指针会根据ts的大小进行重新定位,整个这个流程基本上不会有什么问题,但对于有下一解码环节的同学来说,就有需要特定处理的地方。

avcodec_send_packet与avcodec_receive_frame是一一对应的关系,发送一帧待解码的数据,就会接收一帧解码后的数据。

avformat_seek_file与avcodec_receive_frame两者之间本身没有直接的关系,但因为解码是发一帧解一帧,同时解码器内部存在缓存的情况,综合这些因素,进行avformat_seek_file后,再进行解码流程处理,基本上avcodec_receive_frame会收到几帧avformat_seek_file之前的缓存数据,这些avformat_seek_file前的数据会对你接下来的处理造成一些麻烦。

可以有两类处理:
1、正常的avcodec_receive_frame读出来,使用时间戳进行比对和谐掉
2、使用API接口avcodec_flush_buffers,清掉内部缓存数据,建议采用该接口

你可能感兴趣的:(ffmpeg,ffmpeg)