ofVideoPlayer loadMovie causes bad access


I’m trying to play video in a new thread but I get bad alloc. Video file exists, I checked file path.

This is my threaded function:

void ThreadedVideoPlayer::threadedFunction()
ofVideoPlayer p;
p.loadMovie(URL); // here I get bad access



Any ideas?

the videoplayer uses a texture internally and since openGL cannot be run in another thread it’ll crash, you need to disable the texture first using p.setUseTexture(false)

1 Like

Thank you for the help. This works. How can I draw the video if I don’t have textures? Is that possible?

Thanks again

It is possible. The video player cannot use a texture (GPU memory) outside of the main thread, but it does have access to the pixel information of the decoded video in CPU memory. This is stored in an ofPixels object.

so in your main thread all you need to do is allocate an ofTexture, and upload the video player’s pixels to it, then draw the texture.




updating the texture should be as simple as

1 Like

Great! thanks. That works!

Hello, I am new here, I did exactly what you said but all i get is an white empty image and the sound from the video playing in back. (I draw the texture not in the thread because I get exception but in testApp::draw()). Have I understood it wrong?

It is hard to say exactly what is going wrong without seeing your code. Can you share the code where you are updating the texture and drawing it?

In my Video Thread.cpp I have:

void MyThread::startVideo(){
vid.loadMovie(“Video/Pokemon Battle.mp4”);

void MyThread::updateVideo(){
unsigned char * pixels = vid.getPixels();
if(pixels != NULL){
drawTexture.loadData(pixels, 600, 400, ofGetGLTypeFromPixelFormat(vid.getPixelFormat()));

void MyThread::drawVideo(){
ofSetColor(255, 255, 255, 255);
drawTexture.draw(5, 5, 600, 400);

void MyThread::threadedFunction() {
while (isThreadRunning()){

in testApp.cpp I call in Setup() the startVideo() and after startThread() & in draw() I call the drawVideo()

You can’t use a texture within your thread class like this. You’ll want to allocate the texture in testApp:setup. In testApp::draw, this is where you should do drawTexture.loadData() and drawTexture.draw(). Any operations that require accessing the graphics card (allocating, update or drawing textures) should be done in the main thread.