从 P 和 B 帧创建 I 帧 [英] Create I Frame out of P and B frames

查看:48
本文介绍了从 P 和 B 帧创建 I 帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个基于 FFMpeg 的 C++ 转换器,它可以接收到 hls-stream 的链接并将其转换为本地 .mp4 视频.到目前为止,一切都很好,转换器就像一个魅力,毫无疑问.

I've written a C++ converter based on FFMpeg which can receive a link to hls-stream and convert it into local .mp4 video. So far, so good, converter works like a charm, no questions about that.

问题:无论我向转换器提供什么输入源,在转换结束时,我只需要接收带有关键帧的视频.由于完美的正向和反向搜索,我需要这样的视频.

PROBLEM: No matter what input source I'm providing to the converter, at the end of convertation I need to receive video with key-frames ONLY. I need such video due to perfect seeking forward and reverse.

众所周知,辅助视频帧(P 和 B)依赖于它们的所有者帧(I 帧),因为该帧包含全像素图.据此,我们可以通过将它们的数据与它们的 I 帧合并来为每个 P 和 B 帧重新创建一个 I 帧.这就是为什么这样的 ffmpeg 命令 ffmpeg -i video.mp4 output%4d.jpg 起作用.

It's a well-known fact that subsidiary video frames (P and B) dependent on their owner-frame (I frame), because this frame contains full pixel map. According to that, we can recreate a I frame for each P and B frame by merging their data with their I frame. That's why such ffmpeg command ffmpeg -i video.mp4 output%4d.jpg works.

问题:如何实现帧合并算法,以便在最后重新创建仅关键帧视频?合并AVPackets的数据需要知道哪些怪癖?

QUESTION: How can I implement an algorithm of merging of frames in order to recreate Key-frames ONLY video at the end? What kind of quirks I need to know about merging datas of AVPackets?

谢谢.

推荐答案

您不能合并"压缩流的 P 和 B 帧(例如使用 H.264 编解码器),以获得 I 帧.

You cannot "merge" P and B-frames of a compressed stream (e.g. with H.264 codec), to obtain I-frames.

ffmpeg 有什么作用

What ffmpeg does with

ffmpeg -i video.mp4 output%4d.jpg

正在解码每一帧(因此它需要从一个 I 帧开始,然后解码流中所有后续的 P 和 B 帧),并将它们压缩回 JPEG 并为原始中的每一帧输出一个 JPEG 图像输入流.

is decoding each frame (thus it needs to start from an I-frame, then decode all subsequent P and B-frames in the stream), and compress them back to JPEG and output a JPEG image for each frame in the original input stream.

如果要将带有 P/B 帧的输入流转换为仅内部流(带有所有 I 帧),您需要转码 流.这意味着解码原始流中的所有帧并将它们编码回仅内部流.

If you want to convert an input stream with P/B frames to an intra-only stream (with all I-frames), you need to transcode the stream. That means decode all frames from the original stream and encode them back to an intra-only stream.

这篇关于从 P 和 B 帧创建 I 帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆