0 Replies
      Latest reply on Mar 14, 2020 12:04 PM by Aquilosion
      Aquilosion Level 1 Level 1 (0 points)

        I have some large MP4 files hosted on an HTTP server on my LAN. I'm trying to stream them to a tvOS app using AVPlayer. The Apple TV has a gigabit connection to the server, and I've confirmed that it can download regular files from it at a speed of at least 600 Mbit.


        Streaming videos encoded at up to around 20 Mbit works no problem: there's no lag, seeking is practically instant and the thumbnail preview appears when doing so, etc.


        Unfortunately, trying to stream 4K HEVC-encoded files at around 50 Mbit is a different story: after a few seconds of playing without any hiccups, it usually completely freezes and struggles to resume after any scene with even mild complexity.


        I know that videos played from an HTTP URL in AVFoundation load chunks as necessary rather than downloading the full file once, so I expected some overhead from that, but after analysing the server logs it seems to only be fetching at most a few megabytes at a time, with many requests being even smaller. In any case, it seems to on average perform several requests a second, which I guess is bottlenecking somewhere.


        If I re-encode the videos on the server to generate HLS playlists with fragmented MP4s, they play without a problem, I guess because this actually does force it to download larger chunks less often, though I'm really looking for a solution using regular MP4 files.


        My question is:

        • Is it possible to force AVFoundation to load large MP4s more efficiently, by e.g. asking it to load larger chunks less frequently?
        • If that's not possible, is it possible to prepare the MP4s more efficiently somehow which would let it work? (I tried creating fragmented MP4s by themselves without the m3u8 playlist, but AVFoundation didn't seem to like to play them.)


        There are definitely other apps out there which can stream large MP4s in realtime from the LAN, though I think most of them don't use AVPlayer, which is a requirement for me. Is it possible that AVFoundation is just known to be inefficient in this regard, and I'm expected to just use HLS?