如何获取视频文件的第一帧并从中提取字节数据?

发布于 2025-01-19 01:04:11 字数 933 浏览 4 评论 0 原文

几天来,我一直在尝试编写返回本地视频文件第一帧缩略图字节数据的代码,但没有成功。这个特定的代码位不需要 GUI 或渲染 - 我只需要获取第一个视频帧的缩略图,并获取该缩略图的字节数据。 (就上下文而言,我正在编写一个 Flutter 插件,它将通过 方法通道 - 它将传入文件路径,并且缩略图的字节预计将从方法通道调用返回)

我尝试过这样做使用 MediaFoundation 库没有成功,依赖于 此示例由 Microsoft 提供。 (这让我感到困惑,因为正如我上面提到的,我不需要在屏幕上渲染缩略图,也不需要视频中的多个缩略图 - 我只需要第一个。)花了很多小时之后经过几天与这段代码的斗争,我得出的结论是这个库对我来说没有用,因为它似乎涉及在每个级别以某种方式进行渲染 - 甚至是 GetDIBits 函数,这似乎是取出这些位的最佳方法位图的操作依赖于一个句柄,该句柄似乎来自现有的应用程序窗口,但在我的特定情况下不存在。

我在互联网上搜索了一种简单的方法来完成此任务,但一无所获。我读过这么多来自 Microsoft 的论坛帖子和文档,整件事简直让我抓狂!这个问题一定有一个简单的解决方案,对吧?必须有一种不涉及渲染的方法来做到这一点。

我还尝试使用 std::fstream 但没有成功。

I've been attempting to write code that returns the byte data of a thumbnail for the very first frame of a local video file for a few days now with no success. No GUI or rendering is required for this particular bit of code - I simply need to get a thumbnail of the very first video frame, and get the byte data of that thumbnail. (For context, I'm writing a Flutter plugin that will call this code through a method channel - it will pass in the file path, and the bytes of the thumbnail are expected to be returned from the method channel call)

I have attempted to do this with no success using the MediaFoundation library, relying on the confusing code in this example provided by Microsoft. (It is confusing to me because, as I mentioned above, I don't need to render the thumbnail on the screen, nor do I need more than one thumbnail from the video - I only need the very first.) After spending many hours over the course of several days fighting with this code, I've come to the conclusion that this library is not useful for me since it seems to involve rendering in some way at every level - even the GetDIBits function, which appears to be the best way to get the bits out of a Bitmap, relies upon having a handle, which seems to come from the existing application Window, which is not present in my particular case.

I have scoured the internet looking for a simple way to accomplish doing this and have come up with nothing. I've read so many forum posts and documentation from Microsoft, and the whole thing is driving me absolutely crazy! There must be a simple solution to this problem, right? There has to be a way to do this that doesn't involve rendering.

I've also tried working with std::fstream with no success.

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

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

发布评论

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

评论(1

眼前雾蒙蒙 2025-01-26 01:04:11

看来您正在误读文档。在Win32中,有很多被称为“手柄”的东西。例如,有一个“窗口句柄”, hwnd 。这就是您的应用程序窗口所拥有的。

但是 getDibits 采用另一种句柄,“设备上下文的句柄”或 hdc 。这些通常是相关的;甚至还有一个 window fromdc 可以从另一个获得一个。但是您只想将其绘制到内存缓冲区,不需要可见。在这种情况下,您可以使用 。请注意,该页面上使用它与 createCompatibledc - 这是该位图获得 HDC 的方式。

It seems you're misreading the documentation. In Win32, there are many things that are called "handles". There's for instance a "window handle", HWND. That's what your application window would have.

But GetDIBits takes another sort of handle, a "handle to a device context" or HDC. These are often related; there's even a WindowFromDC to get one from the other. But you just want to paint to a memory buffer, it doesn't need to be visible. In that case, you can use CreateCompatibleBitmap(). Note the example on that page using it in conjunction with CreateCompatibleDC - this is how you get an HDC for that bitmap.

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