【问题标题】:Reliably get PTS values in ffmpeg?在ffmpeg中可靠地获取PTS值?
【发布时间】:2013-12-05 03:32:36
【问题描述】:

我正在尝试编写一种方法,该方法将在查询时提供下一帧和演示时间戳。代码目前看起来像这样:

while( getNextFrame(image, pts) )
{
    // show current image
    drawImage(currentImage);
    sleep(pts);
    currentImage = image;
}

到目前为止,我一直在关注 Dranger 教程,但一直无法可靠地获取帧的 PTS 值 (http://www.dranger.com/ffmpeg/tutorial05.html)。返回的 PTS 值始终为 0。

另外,get_buffer() 已被弃用,所以我现在使用get_buffer2() 方法来设置全局 pts 值。但是,release_buffer 方法也已被弃用,我似乎找不到它的替代品。这让我相信教程中列出的方法可能不再是完成这项任务的最佳方式。

简而言之,使用最新的 ffmpeg,可靠地抓取帧 pts 值的最佳方法是什么?

【问题讨论】:

标签: video ffmpeg libavcodec libavformat pts


【解决方案1】:

好吧,你没有提供太多信息,所以我将对你的代码做一些假设。

int err, got_frame;
AVFormatContext *avctx;
AVPacket avpkt;
AVFrame *frame;
// You open file, initialize structures here
// You read packet here using av_read_frame()
{
    AVStream *stream = avctx->streams[avpkt.stream_index];
    if ( 0 > ( err = avcodec_decode_video2 ( stream->codec, frame, &got_frame, &avpkt ) && got_frame ) )
    {
        int64_t pts = av_frame_get_best_effort_timestamp ( frame );
        // TODO test for AV_NOPTS_VALUE
        pts = av_rescale_q ( pts,  stream->time_base, AV_TIME_BASE_Q );
        // pts is now in microseconds.
    }
}

【讨论】:

  • av_frame_get_best_effort_timestamp - 这正是我想要的。谢谢!
  • av_frame_get_best_effort_timestamp() 现在已弃用。换什么?
  • 替换是直接访问AVFrame->best_effort_timestamp字段。
猜你喜欢
  • 2014-03-27
  • 2013-04-23
  • 2011-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-21
  • 1970-01-01
相关资源
最近更新 更多