ofxVideoRecorder -> multiple recording

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 !

I am not sure if you are trying to record 4 videos at the same time or one after they other. ?

I would load the new video not right after you stop the recording process but rather when “recordingComplete()” function gets called.

I want to record one after the other…

here is the process :
‘r’ = record -> ‘r’ = stop recording -> ‘c’ = close… (for 1 video)
then I am suppose to have the file ready in my bin/data folder…
I do this 4 times, and then I draw the 4 recorded videos…

The problem is that the files (except the first one) in the bin/data folder seems not to be close ?
Here is a screen capture of the folder (bin/data)

and thank’s for pointing me out the loading thing :slight_smile:

can you send me a zip of your whole project. I can take a look then.

here’s the link for the file:

I really appreciate !
Thank you

it works for me on OF 0.10.1 with macOS 10.14.6

I had to add ofxVideoRecorder and ofxPoco via project generator.
I also had to add the FFmpeg folder to my data folder and point the add-on to this folder, since FFmpeg (usually pointing to somewhere deep inside the os) does not work otherwise on my system.


I hope this works for you too.

OK !! maybe I have a problem with ofxVideoRecorder version ?
When I open your project, I cannot find this function in the add-on
vidRecorder.stopThread();

But I download it from the http://www.ofxaddons.com/
It suppose to be the latest version

here is my version.

It work’s now !!

Thank’s for your time !!