getPixels() returning null using ofVideoPlayer

Hi there.

I’m having incredibly painful problems loading frames of a video into a vector called eventFrames.

I have pasted the whole function below, and I get a bad access error at this line:

currentPixelsWithAlpha[pixel * 4 ] = 255 - currentPixelsNoAlpha[pixel * 3 ];

It would seem that when I assign the ‘currentPixelsNoAlpha’ array with the below function the array == null

mainFrames->getPixels();

This line:

cout << mainFrames->isLoaded() << ", init: " << mainFrames->isInitialized() << endl;

Outputs this:
“0, init: 0”

However the load() method for mainFrames gives me this output in the output so I’m inclined to think the video was loaded correctly:
“2016-02-01 23:57:09.672 timelineDebug[2036:87179] video loaded at 320 x 240 @ 30.099001 fps”

I think I might be experiencing similar problems to this thread, but I am really unsure on how to proceed. The advice at the end of the thread is to switch to 0.8.4, but I’d like to avoid that if I can. Any thoughts from you wiser folk would be massively appreciated - thanks for taking the time to read this too.

Superdude / Leon

EDIT: just note as well this is called during ofApp::setup()

// this function generates the frames to be manipulated taken from main video track
bool Event::generateFrames(ofxTLVideoTrack* _mainVideo, unsigned long _framesBegin, unsigned long _framesEnd) { 
    
    // get pointer to main video track
    //std::shared_ptr<ofVideoPlayer> mainFrames = _mainVideo->getPlayer();
    std::shared_ptr<ofVideoPlayer> mainFrames = make_shared<ofVideoPlayer>();
    mainFrames->load(ofToDataPath("fingers.mov"));
    
    // check it is not null and not out of bounds
    if (mainFrames != NULL && _framesEnd < mainFrames->getTotalNumFrames()) {
        
        // set size of event frames
        eventFrames.resize(_framesEnd - _framesBegin);
        
        unsigned long eventFramesIndex = 0;
        unsigned int  main_width = floor(mainFrames->getWidth());
        unsigned int  main_height = floor(mainFrames->getHeight());
        
        // current frame's pixels with room for an alpha value
        unsigned char * currentPixelsWithAlpha = new unsigned char[main_width * main_height * 4];
        
        unsigned int totalPixels = main_width * main_height;
        
        // we will fill this with pixels later in the for loop
        ofPixels temp;
        
        // set the beginning frame
        mainFrames->setFrame(_framesBegin);
        
        cout << mainFrames->isLoaded() << ", init: " << mainFrames->isInitialized() << endl;
        
        // grab frames from main video, from the bounds specified
        for (unsigned long mainFrameIndex = _framesBegin; mainFrameIndex < _framesEnd; ++mainFrameIndex) {
            
            // allocate space
            temp.allocate(main_width, main_height, OF_IMAGE_COLOR_ALPHA);
            
            // get current frame from main main video using for loop's index
            mainFrames->nextFrame();
            
            // get the current frames pixels
            unsigned char * currentPixelsNoAlpha = mainFrames->getPixels();
            
            // loop through the pixels and convert to alpha pixels at pixel level
            for (int pixel = 0; pixel < totalPixels; ++pixel) {
                
                currentPixelsWithAlpha[pixel * 4    ] = 255 - currentPixelsNoAlpha[pixel * 3    ];
                currentPixelsWithAlpha[pixel * 4 + 1] = 255 - currentPixelsNoAlpha[pixel * 3 + 1];
                currentPixelsWithAlpha[pixel * 4 + 2] = 255 - currentPixelsNoAlpha[pixel * 3 + 2];
                currentPixelsWithAlpha[pixel * 4 + 3] = 255;
            }
            
            // fill 'temp' with pixels array
            temp.setFromPixels(currentPixelsWithAlpha, mainFrames->getWidth(), mainFrames->getHeight(), OF_IMAGE_COLOR_ALPHA);
            
            // push to the back of the deque
            eventFrames[eventFramesIndex] = temp;
            
            // increment event frames
            eventFramesIndex++;
            
            // ensure clearance of pixels
            temp.clear();
        }
        
        return true;
        
    } else {
        
        return false;
    }
}

`

This was a known problem in 0.9.0 but it should be fixed in 0.9.1 which we released 2 days ago, can you try if that fixes it?

Many thanks, that has indeed fixed it. Leon