zoukankan      html  css  js  c++  java
  • 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

    视频下载地址:http://www.chungen90.com/?news_3/

     Demo下载地址: http://www.chungen90.com/?news_2

  • 相关阅读:
    实用产品规划
    产品经理对用户的调研
    产品经理用户研究
    竞品分析方案
    产品竞品分析
    Mybatis Plus
    shiro
    Spring cloud
    Spring Boot
    Redis入门(二)
  • 原文地址:https://www.cnblogs.com/wanggang123/p/5686187.html
Copyright © 2011-2022 走看看