hi all
i am trying to make a webcam recorder with the ofQtVideoSaver wich is working really good:
the thing is i think that my recorder is messing up the time sometimes going faster sometimes going slower. Maybe some one can help me optimize the code
OSX
macbook
OF 005.
mycode:
main.cpp
#include "ofMain.h"
#include "testApp.h"
//========================================================================
int main( ){
ofSetupOpenGL(720,400, OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new testApp());
}
testApp.cpp
#include "testApp.h"
static bool bRecording = false;
static bool cRecording = false;
//--------------------------------------------------------------
void testApp::setup(){
fileNumber = 1;
camWidth = 320; // try to grab at this size.
camHeight = 240;
vidGrabber.setVerbose(true);
vidGrabber2.setDeviceID(0);
vidGrabber.initGrabber(camWidth,camHeight);
vidGrabber2.setVerbose(true);
vidGrabber2.setDeviceID(1);
vidGrabber2.initGrabber(camWidth,camHeight);
string fileName = "output_" + ofToString(fileNumber) + ".mov";
string fileName2 = "output2_" + ofToString(fileNumber) + ".mov";
saver.listCodecs();
//saver.setCodecType(2); ZACH FIX see recording quicktime with sound in sync on of forum
saver.setCodecQualityLevel(OF_QT_SAVER_CODEC_QUALITY_NORMAL);
saver.setup(320,240,fileName);
saver2.listCodecs();
//saver.setCodecType(2); ZACH FIX see recording quicktime with sound in sync on of forum
saver2.setCodecQualityLevel(OF_QT_SAVER_CODEC_QUALITY_NORMAL);
saver2.setup(320,240,fileName2);
ofSetFrameRate(30);
}
//--------------------------------------------------------------
void testApp::update(){
ofBackground(100,100,100);
vidGrabber.grabFrame();
vidGrabber2.grabFrame();
if (bRecording == true){
saver.addFrame(vidGrabber.getPixels(), 1.0f / 30.0f);
// you can also pass in the frameRate:
// saver.addFrame(vidGrabber.getPixels(), 1.0f / 30.0f); // 30 fps for this frame
// saver.addFrame(vidGrabber.getPixels(), 1.0f / 5.0f); // 5 fps for this frame, etc....
}
if (cRecording == true){
saver2.addFrame(vidGrabber2.getPixels(), 1.0f / 30.0f);
}
}
//--------------------------------------------------------------
void testApp::draw(){
ofSetColor(0xffffff);
vidGrabber.draw(20,20);
vidGrabber2.draw((20*2)+camWidth,20);
if (saver.bAmSetupForRecording()){
ofSetColor(0xffffff);
ofDrawBitmapString("setup for recording, (press 's' to save)",100,300);
if (bRecording){
ofSetColor(0x00ff00);
ofDrawBitmapString("recording, (press 'r' to toggle)",100,320);
} else {
ofSetColor(0xff0000);
ofDrawBitmapString("not recording, (press 'r' to toggle)",100,320);
}
} else {
ofSetColor(0xffffff);
ofDrawBitmapString("not setup for recording (press 'a' to start)",100,300);
ofSetColor(0xaaaaaa);
ofDrawBitmapString("not setup to record",100,320);
}
}
//--------------------------------------------------------------
void testApp::keyPressed (int key){
if (key == 'a'){
fileNumber = ++fileNumber;
string fileName = "output_" + ofToString(fileNumber) + ".mov";
string fileName2 = "output2_" + ofToString(fileNumber) + ".mov";
saver.setup(320,240,fileName);
saver2.setup(320,240,fileName2);
} else if (key == 's'){
saver.finishMovie();
saver2.finishMovie();
bRecording = false;
cRecording = false;
} else if (key == 'r'){
bRecording = !bRecording;
cRecording = !cRecording;
}
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(){
}
testApp.h
#ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofAddons.h"
#include "ofQtVideoSaver.h"
class testApp : public ofSimpleApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased();
ofVideoGrabber vidGrabber;
ofVideoGrabber vidGrabber2;
ofTexture videoTexture;
int camWidth;
int camHeight;
int fileNumber;
string fileName;
string fileName2;
ofQtVideoSaver saver;
ofQtVideoSaver saver2;
};
#endif