Saving FBO as individual frames

Hello,

I need to save the content of the screen to MP4 file.

My ofFBO has resolutions 1920x1920.

My display on which I show graphics is 1280x1024, so I crop my ofFbo to fit on the screen.

I can use ffmpeg with CUDA (NVENC) support, which allows to grab window content and encode it in real time. However it will be 1280x1024 and not 1920x1920.

I can also potentially connect a second (hidden from public) display (1920x1920) just for grabbing purposes and direct ffmpeg there. But if I understand correctly it’s impossible to output full-screen windows to two different displays at the same time from OF. So this solution won’t work either. Right ?

That leaves me with the only option - somehow take GPU data and dump it to files and 30fps. However doing this with copyToPixel is way too slow. So is there a solution for this problem ?

Thanks, M

That leaves me with only only one solution. Somehow write ofFBO to disk at high speed and then ask ffmpeg to encode frames into ffmpeg. But how ?

Hi!

If you search on this forum, and on ofxAddons, you will find a lot of solutions on how to save FBOs to image sequence/video, threaded and with queue.

One thing I can recommend, if you are on Windows and this is what I usually do, is to use Spout and OBS Studio to do the recording. You will need this add-on for OBS. Easy to setup, resolution independent, solid performance and you get OBS GUI and all it’s extras / add-ons.

@hubris

good to know - thanks! will check this!
Actually I didn’t find tons of solutions in ofxAddons to capture videos or frames at high rate.

is very slow just looking at the code. Does it pixel by pixel in a width/height loop :face_with_open_eyes_and_hand_over_mouth:

is calling readToPixels … also quite slow

empty

Raspberry PI only

Looks promising. But I see it talking about pixels again, so looks like it’s CPU->Video, not GPU->Video…

that’s about it…

readToPixels is very slow from what I’ve seen.
maybe can work for small buffers, but not for 1920x1920
so this is not an option…

You can share FBOs across multiple windows. You just have to specify it in main.cpp.

See the commented example code here:

So in this case your draw call for the second window would be drawing just the fullscreen fbo.

And you can make a window go fullscreen on a second display. Just move the window to that display first and then toggle fullscreen.

Ah - nice to know! Thanks.

It’s NOT the most elegant solution, but the fact that I can use Nvidia GPU to encode MP4 on-the fly is somewhat appealing.

I ended up using a large window spanning two monitors, which I position at 0,0 at left-most monitor and then I just draw my ofFbos - one original, one scaled down. Then I use ffmpeg to grab the left monitor by indicating required area in parameters. Seems to be working fine!

2 Likes