Hi Folk’s !
I got some issue with ofxVideoRecorder…
I try to record the screen 4 time and then play the 4 videos recorded simultaneously and repeat the process a couple time.
for now, I’m able to record only 1 video, all the other videos created by the recording seems not working (I couldn’t open it ?).
Anyone can point me out what’s wrong in my code ?
void ofApp::setup(){
ofSetFrameRate(30);
ofSetLogLevel(OF_LOG_VERBOSE);
now.allocate(ofGetWidth(), ofGetHeight());
now.begin();
ofClear(0,0,0,255);
now.end();
screenFbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGB);
screenFbo.begin();
ofClear(0,0,0,255);
screenFbo.end();
videos.resize(10); // 10 video players !
vIndex = 0;
fileName = "test";
fileExt = ".mov";
vidRecorder.setVideoCodec("mpeg4");
ofAddListener(vidRecorder.outputFileCompleteEvent, this, &ofApp::recordingComplete);
bRecording = false;
ofEnableAlphaBlending();
}
//--------------------------------------------------------------
void ofApp::exit(){
ofRemoveListener(vidRecorder.outputFileCompleteEvent, this, &ofApp::recordingComplete);
vidRecorder.close();
}
//--------------------------------------------------------------
void ofApp::update(){
//vidGrabber.update();
if( bRecording ){
screenFbo.readToPixels(recordPixels);
bool success = vidRecorder.addFrame(recordPixels);
if (!success) {
ofLogWarning("This frame was not added!");
}
}
// Check if the video recorder encountered any error while writing video frame or audio smaples.
if (vidRecorder.hasVideoError()) {
ofLogWarning("The video recorder failed to write some frames!");
}
if (vidRecorder.hasAudioError()) {
ofLogWarning("The video recorder failed to write some audio samples!");
}
for(auto &video:videos){
video.update();
}
}
//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(0);
int x = sin(ofGetElapsedTimeMillis()*0.001)*500+500;
// Dessine une cercle oscillant au milleu (fbo)
now.begin();
ofClear(0, 0, 0, 255);
ofSetColor(255);
ofDrawCircle(x, ofGetHeight()/2, 50);
now.end();
// on enregistre 4x (voir 'r')
if(vIndex < 4){ // 0,1,2,3
screenFbo.begin();
now.draw(0,0);
screenFbo.end();
}
if(vIndex > 3 && vIndex < 8){ // 4,5,6,7
screenFbo.begin();
ofPushMatrix();
ofScale(ofGetWidth(), ofGetHeight());
for(int i = 0; i < 4; i++){
videos[i].draw( (i%2)*1/2., (i/2)*1/2., 1/2., 1/2.);
}
ofPopMatrix();
screenFbo.end();
}
if(bRecording){
ofSetColor(255, 0, 0);
ofDrawCircle(ofGetWidth() - 20, 20, 5);
}
ofSetColor(255);
screenFbo.draw(0,0);
}
//--------------------------------------------------------------
void ofApp::recordingComplete(ofxVideoRecorderOutputFileCompleteEventArgs& args){
cout << "The recoded video file is now complete." << endl;
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
if(key=='r'){
bRecording = !bRecording;
if(bRecording && !vidRecorder.isInitialized()) {
vidRecorder.setup(fileName + ofToString(vIndex) + fileExt, screenFbo.getWidth(), screenFbo.getHeight(), 30);
// Start recording
vidRecorder.start();
}
else if(!bRecording && vidRecorder.isInitialized()) {
vidRecorder.setPaused(true);
}
else if(bRecording && vidRecorder.isInitialized()) {
vidRecorder.setPaused(false);
}
}
if(key=='c'){
bRecording = false;
vidRecorder.close();
videos[vIndex].load("test"+ ofToString(vIndex)+".mov");
videos[vIndex].play();
vIndex++;
ofAddListener(vidRecorder.outputFileCompleteEvent, this, &ofApp::recordingComplete);
}
if(key == 'p'){
bPlaying = !bPlaying;
}
}
Thank’s !