video - 在 ffmpeg 中可靠地获取 PTS 值?

标签 video ffmpeg libavcodec libavformat pts

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

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 值的最佳方法是什么?

最佳答案

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

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.
    }
}

关于video - 在 ffmpeg 中可靠地获取 PTS 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20107833/

相关文章:

ffmpeg - 使用ffmpeg录制MP4时突然断电

具有 fr 和分辨率操作的 Android 视频编码

c++ - 在 Visual C++ 中使用 ffmpeg ffprobe

ffmpeg - 与 0 异或的目的?

c++ - 与 libavcodec 链接,仍然看到 undefined reference

c++ - 使用 libavformat 读取位于内存中的文件

ffmpeg h264流解码伪影

php - 使用 PHP 上传 mp4 文件

ios - 在 iOS 上关闭流式视频(m3u8 文件)的隐藏式字幕按钮

ffmpeg - 如何在ffmpeg中为字幕设置背景?