Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Real-time OpenGL screen capture


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
27 replies to this topic

#1 stevus06   Members   -  Reputation: 122

Like
0Likes
Like

Posted 30 June 2010 - 05:09 PM

Well this is my first post here but I wanted to ask hopefully a straightforward question.

I'm trying to take a video of the screen frame by frame and I want to do it as close to real time as possible. I've heard there's ways to do it using Win32 GDI, OpenGL, DirectX, but I know that OpenGL is platform-independent so I want to use that.

I've seen things for games like recording Counterstrike games and stuff but I wasn't sure how these worked. Basically if I can get something in a format where I can work with the individual pixels for each frame, that would work out.

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 37281

Like
0Likes
Like

Posted 30 June 2010 - 05:29 PM

Just to clarify - do you want to capture something that you're rendering (with GL), or do you want to capture the output of some other program?

#3 stevus06   Members   -  Reputation: 122

Like
0Likes
Like

Posted 30 June 2010 - 06:50 PM

I want to capture the output. Mainly at the OS level. Like what someone would see on a monitor.

#4 szecs   Members   -  Reputation: 2285

Like
-1Likes
Like

Posted 30 June 2010 - 07:31 PM

There is FRAPS for example
Or CamStudio

If you google "screen capture video" for example, you will get lots of other hits.

#5 Decrius   Members   -  Reputation: 100

Like
0Likes
Like

Posted 30 June 2010 - 07:49 PM

Personally I like http://sourceforge.net/projects/taksi/, it's a free capturer, no limitations etc. (unlike FRAPS). You can also capture a part of the screen, pretty neat.

#6 thefrost   Members   -  Reputation: 100

Like
0Likes
Like

Posted 30 June 2010 - 08:40 PM

Each time you render: Grab the frame from OGL with glReadPixels(), dump it to a tmp file (possibly use fast Zlib compression to save disk space), and once done recording, encode tmp file frame-by-frame using libogg/libvorbis.


#7 mhagain   Crossbones+   -  Reputation: 9161

Like
0Likes
Like

Posted 30 June 2010 - 11:19 PM

Reading from the backbuffer into system memory is going to incur a pipeline stall though, so you'll never get it really "real-time".

#8 samoth   Crossbones+   -  Reputation: 5456

Like
0Likes
Like

Posted 01 July 2010 - 01:12 AM

Quote:
Original post by thefrost
Each time you render: Grab the frame from OGL with glReadPixels(), dump it to a tmp file (possibly use fast Zlib compression to save disk space), and once done recording, encode tmp file frame-by-frame using libogg/libvorbis.
Quote:
Original post by mhagain
Reading from the backbuffer into system memory is going to incur a pipeline stall though, so you'll never get it really "real-time".
Yes to both. However, the second one is not true if you use a pixel buffer object and properly overlap frames. This is a tiny bit more organisational work, but still pretty straightforward.

When a frame is to be recorded, issue a read into a pixel buffer object and push the PBO's identifier as well as any additional information that you might want, such as the current frame's number into a queue. Forget about the PBO for now, let it do its work.
Each frame, the queue is checked for frames that are at least 2 frames old. You can use the previous frame as well, this works exactly the same. However, I prefer being 100% on the safe side, and it doesn't really matter to wait a fraction of a second longer, so I'm waiting two frames.
If there are any candidate frames on the queue, their PBOs are mapped (GL_STREAM_READ) and handed to GDI+ for compression, and are written to disk (need to do one copy to flip them upside down, but that's a simple fast loop).

In my measurements, the overhead of this is exactly zero (meaning there is no measurable difference whatsoever in frame rates with or without screenshots, and the additional CPU load is under threshold).
Note, however, that supplying wrong flags when creating or mapping your PBO may cut your frame rate in half (due to stalls)!

There is no reason why the same could not be done for recording a video as well, which basically is no more than screenshotting every frame.


#9 stevus06   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 July 2010 - 06:46 AM

Wow lots of responses so far! So it sounds like a solution like this is definitely possible. I'm not really concerned about any stalls as long as they're not cumulative. As long as frames enter a program and exit to video at a fixed rate, it's no problem.

Decrius: I agree with the open source libraries solution. I'm not looking for a currently finished application.

Samoth: Sounds like you have a pretty good understanding about this. How much code do you think this would take? Is it something I can run in the background easily, maybe as some kind of DLL?

#10 szecs   Members   -  Reputation: 2285

Like
0Likes
Like

Posted 02 July 2010 - 06:48 AM

Do you want to make it yourself, or do you want an existing program?

Quote:
Original post by szecs
There is FRAPS for example
Or CamStudio // this is free

If you google "screen capture video" for example, you will get lots of other hits.


#11 stevus06   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 July 2010 - 06:49 AM

Quote:
Original post by szecs
Do you want to make it yourself, or do you want an existing program?

Quote:
Original post by szecs
There is FRAPS for example
Or CamStudio // this is free

If you google "screen capture video" for example, you will get lots of other hits.


Prefer to write it myself. It will be part of a larger solution.

#12 Decrius   Members   -  Reputation: 100

Like
0Likes
Like

Posted 02 July 2010 - 07:17 AM

Quote:
Original post by stevus06
Decrius: I agree with the open source libraries solution. I'm not looking for a currently finished application.


Sorry! Didn't thought you needed it embedded.


#13 stevus06   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 July 2010 - 07:27 AM

Quote:
Original post by Decrius
Quote:
Original post by stevus06
Decrius: I agree with the open source libraries solution. I'm not looking for a currently finished application.


Sorry! Didn't thought you needed it embedded.


Well if there is something in those libraries that could be useful, it is an option. Just to clarify though, I don't want to use something already developed and packaged. If I have access to source, or some kind of library, that would be preferable.

#14 samoth   Crossbones+   -  Reputation: 5456

Like
0Likes
Like

Posted 02 July 2010 - 11:12 AM

Quote:
Original post by stevus06
How much code do you think this would take? Is it something I can run in the background easily, maybe as some kind of DLL?
It depends on how easy or sophisticated you want it. My implementation has maybe a dozen OpenGL calls, half a dozen GDI+ calls, and little over a dozen lines of code otherwise.

If "running in the background as some kind of DLL" means you make a DLL that records screens from some unknown foreign program, you will need to make a fake opengl32.dll which exports the functions up to 1.2 (forwarding to the original functions) and hooks a "key" function such as for example SwapBuffers (forwarding to the original function, but also doing the capture).

If "running in the background as some kind of DLL" simply means running without impacting your game, and being able to put it in a DLL -- no problem at all.
Like I said, the overhead (when implemented properly) is neglegible, so running in the background is no issue. As for the DLL, you need to be careful that memory which you allocate stays on the same heap (i.e. do NOT allocate something in the main program and free in the DLL, or vice versa), but other than that I see no reason why there should be any issues.

Quote:
I'm not really concerned about any stalls
Stalls are the only thing you need to be concerned about, really. They're the only thing that may cause your program to become "jerky". The actual overhead is neglegible, it's only the stalls that matter -- but you can avoid them as described.

#15 stevus06   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 July 2010 - 12:25 PM

My idea was to make it run in the background, and capture whatever data was being sent to the monitor. Basically whichever data was viewable on the monitor, for example the windows screen with a web browser running or Word or whatever.

I'm not really intending to record any particular foreign program, only what I mention above as whatever is displayed on-screen. Basically I want to copy some of the functionality of the video capture tools like Fraps, but without having to create a UI and all of the other stuff.

Main goal of this app/DLL is to have it running and be able to provide a stream of frames representing what is being displayed on the monitor.

When you mean without impacting my game, are you talking about running a DLL in the background of the OS, and having it not impact the framerate of a separate game application?

#16 samoth   Crossbones+   -  Reputation: 5456

Like
0Likes
Like

Posted 02 July 2010 - 12:42 PM

If you want to capture whatever data goes to the monitor, you don't want an OpenGL capture. Look at for example Greenshot to see how this can be done.

It's an entirely different thing, but yes, this can also be done in a background application.

#17 Martins Mozeiko   Crossbones+   -  Reputation: 1422

Like
0Likes
Like

Posted 02 July 2010 - 01:20 PM

Here is some interesting information about how to capture OpenGL screen in real-time: http://www.outerra.com/video/index.html.

#18 stevus06   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 July 2010 - 04:11 PM

Quote:
Original post by samoth
If you want to capture whatever data goes to the monitor, you don't want an OpenGL capture. Look at for example Greenshot to see how this can be done.

It's an entirely different thing, but yes, this can also be done in a background application.


Hmm wonder if however it gets the screens would work for what I'm planning on doing? Haven't gotten the source yet though, so I can check it out.

#19 stevus06   Members   -  Reputation: 122

Like
0Likes
Like

Posted 05 July 2010 - 06:52 PM

I got the Greenshot code just now and looked at some of the Capture code.

There is the main part of it that uses Win32 and BitBlt(). I remember seeing somewhere that BitBlt wasn't the best to use if you wanted quick access to framebuffers or something like that. If I find the page, I will try to post it. Most of the code though looks pretty straightforward for taking a screenshot. Lots of it is just the fancy GUI they've developed around it.

So this Greenshot solution could be a better one than one using OpenGL?

#20 samoth   Crossbones+   -  Reputation: 5456

Like
0Likes
Like

Posted 05 July 2010 - 10:37 PM

For the "get whatever goes to the monitor" case, probably yes.
It is quite trivial to capture an OpenGL window (including a big window that covers the entire screen), but not nearly as trivial to capture the entire screen including other windows in the same way.

The BitBlt approach is by no means as efficient as a PBO readback, and it's hard to synchronize e.g. with a game that draws OpenGL (since unless vertical sync is on, you have no idea when new frames are ready).
However, it works for the "whatever goes to the monitor" case (with the exception of hardware accelerated video and webcam windows, which somehow never seem to work properly and mess up with everything). So if you really want to capture everything that's on the screen, this is the way to go.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS