gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:41:00 27 4
gpt4 key购买 nike

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

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com