使用 FFmpeg 进行 MPEG 向后帧解码

发布于 2025-01-07 18:24:54 字数 591 浏览 0 评论 0原文

我有所谓的“块”,用于存储一些 MPEG4(I,p,p,p,p ...)帧。 对于每个“块”,帧以“I”帧开始,并在下一个“I”帧之前结束。 (VOL - “visual_object_sequence_start_code”始终包含在“I”帧之前)

我需要能够以“向后”模式播放这些“块”帧。 最重要的是:

  1. 不可能只获取块中的最后一帧并执行解码,因为它是“P”帧,并且需要“帧间(I)”才能正确解码。

  2. 我不能只获取第一个“I”帧,然后将其传递给 ffmpeg 的“avcodec_decode_video”函数,然后才将最后一个“P”帧传递给 ffmpeg,因为最后一个“P”帧取决于前面有“P”框,对吧? (嗯..据我测试过这个方法,我最后解码的 P 帧有伪影)

现在我执行向后播放的方式是 - 首先解码 RGB 中的所有“块”帧并将它们存储在内存中。 (在大多数情况下,每个块最多约为 25 帧。)但是这种方法确实需要大量内存......(特别是在帧分辨率很高的情况下) 我有一种感觉,这不是正确的方法......

所以我想问,有没有人有任何建议如何使用 FFmpeg 执行这种“向后”帧解码/播放?

谢谢

I have so-called "block's" that stores some of MPEG4 (I,p,p,p,p...) frames.
For every "block", frame starts with an "I" frame, and ends before next "I" frame.
(VOL - "visual_object_sequence_start_code" is allways included before the "I" frame)

I need to be able to play those "block" frames in "backwards" mode.
The thick is that:

  1. It's not possible to just take the last frame in my block and perform decoding, because it's a "P" frame and it needs an "inter frame (I)" to be correctly decoded.

  2. I can't just take my first "I" frame, then pass it to the ffmpeg's "avcodec_decode_video" function and only then pass my last "P" frame to the ffmpeg, because that last "P" frame depends on the "P" frame before it, right? (well.. as far as I've tested this method, my last decoded P frame had artifacts)

Now the way I'm performing backwards playing is - first decoding all of my "block" frames in RGB and store them in memory. (in most cases it would be ~25 frames per block max.) But this method really requires a lot of memory... (especially if frames resolutions is high)
And I have a feeling that this is not the right way to do this...

So I would like to ask, does any one have any suggestions how this "backwards" frame decoding/playing could be performed using FFmpeg?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青瓷清茶倾城歌 2025-01-14 18:24:54

您所看到的实际上是一个研究问题:要了解整体方法,请查看以下论文:

  1. MPEG 视频流的压缩域反向播放,SPIE 国际语音、视频和数据通信研讨会,波士顿, MA,1998 年 11 月。

  2. MPEG 视频流的反向播放算法

  3. 通过应用程序操纵压缩视频数据中的时间依赖性MPEG 视频的压缩域处理​​。

本质上,仍然存在基于关键帧的高级编码,但是,您可以反转运动补偿的过程来实现反向流。这是通过将 P 帧即时转换为 I 帧来完成的。这确实需要向前看,但不需要那么多内存。也许您可以将其另存为新文件,然后将其应用到具有反向播放要求的标准解码器。

然而,这非常复杂,而且我见过很少有软件能够实际做到这一点。

What you are looking at really a research problem: To get a glimps of the overall approach, look at the following paper:

  1. Compressed-Domain Reverse Play of MPEG Video Streams, SPIE International Symposium on Voice, Video, and Data Communications, Boston, MA, November, 1998.

  2. Reverse-play algorithm for MPEG video streaming

  3. MANIPULATING TEMPORAL DEPENDENCIES IN COMPRESSED VIDEO DATA WITH APPLICATIONS TO COMPRESSED-DOMAIN PROCESSING OF MPEG VIDEO.

Essentially, there is still advanced encoding based on key frames, however, you can reverse the process of motion compensation to achieve the reverse flow. This is done by on the fly conversion of P frames into I frames. This does require looking forward but doesn't require that much more memory. Possibly you can save this as a new file and then apply it to standard decoder with reverse play requirements.

However, this is very complex, and i have seen rare softwares doing this practically.

葬シ愛 2025-01-14 18:24:54

我认为没有办法从 I 帧开始解码所有 P 帧,因为 P 帧取决于前一帧。为了处理解码的帧,可以将它们保存到文件中,或者,在有限的存储和额外的 CPU 能力的情况下,可以丢弃旧的 P 帧并在以后重新计算。

在命令级别,您可以将输入视频转换为一系列图像:

ffmpeg -i input_video output%4d.jpg

然后以某种方式反转它们的顺序并转换回视频:

ffmpeg -r FRAME_RATE -i reverse_output%4d.jpg output_video

如果可以的话,您可以考虑进行预处理。

I do not think there is a way around starting from I-frame and decoding all P-frames, due to P-frame depending on the previous frame. To handle decoded frames, they can be saved to a file, or, with limited storage and extra CPU power, older P-frames can be discarded and recomputed later.

At the command level, you can convert input video to a series of images:

ffmpeg -i input_video output%4d.jpg

then reverse their order somehow and convert back to a video:

ffmpeg -r FRAME_RATE -i reverse_output%4d.jpg output_video

You may consider pre-processing, if it is an option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文