View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Videos

Abrir menú Cerrar menú
  • Colecciones
  • Todos los videos
  • Información

Más videos

  • Información
  • Código
  • Display HDR video in EDR with AVFoundation and Metal

    Learn how you can take advantage of AVFoundation and Metal to build an efficient EDR pipeline. Follow along as we demonstrate how you can use AVPlayer to display HDR video as EDR, add playback into an app view, render it with Metal, and use Core Image or custom Metal shaders to add video effects such as keying or color management. Whether you develop games or pro apps, we'll help you decide which frameworks to use and share best practices for selecting transports, colorspaces, and pixelbuffer formats.

    Recursos

    • Learn more about AVFoundation
      • Video HD
      • Video SD

    Videos relacionados

    WWDC23

    • Support HDR images in your app

    Tech Talks

    • Discover Reference Mode

    WWDC22

    • Display EDR content with Core Image, Metal, and SwiftUI
    • Explore EDR on iOS

    WWDC21

    • Explore HDR rendering with EDR

    WWDC20

    • Edit and play back HDR video with AVFoundation
    • Optimize the Core Image pipeline for your video app
  • Buscar este video…
    • 6:58 - Playing media using AVPlayerViewController

      // Playing media using AVPlayerViewController
      let player = AVPlayer(URL: videoURL)
      
      // Creating a player view controller
      var playerViewController = AVPlayerViewController()
      
      playerViewController.player = player
      
      self.presentViewController(playerViewController, animated: true) {
         playerViewController.player!.play()
      }
    • 7:38 - Playing media using AVPlayer and AVPlayerLayer

      // Playing media using AVPlayer and AVPlayerLayer
      let player = AVPlayer(URL: videoURL)
      
      var playerLayer = AVPlayerLayer(player: player)
      
      playerLayer.frame = self.view.bounds
      
      self.view.layer.addSublayer(playerLayer)
      
      player.play()
    • 9:28 - CAMetalLayer Properties

      // Opt into using EDR
      let layer: CAMetalLayer
      layer.wantsExtendedDynamicRangeContent = true
      
      // Use half-float pixel format
      layer.pixelFormat = MTLPixelFormatRGBA16Float
      
      // Use extended linear display P3 color space
      layer.colorspace = kCGColorSpaceExtendedLinearDisplayP3
    • 11:33 - Create an AVPlayerItemVideoOutput

      let videoColorProperties = [
          AVVideoColorPrimariesKey: AVVideoColorPrimaries_P3_D65,
          AVVideoTransferFunctionKey: AVVideoTransferFunction_Linear,
          AVVideoYCbCrMatrixKey: AVVideoYCbCrMatrix_ITU_R_2020
      ]
      
      let outputVideoSettings = [
          AVVideoAllowWideColorKey: true,
          AVVideoColorPropertiesKey: videoColorProperties,
          kCVPixelBufferPixelFormatTypeKey as String: NSNumber(value: kCVPixelFormatType_64RGBAHalf)
      ] as [String : Any]
         
      // Create a player item video output
      let videoPlayerItemOutput 
      = AVPlayerItemVideoOutput(outputSettings: outputVideoSettings)
    • 13:02 - Create a display link

      // Create a display link
      lazy var displayLink: CADisplayLink 
      = CADisplayLink(target: self, 
                      selector: #selector(displayLinkCopyPixelBuffers(link:)))
      
      var statusObserver: NSKeyValueObservation?
      
      statusObserver = videoPlayerItem.observe(\.status,
            options: [.new, .old],
            changeHandler: { playerItem, change in
              if playerItem.status == .readyToPlay {
                playerItem.add(videoPlayerItemOutput)
                displayLink.add(to: .main, forMode: .common)
                videoPlayer?.play()
              }
           })
      }
    • 14:16 - Run DisplayLink to get pixel buffers

      @objc func displayLinkCopyPixelBuffers(link: CADisplayLink) 
      {
        let currentTime = videoPlayerItemOutput.itemTime(forHostTime: CACurrentMediaTime())
      	
        if videoPlayerItemOutput.hasNewPixelBuffer(forItemTime: currentTime)
        {
            if let buffer 
            = videoPlayerItemOutput.copyPixelBuffer(forItemTime: currentTime, 
      	                                          itemTimeForDisplay: nil) 
      	  {
              let image = CIImage(cvPixelBuffer: buffer!)
      
              let filter = CIFilter.sepiaTone()
              filter.inputImage = image
              output = filter.outputImage ?? CIImage.empty()
          
              // use context to render to you CIRenderDestination
           }
       }
      }
    • 15:53 - Integrate Core Image

      @objc func displayLinkCopyPixelBuffers(link: CADisplayLink) 
      {
        let currentTime = videoPlayerItemOutput.itemTime(forHostTime: CACurrentMediaTime())
      	
        if videoPlayerItemOutput.hasNewPixelBuffer(forItemTime: currentTime)
        {
            if let buffer 
            = videoPlayerItemOutput.copyPixelBuffer(forItemTime: currentTime, 
      	                                          itemTimeForDisplay: nil) 
      	  {
              let image = CIImage(cvPixelBuffer: buffer)
      
              let filter = CIFilter.sepiaTone()
              filter.inputImage = image
              output = filter.outputImage ?? CIImage.empty()
          
              // use context to render to your CIRenderDestination
           }
        }
      }
    • 19:13 - Using CVMetalTextureCache

      // Create a CVMetalTextureCacheRef
      
      let mtlDevice = MTLCreateSystemDefaultDevice()
      
      var mtlTextureCache: CVMetalTextureCache? = nil
      
      CVMetalTextureCacheCreate(allocator: kCFAllocatorDefault, 
                                cacheAttributes: nil, 
                                metalDevice: mtlDevice, 
                                textureAttributes: nil, 
                                cacheOut: &mtlTextureCache)
      
      // Create a CVMetalTextureRef using metalTextureCache and our pixelBuffer
      let width  = CVPixelBufferGetWidth(pixelBuffer)
      let height = CVPixelBufferGetHeight(pixelBuffer)
      
      var cvTexture : CVMetalTexture? = nil
      
      CVMetalTextureCacheCreateTextureFromImage(allocator: kCFAllocatorDefault, 
                                                textureCache: mtlTextureCache, 
                                                sourceImage: pixelBuffer, 
                                                textureAttributes: nil, 
                                                pixelFormat: MTLPixelFormatRGBA16Float, 
                                                width: width, 
                                                height: height, 
                                                planeIndex: 0, 
                                                textureOut: &cvTexture)
      
      let texture = CVMetalTextureGetTexture(cvTexture)
      
      // In Obj-C, release CVMetalTextureRef in Metal command buffer completion handlers

Developer Footer

  • Videos
  • WWDC22
  • Display HDR video in EDR with AVFoundation and Metal
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines