Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

ofxVideoRecorder save video with effects not working

$
0
0

@Jhovarie_Guiang wrote:

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);
    */
}

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles