0、实现播放进度控制—即实现随机访问流媒体文件
seek流程:
1、停下demux线程、音视频解码线程
2、清空pkt队列
3、恢复三个线程(此时还不能进入正常播放状态)
4、扔掉小于seek的目标pts的帧
5、直到拿到帧的pts≥seek目标pts,才恢复音视频渲染
6、恢复正常播放
ffplay的seek操作:对于ts和mp4的逻辑差异
mp4 可以seek到指定的时间戳
ts 是 seek到文件的某个position,而不能直接seek到指定的时间点
1、seek操作要点
1、操作基准:即seek操作当前时间点,因此在进行播放时需要实时记录音视频流的DTS或者PTS
2、时间单位:进行seek操作时,根据流索引,确定其时间单位time_base,
3、时间大小:即向前或者向后seek的时间大小,根据此时间大小和当前时间点,可以计算出向前或者向后进行seek操作时的目标时间
4、操作载体:即是按照音频还是视频进行seek操作,只需要按照其中一个流进行seek即可,不需要分别对音视频流进行seek操作
5、操作刷新:在进行seek操作之后,正常播放之前需要将编解码的内部缓冲区进行刷新,同时也要将自行控制的缓冲区内缓存的音视频清零
2、seek相关函数
avformat_seek_file(会调用av_seek_frame)
/**
* Seek to timestamp ts.
* Seeking will be done so that the point from which all active streams
* can be presented successfully will be closest to ts and within min/max_ts.
* Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
*
* If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
* are the file position (this may not be supported by all demuxers).
* If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
* in the stream with stream_index (this may not be supported by all demuxers).
* Otherwise all timestamps are in units of the stream selected by stream_index
* or if stream_index is -1, in AV_TIME_BASE units.
* If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
* keyframes (this may not be supported by all demuxers).
* If flags contain AVSEEK_FLAG_BACKWARD, it is ignored.
*
* @param s media file handle
* @param stream_index index of the stream which is used as time base reference
* @param min_ts smallest acceptable timestamp
* @param ts target timestamp
* @param max_ts largest acceptable timestamp
* @param flags flags
* @return >=0 on success, error code otherwise
*
* @note This is part of the new seek API which is still under construction.
* Thus do not use this yet. It may change at any time, do not