Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing HEVC(H.265) file using AVPlayer from a remote url

I am trying to play an HEVC(H.265) codec media url on AVPlayer. But the video is not showing. I didn't get any solution. How do I implement this in ios?

let videoURL = URL(string: "http://bitmovin-a.akamaihd.net/content/dataset/multi-codec/hevc/stream_fmp4.m3u8")
let avPlayer = AVPlayer(url: videoURL!)
let playerViewController = AVPlayerViewController() 
playerViewController.player = avPlayer 
self.present(playerViewController, animated: true) { 
    playerViewController.player!.play()
}
like image 208
Lijith Vipin Avatar asked Oct 24 '25 06:10

Lijith Vipin


1 Answers

Following your example I am able to play this content on a device (not simulator)

Pay attention also that I changed the URL from HTTP to HTTPS!

import UIKit
import AVFoundation

class ViewController: UIViewController {

    let videoURL = URL(string: "https://bitmovin-a.akamaihd.net/content/dataset/multi-codec/hevc/stream_fmp4.m3u8")
    let avPlayer = AVPlayer()


    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(_ animated: Bool) {
        let asset = AVAsset(url: videoURL!)
        let playerItem = AVPlayerItem(asset: asset)
        avPlayer.replaceCurrentItem(with: playerItem)

        let avLayer = AVPlayerLayer(player: avPlayer)
        avLayer.frame = view.bounds
        view.layer.addSublayer(avLayer)
        avPlayer.play()
    }

}

NB:

The container format for HEVC video MUST be fMP4.

There are a few ways to deliver HEVC content to users:

  • HEVC in HLS using MPEG-2 Transport Stream chunks, which Apple doesn’t support
  • HEVC in HLS using fMP4 segments, which is what Apple announced on WWDC17 and our player supports
  • HEVC in MPEG-DASH using fMP4 segments

For reference: WWDC17 – HEVC with HLS – Apple just announced a feature that we support out of the box

HLS Authoring Specification for Apple Devices

like image 83
Peter Pajchl Avatar answered Oct 25 '25 19:10

Peter Pajchl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!