ofxVideoRecorder save video with effects not working

Hello I need help. I am trying to add effects to a video what I did is first

  1. load and play video.
  2. then apply shader to add effects to video.
  3. save video using ofxVideoRecorder…

My problem is I cannot save the video with shader effects … I can only save video without effects whats wrong with my code?

#include "ofApp.h"

ofShader shader;    //Shader
ofFbo fbo;            //Buffer for intermediate drawing
ofImage image;
ofVideoPlayer video; //Declare video player object
ofPixels recordPixels;

void ofApp::setup(){
    shader.load("shaderVert.c",
                "shaderFrag.c" );
   // fbo.allocate( ofGetWidth(), ofGetHeight() );
    fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGB);
    video.load("300.mp4");
    video.play();
    
    //recording setup ----------------------
    sampleRate = 44100;
    channels = 2;
    ofSetFrameRate(60);
    ofSetLogLevel(OF_LOG_VERBOSE);
    fileName = "testMovie";
    fileExt = ".mov"; // ffmpeg uses the extension to determine the container type. run 'ffmpeg -formats' to see supported formats
    
    // override the default codecs if you like
    // run 'ffmpeg -codecs' to find out what your implementation supports (or -formats on some older versions)
    vidRecorder.setVideoCodec("mpeg4");
    vidRecorder.setVideoBitrate("800k");
    vidRecorder.setAudioCodec("mp3");
    vidRecorder.setAudioBitrate("192k");
    
    ofAddListener(vidRecorder.outputFileCompleteEvent, this, &ofApp::recordingComplete);
    soundStream.setup(this, 0, channels, sampleRate, 256, 4);
    ofEnableAlphaBlending();
    
    //start recording------------------------------------
    
    bRecording = true;
    //vidRecorder.setup(fileName+ofGetTimestampString()+fileExt, ofGetWidth(), ofGetHeight(), 30, sampleRate, channels);
              vidRecorder.setup(fileName+ofGetTimestampString()+fileExt, ofGetWidth(), ofGetHeight(), 30); // no audio
    //            vidRecorder.setup(fileName+ofGetTimestampString()+fileExt, 0,0,0, sampleRate, channels); // no video
    //          vidRecorder.setupCustomOutput(vidGrabber.getWidth(), vidGrabber.getHeight(), 30, sampleRate, channels, "-vcodec mpeg4 -b 1600k -acodec mp2 -ab 128k -f mpegts udp://localhost:1234"); // for custom ffmpeg output string (streaming, etc)
    
    // Start recording
    vidRecorder.start();
    
    fbo.begin();
    ofClear(0, 0, 0, 255);
    fbo.end();
}

//--------------------------------------------------------------
void ofApp::update(){
    fps.updateStartProcess();
    video.update();
    if(video.isFrameNew() && bRecording) {
        //saved video but no shader effects...
        ofPixels pixels; // this is used to store the pixels read from the fbo
        fbo.readToPixels(pixels);
        vidRecorder.addFrame(pixels);
        /*
        //save video with shader effects but it doest not work properly and it run very slow
        ofImage img;
        img.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
        vidRecorder.addFrame(img.getPixels());
        */
    }
    fps.updateEndProcess();
}

void ofApp::draw(){
    fbo.begin();
    ofClear(0, 0, 0, 255);
    video.draw(0,0,1024,768);
    fbo.end();
    
    shader.begin();
    ofSetColor( 255, 255, 255 );
    fbo.draw( 0, 0 );
    shader.end();
    /*
    save video but there is no shader effects
    ofPixels pixels;
    fbo.readToPixels(pixels);
    vidRecorder.addFrame(pixels);
    */
}

It would be really helpfull if you could format your code properly. If you put ``` at the beggining and at the end of your code, you get syntax highlighting and all your code in a single block.

First, every time you call ofPixels pixel in your draw call you are allocating a new object, move this to the header file (ofApp.h), so that it is allocated at the beginning and then you keep using the same object, you can gain some speed, although I do not think that performance are a problem here.

ofPixels pixels; // this goes to the header file

Second, I did not test it. But basically you are applying your shader effect after recording. Try this:

void ofApp::update(){
	fps.updateStartProcess();
	video.update();

	ofClear(0, 0, 0, 255);

	fbo.begin();
	shader.begin();
	video.draw(0,0,1024,768);
	shader.end();
	fbo.end();

	if(video.isFrameNew() && bRecording) {
        // pixels is the object declared in your header file
        fbo.readToPixels(pixels);
		bool success = vidRecorder.addFrame(pixels);
        if (!success) {
            ofLogWarning("This frame was not added!");
        }

	}
	fps.updateEndProcess();
}

void ofApp::draw(){
	ofSetColor( 255, 255, 255 );
	fbo.draw( 0, 0 );
}