Ffmpeg 定位文件(seek file)
生活随笔
收集整理的這篇文章主要介紹了
Ffmpeg 定位文件(seek file)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?? 有朋友問到ffmpeg播放文件如何定位問題,我想到應該還有一些新手朋友對這一塊比較陌生。ffmpeg定位問題用到seek方法,代碼
如下:
void SeekFrame(AVFormatContext* context, int64_t seekFrame)//跳轉到指定位置 {int defaultStreamIndex = av_find_default_stream_index(context);if(ist->index == defaultStreamIndex){auto time_base = context->streams[defaultStreamIndex]->time_base;auto seekTime = context->streams[defaultStreamIndex]->start_time + av_rescale(seekFrame, time_base.den, time_base.num);int ret ;if(seekTime > ist->cur_dts){ret = av_seek_frame(context, defaultStreamIndex, seekTime, AVSEEK_FLAG_ANY);}else{ret = av_seek_frame(context, defaultStreamIndex, seekTime, AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD);}} }?需要注意的是,調用seek方法以后,packet的時間戳一定要重新計算,ffmpeg要求時間戳遞增,可以用一個成員變量記住最后一個時間戳信息,依次累加。
如需交流 請加入流媒體/Ffmpeg/音視頻 127903734
轉載于:https://www.cnblogs.com/wanggang123/p/5686187.html
總結
以上是生活随笔為你收集整理的Ffmpeg 定位文件(seek file)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IE8的parseInt
- 下一篇: rsync 断点续传