在Windows中从OpenGL窗口捕获视频 [英] Capturing video out of an OpenGL window in Windows

查看:917
本文介绍了在Windows中从OpenGL窗口捕获视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该为我的用户提供一个非常简单的方法,从我的OpenGL应用程序的主窗口捕获视频剪辑。我想添加按钮和/或键盘快捷键来启动和停止捕获;当启动时,我可以要求一个文件名和其他选项,如果有。它必须在Windows(XP / Vista)中运行,但我也不想关闭我目前能够保持打开的Linux门。



应用程序使用OpenGL片段和着色器程序,在最终视频中我绝对需要的效果。



它看起来像我可能甚至几个不同的方法可能满足我的要求(但我真的不知道应该从哪里开始):




  • 其功能类似于startRecording(filename),stopRecording和captureFrame。我可以在每个帧渲染(或每秒/第三/任何)后调用captureFrame()。


  • 一个独立的外部程序,可以通过我的应用程序进行编程控制。毕竟,一个独立的程序,可以不是控制几乎做我需要的...但正如所说,它应该是真的很简单的用户操作,我会感谢无缝;我的应用程序通常运行全屏。此外,应该可以作为我目前使用NSIS准备的应用程序的安装包的一部分进行分发。


  • 使用Windows API捕获屏幕截图逐帧使用(例如)此处提到的库中的一个 。似乎很容易找到如何在Windows中捕获屏幕截图的示例;


  • 使用OpenGL渲染到一个非常不错的解决方案。屏幕上的目标,然后使用库来产生视频。我不知道这是否可能,恐怕它可能不是最小的痛苦的道路。特别是,我不喜欢实际渲染采取不同的执行路径,取决于视频是否被捕获。此外,我会避免在正常,非捕获模式下可能会降低帧速率的任何内容。




解决方案在任何意义上的自由,那么这将是伟大的,但它不是一个真正的绝对要求。一般来说,脓肿越少,越好。另一方面,由于这个问题以外的原因,我不能链接任何GPL-only代码,不幸的是。



关于文件格式,我不能指望我的用户开始谷歌搜索任何编解码器,但只要还显示 视频对于一个基本的Windows用户来说足够容易,我真的不在乎什么格式。



只是为了说明:我不要需要从摄像机的外部设备捕获视频,也不是我真正感兴趣的鼠标移动,即使获得它们也不会伤害。对音频没有要求;应用程序没有任何噪音。



我使用Visual Studio 2008编写C ++,这个应用程序也受益于GLUT和GLUI。我对C ++和链接在库和这种东西有一个坚实的理解,但另一方面OpenGL对我来说是新的:到目前为止,我真的只学到了必要的位,以实际完成我的工作。 p>

我不需要超级紧急的解决方案,所以请随时抽出时间:)

解决方案

这里有两个不同的问题 - 如何从OpenGL应用程序抓取帧,以及如何将它们转换为电影文件。



第一个问题很容易;你只需要通过glReadPixels()获取每个框架(如果你需要性能则通过PBO)。



第二个问题是跨平台解决方案)倾向于GPL'd或LGPL'd。您的项目可接受LGPL吗?



编辑:由于LGPL是确定的,你可以使用ffmpeg,请参阅这里了解如何以编码视频。


I am supposed to provide my users a really simple way of capturing video clips out of my OpenGL application's main window. I am thinking of adding buttons and/or keyboard shortcuts for starting and stopping the capture; when starting, I could ask for a filename and other options, if any. It has to run in Windows (XP/Vista), but I also wouldn't like to close the Linux door which I've so far been able to keep open.

The application uses OpenGL fragment and shader programs, the effects due to which I absolutely need to have in the eventual videos.

It looks to me like there might be even several different approaches that could potentially fulfill my requirements (but I don't really know where I should start):

  • An encoding library with functions like startRecording(filename), stopRecording, and captureFrame. I could call captureFrame() after every frame rendered (or every second/third/whatever). If doing so makes my program run slower, it's not really a problem.

  • A standalone external program that can be programmatically controlled from my application. After all, a standalone program that can not be controlled almost does what I need... But as said, it should be really simple for the users to operate, and I would appreciate seamlessness as well; my application typically runs full-screen. Additionally, it should be possible to distribute as part of the installation package for my application, which I currently prepare using NSIS.

  • Use the Windows API to capture screenshots frame-by-frame, then employ (for example) one of the libraries mentioned here. It seems to be easy enough to find examples of how to capture screenshots in Windows; however, I would love a solution which doesn't really force me to get my hands super-dirty on the WinAPI level.

  • Use OpenGL to render into an offscreen target, then use a library to produce the video. I don't know if this is even possible, and I'm afraid it might not be the path of least pain anyway. In particular, I would not like the actual rendering to take a different execution path depending on whether video is being captured or not. Additionally, I would avoid anything that might decrease the frame rate in the normal, non-capture mode.

If the solution were free in either sense of the word, then that would be great, but it's not really an absolute requirement. In general, the less bloat there is, the better. On the other hand, for reasons beyond this question, I cannot link in any GPL-only code, unfortunately.

Regarding the file format, I cannot expect my users to start googling for any codecs, but as long as also displaying the videos is easy enough for a basic-level Windows user, I don't really care what the format is. However, it would be great if it were possible to control the compression quality of the output.

Just to clarify: I don't need to capture video from an external device like camcorder, nor am I really interested in mouse movements, even though getting them does not harm either. There are no requirements regarding audio; the application makes no noise whatsoever.

I write C++ using Visual Studio 2008, for this very application also taking benefit of GLUT and GLUI. I have a solid understanding regarding C++ and linking in libraries and that sort of stuff, but on the other hand OpenGL is quite new for me: so far, I've really only learnt the necessary bits to actually get my job done.

I don't need a solution super-urgently, so feel free to take your time :)

解决方案

There are two different questions here - how to grab frames from an OpenGL application, and how to turn them into a movie file.

The first question is easy enough; you just grab each frame with glReadPixels() (via a PBO if you need the performance).

The second question is a little harder since the cross-platform solutions (ffmpeg) tend to be GPL'd or LGPL'd. Is LGPL acceptable for your project? The Windows way of doing this (DirectShow) is a bit of a headache to use.

Edit: Since LGPL is ok and you can use ffmpeg, see here for an example of how to encode video.

这篇关于在Windows中从OpenGL窗口捕获视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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