Hi I am trying to play video with shader my problem is that the FPS always change from 46 FPS to 1 FPS
the log of my FPS
FPS: 46
FPS: 8
FPS: 6
FPS: 1
FPS: 4
FPS: 1
FPS: 8
FPS: 2
FPS: 3
FPS: 5
FPS: 1
FPS: 7
FPS: 24
FPS: 23
FPS: 6
FPS: 13
FPS: 4
FPS: 3
FPS: 5
my codes looks like this.
#include “ofApp.h”
ofShader shader; //Shader
ofFbo fbo; //Buffer for intermediate drawing
ofImage image;
ofVideoPlayer video; //Declare video player object
float prevtime = ofGetElapsedTimef();
double clockToMilliseconds(clock_t ticks){
// units/(units/time) => time (seconds) * 1000 = milliseconds
return (ticks/(double)CLOCKS_PER_SEC)*1000.0;
}
clock_t deltaTime = 0;
unsigned int frames_count = 0;
double frameRate = 30;
double averageFrameTimeMilliseconds = 33.333;
//--------------------------------------------------------------
void ofApp::setup() {
shader.load( “shaderVert.c”, “shaderFrag.c” );
fbo.allocate( ofGetWidth(), ofGetHeight() );
image.loadImage( “sunflower.png” );
video.loadMovie("300.mp4");
video.play();
}
//--------------------------------------------------------------
void ofApp::update(){
clock_t beginFrame = clock();
video.update();
clock_t endFrame = clock();
deltaTime += endFrame - beginFrame;
frames_count ++;
//if you really want FPS
if( clockToMilliseconds(deltaTime)>1000.0){ //every second
frameRate = (double)frames_count*0.5 + frameRate*0.5; //more stable
std::cout << "FPS: "<<frames_count << std::endl;
frames_count = 0;
deltaTime -= CLOCKS_PER_SEC;
averageFrameTimeMilliseconds = 1000.0/(frameRate==0?0.001:frameRate);
}
}
//--------------------------------------------------------------
void ofApp::draw(){
//1. Drawing into fbo buffer
fbo.begin(); //Start drawing into buffer
//Draw something here just like it is drawn on the screen
ofBackgroundGradient( ofColor( 255 ), ofColor( 128 ) );
ofSetColor( 255, 255, 255 );
//image.draw( 351, 221 );
video.draw(0,0,1024,768);
fbo.end(); //End drawing into buffer
//2. Drawing to screen through the shader
shader.begin(); //Enable the shader
//Draw fbo image
ofSetColor( 255, 255, 255 );
fbo.draw( 0, 0 );
shader.end(); //Disable the shader
}
How to fixed this? I am expecting steady FPS value.