How to set framerate for recording from webcam

Hi all,

This might be a basic question, but I’ve tried to use the osxVideoRecorderExample from the examples folder which uses ofQTKitGrabber. However, using setDesiredFrameRate on the video grabber gives the warning [warning] ofQTKitGrabber: setDesiredFrameRate(): cannot set framerate for QTKitGrabber. I searched though the forums and haven’t seen a clear answer. The source for ofQTKitGrabber shows this warning so I imagine that calling the function on ofVideoGrabber calls the function defined in ofQTKitGrabber (if I’m not mistaken) so that function will never work.

I don’t actually really understand fully how video recording works with the grabber and recorder in that example. So even an explanation of that would be super helpful, but I’m wondering if anyone has a solution for using some recording method on osx to be able to change the rate of grabbing frames from the camera. Any help would be appreciated. I’m on OSX 10.10.

Thanks in advance,
Patrick

you are right, looking at the code the QTKit will always throw the warning. You can probably do a work around for the framerate issue by sampling the frames at the rate you want it to be. like in update check if enough time has passed since you last sampled a frame with something like

if(ofGetElapsedTimef() - timeSinceLastFrame > 1.0/framerate){
  frame = vidGrabber.getPixels();
  timeSinceLastFrame = ofGetElapsedTimef();
}

thats not perfect but it should work

Hi,

Thanks for the information. So are you saying that the thing that actually controls the framerate is how often you sample from the camera and not an internal camera or driver (or other) setting? I didn’t realize this as all of my videos come out 30 fps regardless of what I try to set or anything else. So I thought that there was something (maybe in the camera) setting that rate of capture from the scene. Perhaps both could be true I guess and the camera is just set at 30 fps and I have no interface to change that.

Any other thoughts?

Thanks a million,
patrick

Not quite, there is a hardware limit and some drivers are capable of changing framerates. QtKit doesn’t seem to have that implemented though others do. The video recorder example is also stuck using QtKit and you don’t pass in frames so you can’t control the framerate from the hardware or software.

My honest suggestion is that Apple has dropped QtKit so you might want to use an extension like ofxVideoRecorder which uses ffmpeg and has more customizable options than the built in class.

Just to add a note to @DomAmato’s great suggestion - you can get pretty solid framerate with ofxVideoRecorder by adding an audio track, even a silent one. It does a better job syncing to a static framerate if there’s audio to compare against.

Thank you both for the replies. I’m looking into ofxVideoRecorder right now. I’m not 100% I understand what you mean about the audio track however. You mean record a silent audio track at a particular bit rate before hand and add it to each video steam that you are pulling in when you record the final video through ffmpeg? If that is the case, you’re saying that ffmpeg will use the audio track to regulate the video frames in some manner?

thanks again.

Not beforehand, but while you are sending it video frames - check out the examples included. There’s an option to setup an audio track when recording a video - the audio input can be any valid ofSoundStream object, but doesn’t care if the source is making any sound, as it were.

Thanks for all the information. I will try some of this stuff out. Thanks for your time and effort in the responses.