Incorrect duration calculation for streams of content type 'video/mp4'
When playing a stream of type 'video/mp4' such as:
https://r9---sn-q0c7dn7k.googlevideo.com/videoplayback?mm=31&mn=sn-q0c7dn7k&ratebypass=yes&mime=video%2Fmp4&requiressl=yes&source=youtube&pl=30&dur=223.352&expire=1487871460&mt=1487849660&mv=m&ms=au&signature=171211C53D5F2CA1EBB0430F64379B15582E9F3D.4EFAFAB7E91C2B16A26E602F203B5B1E8431A63E&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&ipbits=0&ip=2a02%3A8084%3A601d%3A600%3A885b%3Aaa1a%3Acac3%3Adbd0&beids=%5B9452307%5D&lmt=1386698118372978&key=yt6&itag=18&initcwndbps=1418750&id=o-AHqLawtMlTa3CkrRtOpjewuzQ4zvhWyNCSjiXYF-5mB3&upn=WdXrxjNguNc
It reports the duration as being 12:26 (when converted from seconds to minutes) when in actuality the video is 3:43 minutes in length.
I presume this is due to the larger data size coming back in the headers (due to it being mixed content of audio & video) and how the length is calculated in calculatedBitRate (i.e averagePacketByteSize / packetDuration * 8) or the duration method (i.e audioDataLengthInBytes / (calculatedBitRate / 8))
I don't expect @tumtumtum to chip in as he doesn't seem to be maintaining this project any more but has anyone else run into this issue or has any notions on how to fix?
Its breaking scrubbing (seeking) and obviously misreporting the duration to the UI when displaying.
Hi @patrickjquinn Is this still an open issue?
I’ve managed to hack this to work by setting the duration to dur / 2 at a framework level but yeah, for certain content types like MP4 you need to basically half the value due to the inclusion of more than just audio in the streams payload.
I see. I'll try to look into that. Thanks for the update @patrickjquinn
Hey, I've been looking at this one and it seems to be a bug in CoreAudio, it's around the AudioDataByteCount not being interpreted for movie files on the callback for AudioFileStreamPropertyListenerProc. Running this with Xcode 11 resolves the issue! I do have a fix for local files at the moment (although probably not needed for > iOS 12), I'll make a PR when I get some free time