gpt4 book ai didi

c - 如何 FFmpeg 解码并提取最后一帧的元数据?

转载 作者:行者123 更新时间:2023-11-30 15:06:30 26 4
gpt4 key购买 nike

我正在使用 FFMpeg 进行解码。我正在解码的视频是使用 C 代码的 H.264 或 MPEG4 视频。我正在使用 32 位库。我已成功解码并提取第一帧的元数据。我现在想解码最后一帧。我已经定义了视频的持续时间,并且认为可以安全地假设 isLastFrame = period。这就是我所拥有的,有什么建议吗?

AVFormatContext* pFormatCtx = avformat_alloc_context();
avformat_open_input(&pFormatCtx, filename, NULL, NULL);
int64_t duration = pFormatCtx->duration;
i=0;
while(av_read_frame(pFormatCtx, &packet)>=0) {
/* Is this a packet from the video stream? */
if(packet.stream_index==videoStream) {
/* Decode video frame*/
avcodec_decode_video2(pCodecCtx, pFrame, &duration, &packet);
}

非常感谢任何帮助! :)

最佳答案

感谢大家的帮助,但我发现 AV_SEEK_FRAME 持续时间不起作用的原因是您必须将其乘以 1000 才能适用于读取帧。另请注意,我使用decode_video而不是decode函数调用的原因是因为我使用的是32位并创建了我自己的,但如果您插入video_decode()或者我相信它是decode_video2,它也能正常工作。希望这对 future 的解码器同行有所帮助。

AVFormat Format;
int64_t duration = Format->duration;
duration = duration * 1000;
if (av_seek_frame(Format, Packet->stream_index, duration, AVSEEK_FLAG_ANY) <= 0)
{
/* read the frame and decode the packet */
if (av_read_frame(FormatContext, &Packet) >= 0)
{
/*decode the video frame*/
decode_video(CodecContext, Frame, &duration, &Packet);

}

关于c - 如何 FFmpeg 解码并提取最后一帧的元数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38958359/

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