how to fade a video in and out

Hi I’m using openframeworks ofVideoPlayer() function :

I’ve created a video, but I want to fade it out when it is done. Any idea of how to do that?

You can use ofSetColor to alter the color of whatever is drawn afterwards. So to fade a movie out, you just need to change either the brightness or alpha of the current color prior to drawing the video.

To fade out the end of the video, you need to check to see where the current “play head” position is relative to the total duration of the video, once the time remaining is less than a certain value, lets say 5 seconds, you start fading the alpha based on the percentage of the way through the last 5 seconds.

Try this, let me know if you have any questions about it

void testApp::draw() {  
    float videoLength = videoPlayer.getDuration();  
    float videoElapsedTime = videoPlayer.getPosition()*videoPlayer.getDuration();  
    float videoTimeRemaining = videoLength - videoElapsedTime;  
    float fadeTime = 5.0;  
    if(videoTimeRemaining < fadeTime){ //if it is time to fade  
        ofSetColor(255, 255, 255, 255 * videoTimeRemaining / fadeTime); // fade based on time left  
    else {  
        ofSetColor(255, 255, 255, 255); //else draw at full opacity  
    ofEnableAlphaBlending(); // got to have this somewhere to use opacity  
    videoPlayer.draw(0, 0);  

1 Like