Video artefacts when switching ofVideoPlayer pointers

Hey all,

I’m getting some strange video artefacts when switching between pointers to ofVideoPlayers. It’s usually a few frames from another video file, but can be garbage, which makes me think they are briefly pointing at the wrong place. This doesn’t happen when looping a single video.

This is happening both on OS X and Linux, the videos are H.264 mp4 files.

Class.h

vector<string>              mFiles;
vector<ofVideoPlayer*>      mPlayers;
ofVideoPlayer*              mPlayer;
int                         mFileIndex;

Class.cpp

void setup() {
    mFileIndex = 0;
    mPlayer = NULL;

    ofDirectory dir(VIDEO_PATH);
    if (dir.exists()) {
        dir.allowExt("mp4");
        dir.listDir();
        dir.sort();

        for(int i = 0; i < dir.numFiles(); ++i) {
            mFiles.push_back(dir.getPath(i);
            mPlayers.push_back(new ofVideoPlayer());
            mPlayers.back()->loadMovie(mFiles.back();
            mPlayers.back()->setLoopState(OF_LOOP_NONE);
        }
    }
    dir.close();

    mPlayer = mPlayers.at(mFileIndex);
}

void update() {
    if (mPlayer && mPlayer->isLoaded()) {

        mPlayer->update();

        if (mPlayer->getIsMovieDone()) {
            mFileIndex = (mFileIndex + 1) % mFiles.size();
            mPlayer = mPlayers.at(mFileIndex);
            mPlayer->play();
        }
    }
}

Any thoughts much appreciated,

Arthur C

This garbage frame seems to occur on the 0th frame of the new player, so calling mPlayer->update() before mPlayer->play() does the trick.

Is this to be expected? The documentation implies that .play() should be called before .update()

Did you edit your code after you figured it out? It looks like you do call .update() before you call .play() already… unless I’m missing something? I’m having a similar problem when switching between ofVideoPlayer objects: garbage frames when they app is first run, and then a flashframe from the middle of the video every time I switch back to it (when I’m trying to start the video over).

In my code I called update on the old player, but not before calling play on the new player.

From what I remember, I may have still had issues as I ended up concatenating the videos and using a single video player in production.