Search code examples
iosavplayerh.264http-live-streaminghevc

Can't play HEVC with VideoPlayer on iOS 14 (emulator and device)


I'm making an app which will play live video from TV channels. Some channels are in HEVC format and some in h.264. H.264 plays just fine, but HEVC won't. I tried both on real device (iPhone 6s and iPhone 8 with iOS 14) and on emulator (iPhone 8, 11, 12 with iOS 14). I read on the internet, that only iPhones 7 and up support HEVC, so it's no surprise, that it doesn't work on iphone 6s.
Live stream is provided with HLS over HTTPS. HEVC and h.264 plays in VLC (Media -> Open Network Stream) so it shouldn't be an issue with stream.
Since I can't provide url of stream (internal use only), I will provide screenshot from VLC.
This is what url looks like: https://domain.example.com/api/stream/some_token/10
And after connection is established it redirects to: http://1xx.xx.xx.xx:85/stream/some_token/stream.m3u8
I allowed HTTP in Info.plist (https://stackoverflow.com/a/32817873/4798218)

Working h.264 stream codec info

Working H.264 Codec info

Working H.264 statistics

Not working HEVC stream codec info

Not working HEVC Codec info Not working HEVC statistics

Now the code with which I'm trying to make it work. I tried it in AVPlayerVideoController and also with VideoPlayer (from AVKit, ios14+) and none play HEVC.

import SwiftUI
import AVKit

struct SUIVideoPlayer: View {
    private let player = AVPlayer(url: URL(string: "https://domain.example.com/api/stream/some_token/10")!)
    
    var body: some View {
        VideoPlayer(player: player)
            .onAppear() {
                player.play()
            }
            .onDisappear() {
                player.pause()
            }
    }

}

I'm not getting any errors when trying to play HEVC or h.264 stream. One works, other one does not.


Solution

  • Found the answer. TS files are not and will not be supported on iOS. You must use fMP4. Official response from apple in their forums: https://developer.apple.com/forums/thread/132291