Recommendations for 2K video files

Hey folks –

My current project has approximately 8 1920 x 2160 video files that are played one at a time in succession. I ran into some playback issues using ofQTKitplayer – which have already been documented on the forums and on github – and decided to switch to the ofxAVFVideoPlayer (the Clouds version).

What I’ve discovered is that if I load all of the videos on launch, I’ll start to receive memory allocation errors during the playback of the 3rd video.

If I take a different approach and load one video at a time using multiple instances of ofxAVFVideoPlayer, the app seems to run for a much longer time but crashes after about 7 hours – when loading the the next video.

My code looks a 'lil something like this

videos[index]->close();
videos[index]->loadMovie( "moviePath.mov");
videos[index]->play();

Memory seems to increase over the duration of playback – up to around 2 GB (the files are about 200 MB each). Looking at the Leaks application, I can’t find anything that’s particularly suspect.

Here’s the crash log (for the second approach)

2014-09-19 02:45:35.662 MediaLiteracyDebug[6447:2c15b] An uncaught exception was raised
2014-09-19 02:45:35.662 MediaLiteracyDebug[6447:2c15b] *** -[NSConcreteMutableData appendBytes:length:]: unable to allocate memory for length (50397184)
2014-09-19 02:45:35.663 MediaLiteracyDebug[6447:2c15b] (
	0   CoreFoundation                      0x90cb2471 __raiseError + 193
	1   libobjc.A.dylib                     0x90690091 objc_exception_throw + 162
	2   CoreFoundation                      0x90cb238b +[NSException raise:format:] + 139
	3   Foundation                          0x9ba660cc _NSMutableDataGrowBytes + 1149
	4   Foundation                          0x9ba5ca9b -[NSConcreteMutableData appendBytes:length:] + 372
	5   MediaLiteracyDebug                  0x00082442 __28-[AVFVideoRenderer loadURL:]_block_invoke_3 + 674
	6   AVFoundation                        0x945e4c2e -[AVPlayerPeriodicCaller _effectiveRateChanged] + 412
	7   AVFoundation                        0x945e73b0 __avplayer_timebaseNotificationCallback_block_invoke + 148
	8   libdispatch.dylib                   0x96e4d76b _dispatch_call_block_and_release + 15
	9   libdispatch.dylib                   0x96e4caf3 _dispatch_queue_drain + 410
	10  libdispatch.dylib                   0x96e4dfcf _dispatch_queue_invoke + 126
	11  libdispatch.dylib                   0x96e4c38a _dispatch_root_queue_drain + 72
	12  libdispatch.dylib                   0x96e4d70e _dispatch_worker_thread2 + 39
	13  libsystem_pthread.dylib             0x9b5f3dab _pthread_wqthread + 336
	14  libsystem_pthread.dylib             0x9b5f7cce start_wqthread + 30
)
2014-09-19 02:45:35.664 MediaLiteracyDebug[6447:2c15b] *** Terminating app due to uncaught exception 'NSMallocException', reason: '*** -[NSConcreteMutableData appendBytes:length:]: unable to allocate memory for length (50397184)'
*** Call stack at first throw:
(
	0   CoreFoundation                      0x90cb2471 __raiseError + 193
	1   libobjc.A.dylib                     0x90690091 objc_exception_throw + 162
	2   CoreFoundation                      0x90cb238b +[NSException raise:format:] + 139
	3   Foundation                          0x9ba660cc _NSMutableDataGrowBytes + 1149
	4   Foundation                          0x9ba5ca9b -[NSConcreteMutableData appendBytes:length:] + 372
	5   MediaLiteracyDebug                  0x00082442 __28-[AVFVideoRenderer loadURL:]_block_invoke_3 + 674
	6   AVFoundation                        0x945e4c2e -[AVPlayerPeriodicCaller _effectiveRateChanged] + 412
	7   AVFoundation                        0x945e73b0 __avplayer_timebaseNotificationCallback_block_invoke + 148
	8   libdispatch.dylib                   0x96e4d76b _dispatch_call_block_and_release + 15
	9   libdispatch.dylib                   0x96e4caf3 _dispatch_queue_drain + 410
	10  libdispatch.dylib                   0x96e4dfcf _dispatch_queue_invoke + 126
	11  libdispatch.dylib                   0x96e4c38a _dispatch_root_queue_drain + 72
	12  libdispatch.dylib                   0x96e4d70e _dispatch_worker_thread2 + 39
	13  libsystem_pthread.dylib             0x9b5f3dab _pthread_wqthread + 336
	14  libsystem_pthread.dylib             0x9b5f7cce start_wqthread + 30

I’ve also tried using a single video player, but the player also crashes after around 5 hours of playback – usually when calling videoPlayer.close();

If anybody has any recommendations for other approaches to take with this media player, I’d be super grateful.

Thx++

Jeremy

(All this is on OS 10.9 and OF 0.8)

Hi Jeremy,

How much RAM/GPU memory do you have ? Is there a way to run your application in 64 bit ?

To debug this type of problem, I created a test app that loads/plays/stops/loads/… videos every couple of second and I watch both RAM and GPU memory. If it keeps increasing over time it’s no bueno.

And what about using only one instance of the video player and doing something lik player->loadMovie(videos[index]); ?

(Note: all my coding is done on windows, so things might be different in the mac world :frowning: )

I have no experience with the AVFplayer, but I’ve run into the memory leaks in the regular QT player a while back.

It seemed to me that the leak only happened once per player instance, so I was able to get around it by using only one player instance, and closing, loading and playing each time with a different file name. This was problematic because I would experience a hiccup when opening the new video each time, not as seamless as I wanted.

The work around is to use two players, one being the live player, and another being the staging player that can be prepared while the live player is already playing, even in a separate thread (though you have to manage the textures manually).

Not sure this applies to the newer AVF player, but the situation sounds similar so I hope this helps.

I have been testing the ofxHapPlayer addon to use the hap codec in an upcoming installation, and replacing the source file in one instance player seems to have no problems in terms of memory and a really fast load time (switch are almost instantaneous).

Iv been trying with 8 fullHD clips, randomly changing for a couple of hours. For sure you will need an SSD disk to use this codec. It’s an extension of the qt regular video player, as the hap codec is decoded on the video card.

As the videos are never played at the same time can you make them all into a single file and then just jump to positions when you need the next part of the file (what would have been another file entirely)?

Wow, thanks for the slew of recommendations!

The project is working a lot better on a Mac Pro tower than it was on a Mac Mini. The extra RAM seems to be making that critical difference – it ran for 72 hours straight before audio sync problems started showing up. The plan was always to restart the applications every 24, so this is great.

@silverbahamut if I run into problems down the road, 64-bit seems like a great option. Thanks for the tip.

@TimS the time between file completion and clip loading isn’t an issue here, which is why I took the single AVFPlayer instance route. My only concern is that I’ve seen a file fail to load at times. So I need to watch out for failed load attempts in my code.

@fresla, the films are coming from a CMS, so I can’t make them into a single file.

Again, really appreciate the input.

Jeremy