How to get the current frame (pixel buffer) to record a video


I would like to use ofxVideoRecorder to record a video of my oF applications. Right now I use the particles example to get started. In the example that comes with ofxVideoRecorder ofVideoGrabber is used to grab frames from the camera.

Is there a way to get the current frame (pixel buffer) in my draw() method?



If you use an FBO you can just draw whatever you want into it and then grab the pixels using:!show_readToPixels

Thank you hahakid! I solved it like so:

ofImage img;
img.grabScreen(0, 0, ofGetWidth(), ofGetHeight());

Now I have problems recording the audio. My code looks like this:

void ofApp::audioOut(ofSoundBuffer &buffer) {
  auto b = buffer.getBuffer();
  vidRecorder.addAudioSamples(&b[0], b.size(), buffer.getNumChannels());

Problem is that the audioOut(...) is not called. This is how I initialise my ofSoundPlayer:


I guess I have to connect the player to ofApp. Am I on the right track here?

The audioOut function is used to generate audio samples to be given to the sound card. You can use it to generate tones by calculating audio samples and saving them to the sound buffer. The function is not being called because this method of audio generation needs to be initialize by a call to ofSoundStream().

Unfortunately, the ofSoundPlayer object you’re using to play the mp3 is not connected to the audioOut function at all. In fact, unless something has changed since I last looked into this, there is no good way to get the “current mix” of sound being played by an app that is using something like ofSoundPlayer to generate sound. The work-around is to re-route the output of the entire app back in as an input, then use the audioInput function to save the samples to the ofxVideoRecorder object.

I have done this in the past using an aux cable that literally went from my audio output jack into my audio input jack. There may also be some third party software solutions to accomplish this without converting to analog.

Thanks for your answer TimS! Yesterday I solved the problem by converting my track to WAV and then use libsndfile to read the audio data in audioOut. This works quite good. Though I am not sure whether this approach keeps video and audio in sync in the resulting video.

hi parasight,

i am having an issue with ofxVideoRecorder and i think my audioout code is the problem:

my audioout code is:

if(bRecording) vidRecorder.addAudioSamples(&trackBuffer4[0], trackBuffer4.size(), nChannels);

my project compiles, but crashes soon after running.