[closed] OfAppNoWindow and ofFbo video IO behaviour conflict

I am trying to render a video using ofxVideoRecorder on a headless server. The video renders correctly with a normal window, i.e.

ofSetupOpenGL(640,420, OF_WINDOW);

However, I get messed up frames (could not attache image) with a ofAppNoWindow.

ofAppNoWindow headless;
ofSetupOpenGL(&headless,640,420,OF_WINDOW);
ofRunApp(new testApp());

I have also tried,

ofAppNoWindow headless;
headless.setupOpenGL(640,420,OF_WINDOW);
headless.runAppViaInfiniteLoop(new testApp());

I render objects in ofFbo in update method(). I tried saving image with and without headless window. The image saves correctly without headless window.

I think the issue is with FBO drawing incorrectly with ofApppNoWindow

This is the Fbo draw code

fbo.begin();
     ofClear( 255, 255, 255, 0 );
     ofEnableAlphaBlending();
     element.draw(); //element is my class
fbo.end();

Here is the screen capture code.

fbo.readToPixels(pixels);
pixels.setNumChannels(3);
vidRecorder.addFrame(pixels); //ofxVideoRecorder object

Would appreciate any help to enable near realtime video rendering and writing.

certain OpenGL operations that use the GPU (like ofFbo) may not be available. When I have used headless configurations in the past I have had to things like setUseTexture(false) with ofImage.

what do you get when calling fbo.isAllocated()? Are you seeing any log messages with ofSetLogLevel(OF_LOG_VERBOSE) ?

yes using the ofAppNoWindow won’t create an openGL context so you won’t be able to use any opengl resource. if you are drawing in 2D you can use a cairo renderer instead and draw to PNG or SVG every frame. Just set the renderer before ofSetupOpenGL with:

ofPtr<ofCairoRenderer> cairo(new ofCairoRenderer);
cairo.setup("frame.png");
//cairo.setup("frame.svg");
ofSetCurrentRenderer(cairo);

depending on the extension of the file it’ll use that file type, you can also use pdf and it’ll create a new page for each frame instead of a file per frame.but then you need to make sure of closing the renderer before stopping the app so it finish flushing the pdf correctly

1 Like

Dear @jvcleave and @arturo, Thanks a lot for your time and replying to my post.

jvcleave, you are correct. fbo.isAllocated returns 0 with ofAppNoWindow. It says that the graphic card does not support FBO. I think this has to do with what @arturo pointed out.

However, I will have 3D elements. Looks like Cairo Renderer doesnt work for me.

I get video encoding at 7 fps using VideoRecorder when I set up a blank 640X420 window and draw in FBO. This drops to 2 fps for 1024X720 window. My framerate is 30.

Any advice on how I can fasten the encoding? I got supperexcited with od\fAppNoWindow. I was getting 30 fps but now I realise its because nothing was happening.

PS: I also tried using openCV::VideoWriter which fails to open(). This seems a widespread (and ad hoc) problem about setting up openCV in Linux.

almost sure the drop in the fps has not so much to do with the video encoder but with downloading data from the graphics card, there’s a couple of addons that allow to use a PBO to download asynchronously which should make the process faster:

if that’s not enough, a pbo can be accessed from a different thread once it’s mapped so you could modify that addon to read the mapped memory from a thread and do the encoding from that same thread which should leave the GL thread completely free of anything that could slow it down

Dear @arturo, thanks for your help. I have started work with ofxFastFboReader. It looks promising. I’ll close this thread now (and edit the title).

Just an update about fbo reading speed. I think this is highly dependent on hardware. It was taking around 250 ms on my i5 with 3GB RAM to read a 640x420 fbo. I ran the same code on an i7 machine with 8GB RAM and reading time dropped to 4 ms.