【问题标题】:av_seek_frame breaks avcodec_decode_video2 when codec uses p-frames当编解码器使用 p 帧时,av_seek_frame 会中断 avcodec_decode_video2
【发布时间】:2011-08-30 09:45:05
【问题描述】:

我正在尝试了解如何在使用 p 帧(例如 H.264)编码的视频中寻找 - 现在我只知道如何在使用每帧都是关键帧的编解码器编码的视频中寻找(例如 MJPEG )。

给定一个时间戳,最终它应该播放该时间戳的帧。 但现在,我只是想在时间戳附近播放关键帧。 所以,首先——

ret = av_seek_frame(pFormatCtx, videoStream, avTime, 0); 
avcodec_flush_buffers(pCodecCtx);

然后是一些中间代码,包括av_read_frame。那么——

ret = avcodec_decode_video2(pCodecCtx, captureFrame, &gotPicture, &packet); 

观察:

  • 对于某些视频,这是可行的。对于其他人,avcodec_decode_video2 返回错误(负数)。工作视频示例:here。非工作视频示例:here

  • 对于 MJPEG 视频,这是可行的。

  • 如果我取出av_seek_frame,让它按顺序播放帧,它就可以工作。

【问题讨论】:

    标签: ffmpeg libavcodec libavformat


    【解决方案1】:

    替换这个--

    ret = av_seek_frame(pFormatCtx, videoStream, avTime, isPlayingBackward ? AVSEEK_FLAG_BACKWARD : 0); 
    avcodec_flush_buffers(pCodecCtx);
    

    有了这个——

    ret = avformat_seek_file(pFormatCtx, videoStream, 0, avTime, avTime, 0); 
    

    (警告:avformat_seek_file 的文档说:“这是仍在构建中的新搜索 API 的一部分。因此,请不要使用它。它可能随时更改,不要指望 ABI 兼容性! ")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-15
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-10
      相关资源
      最近更新 更多