I'm trying to differentiate between AVAssets that have variable frame rates and those that don't.
I'm aware I can decode every frame and check that the frame duration doesn't change each frame but this is costly, I've had a look at the metadata available and haven't found anything useful.
Does anyone know where to start? best idea i've got so far is to use:
CMTime duration = [myAsset duration];
CMTime frameDuration = myAssetTrack.minFrameDuration;
if(!(duration.value * frameDuration.timescale) %
(duration.timescale * frameDuration.value))
NSLog(@"asset is constant frame rate");
but this is ultimately susceptible to false negatives. are there any better approaches?
(aside, for anyone looking at the above, this is also succeptible to false positives as AVAssets seem to add a black frame to the end of a video and give it a timestamp that can vary, to correctly use this you should decode the second to last frame and use it's presentation time stamp - this code is simpler)
First of all, unless you created them yourself, I think it's safest to assume that all video files have variable frame rates.
Second, is it really too costly reading every frame? If you create an AVAssetReader + AVAssetReaderTrackOutput with nil output settings, reading frames should* not actually cause decompression, but result in a light parse of the file, giving CMSampleBuffers whose presentation timestamps you can examine to determine frame rate constancy.
*I hope, I haven't verified this lately, but a long time ago I was looking at ways of indexing movie files and this way seemed to be blazingly fast.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With