ofAVFoundationPlayer — ofVideoPlayer - ideas?

I’m now taking a look on ofAVFoundationPlayer just to learn a little bit more about ofVideoPlayer internals.

I’ve noticed two of the things that happens the first time a video is loaded are

ofAVFoundationVideoPlayer alloc

And they are not called anymore when I load the same video the second time, or a different video in the same ofVideoPlayer object.
Question: any of this objects should be recreated in the case I load some video with different pixel dimensions from the first video?


Other thing I’ve noticed is initTextureCache() is being called every frame, so maybe we could avoid allocating a new texture every frame with the following:

    if (!videoTexture.isAllocated()) {
        int videoTextureW = getWidth();
        int videoTextureH = getHeight();
        videoTexture.allocate(videoTextureW, videoTextureH, GL_RGBA);

but probably had to ofTexture::clear after loading a different video. or better yet, after detecting we loaded a different video with different dimensions.

I’ve made a quick test of a program that can load two different videos in the same videoplayer instance, like this

#include "ofApp.h"

void ofApp::setup(){

void ofApp::update(){

void ofApp::draw(){

void ofApp::keyPressed(int key) {
	// ofLog("xaza");
    if (key == 'q') {
    if (key == 'w') {

And I think each load is spawning a new thread, and new ones when video loops and get back to start position. with a quick test of a few minutes I could see more than 100 threads

wow. do you think that it is AVFoundation that does that or that its implementation within OF is wrong?

My guess is there is something specific to OF.
Maybe related, title is maybe misleading:

Trying to look at
dispatch_async and dispatch_queue_t used inside ofAVFoundationVideoPlayer.m
both for load and loadAsync

1 Like