Video to sequence

I’m trying to convert a video to a vector of images.

I’ve been trying something among these line

ofVideoPlayer player;
vector <ofImage> sequence;

player.setPixelFormat(OF_PIXELS_RGB);
player.load("movies/fingers.mov");
player.setLoopState(OF_LOOP_NORMAL);
player.play();

for(int i= 0;i < player.getTotalNumFrames();i++ )
{
    player.nextFrame();
    ofImage image;
    image.allocate(player.getWidth(), player.getHeight(), OF_IMAGE_COLOR);
    image.setFromPixels(player.getPixels());
    sequence.push_back(image);
}

But I’ve been getting these errors

[ error ] ofxiOSVideoPlayer: getPixels(): Returning pixels that may be unallocated. Make sure to initialize the video player before calling getPixels.
[ error ] ofPixels: image type not supported
[ error ] ofPixels: image type not supported
[ error ] ofPixels: image type not supported

I’m on a master using Mac (why is ofxiOSVideoPlayer in the error?)
Is this a good aproach?

Thanks in advance! :wink:

hiya

are you making something for the iphone or mac?
because ofxiOSVideoPlayer is for the iphone are you using the os release of openframeworks ?
try this
image.setFromPixels(player.getPixelsRef());

    ofVideoPlayer player;
vector <ofImage> sequence;

player.setPixelFormat(OF_PIXELS_RGB);
player.loadMovie("fingers.mov");
//player.load("moives/fingers.mov");
player.setLoopState(OF_LOOP_NORMAL);
player.play();


for(int i= 0;i < player.getTotalNumFrames();i++ )
{
    ofImage image;
    player.nextFrame();
    image.allocate(player.getWidth(), player.getHeight(), OF_IMAGE_COLOR);
    image.setFromPixels(player.getPixelsRef());
    sequence.push_back(image);
    image.draw(0, 0);
}

if you need to use ofxiOSVideoPlayer then it might still work

Thanks @strimbob
I’m targetting Mac. It seems your suggestion didn’t have any effect :confused:

The latest merge from i-n-g-o/ofAVFoundationPlayer to master by @theo seems to fix the error pointing to ofxiOSVideoPlayer, but still the same error just pointing to ofAVFoundationPlayer:

2015-04-04 13:13:25.137 mySketchDebug[51512:1795889] video loaded at 320 x 240

[ error ] ofAVFoundationPlayer: getPixels(): Returning pixels that may be unallocated. Make sure to initialize the video player before calling getPixels.
[ error ] ofPixels: image type not supported
[ error ] ofPixels: image type not supported
[ error ] ofPixels: image type not supported

…the error shows up for each frame.

To my understanding ofVideoPlayer::nextFrame() allows to advance through the timeline without the extra hassle of ofVideoPlayer::setPosition() because it doesn’t have to compute the previous frames. Is that right?

Also, my assumption is that ofVideoPlayer::update() is only needed for normal playback but its not my case.

It seems I’m missing something.

It’s just a information. Your code works at 0.8.4 Version.

I don’t know, why this code doesn’t work in github oF version.
Maybe this is a error about loading in setup.

You can check something in github oF version like…
‘0’(nothing) will be show.

// put at end line in stetup()
cout << player.isloaded() << end;  // 

So… player.getPixelsRef() will be error.

Thanks for checking it out @jeonghopark .

It seems there is some bug on master. ofVideoPlayer::load() returns true while ofVideoPlayer::isLoaded() returns false (they should reference the same thing, right?)

bool isLoaded = player.load("movies/fingers.mov");
cout << isLoaded << endl; // 1
cout << player.isLoaded() << endl; // 0 

I’m able to play the video normally by using ofVideoPlayer::update(); but I get this error the first seven update calls

[ error ] ofAVFoundationPlayer: getPixels(): Returning pixels that may be unallocated. Make sure to initialize the video player before calling getPixels.

It looks like ofVideoPlayer::load() was threaded…

ofVideoPlayer::load() its definitely threaded but its returning true for some reason ( I guess is some legacy stuff, it doesn’t make sense to return anything if is threaded).

So, it kind of works if I procces it after ofVideoPlayer::isLoaded() == true

#include "ofApp.h"

void ofApp::setup(){

    player.setPixelFormat(OF_PIXELS_RGB);
    bool isLoaded = player.load("movies/fingers.mov");
    cout << isLoaded << endl; // 1
    cout << player.isLoaded() << endl; // 0
    
    player.setLoopState(OF_LOOP_NORMAL);
    player.play();
}

void ofApp::update(){
    
    if(!player.isLoaded())
        return;
    if(processed)
        return;
    
    for(int i= 0;i < player.getTotalNumFrames();i++ )
    {
        player.nextFrame();
        ofImage image;
        image.allocate(player.getWidth(), player.getHeight(), OF_IMAGE_COLOR);
        image.setFromPixels(player.getPixels());
        sequence.push_back(image);
        processed = true;
    }
}

void ofApp::draw(){
    
    ofBackgroundHex(0xffffff);
    if(!processed)
        return;
    
    int size = 10;
    
    for(int i=0; i<sequence.size(); i++)
    {
        int x = i%(ofGetWindowWidth()/size);
        int y = i*size/ofGetWindowWidth();
        sequence[i].draw(x*size, y*size, size, size);
    }
}

…but ofVideoPlayer::nextFrame() its outputing this on the console:

[16:17:44.476] <<<< Boss >>>> figPlaybackBossStartPrerollAndSetPlayState: zero tracks, so posting a fake preroll completion

And ofVideoPlayer::getPixels() is returning the same frame everytime.

no problem. @xavivives. I want to know a solution of this problem. :slight_smile:
A few days ago, i had a same problem like you. I used just oF 0.8.4 version.
Anyway. It seems a bug.
Would you change a category of the post to bug or write a post to github issue?

Had the same problem with the master branch. Playing the movie worked fine, but I could not access the pixels.
Switched back to 0.8.4

have same problem! :sob: