我正在尝试在AVPlayer上播放HEVC(H.265)编解码器媒体URL。但是视频没有显示。我没有任何解决方案。如何在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()
}

最佳答案

按照您的示例,我可以在设备(不是模拟器)上播放此内容

还请注意,我已将URL从HTTP更改为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()
    }

}

注意:

HEVC视频的容器格式必须为fMP4。

有几种方法可以将HEVC内容交付给用户:

HLS中的
  • HEVC使用MPEG-2 Transport Stream块,Apple不这样做
    支持
  • 苹果公司在FLS上使用fMP4段的
  • HEVC
    WWDC17,我们的播放器支持
  • MPEG-DASH中的
  • HEVC,使用fMP4段

  • 以供参考:
    WWDC17 – HEVC with HLS – Apple just announced a feature that we support out of the box

    HLS Authoring Specification for Apple Devices

    10-07 16:37