Advances in AVFoundation Playback - Apple Inc. · Session 503 Advances in AVFoundation Playback Sam Bushell Media Systems Architect. AVFoundation. File Playback Editing Video Capture
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Automatic waiting for bufferingSimple way to loop playback
Overview
Automatic waiting for bufferingSimple way to loop playbackPlayback refinements
Overview
Automatic waiting for bufferingSimple way to loop playbackPlayback refinementsWide color
Overview
Automatic waiting for bufferingSimple way to loop playbackPlayback refinementsWide colorBest practices for being awesome
BufferingPlease wait...
6
Media Playback Over the Internet
Playback is at the mercy of the network!• Start too soon → playback may stall
• Start too late → user unhappy
• Start when likely to keep up → just right
ExistingAVPlayerItem Buffering State Properties
playbackLikelyToKeepUp
playbackBufferFull
playbackBufferEmpty
For progressive-download playback, in iOS 9• Wait until playbackLikelyToKeepUp or playbackBufferFull before setting AVPlayer.rate
For HLS, rules are simpler• Set AVPlayer.rate and it will automatically wait for buffering before playback begins
AVPlayer in iOS 10 / macOS Sierra / tvOS 10
Same rules for progressive and HLS• Set AVPlayer.rate when user clicks play• Automatically waits to buffer to avoid stalling
If network drops and playback stalls, playback will automatically resume when buffered
NEW
App A
AVFoundation
AVKit MediaPlayer (deprecated)
AVFoundation AVFoundation
App B
App C
Autoplay or Autowait?
automaticallyWaitsToMinimizeStalling
waitingpaused playing
waitingpaused playingplay()
waitingpaused playingplay() likelyToKeepUp
waitingpaused playingplay() likelyToKeepUp
bufferEmpty
waitingpaused playingplay() likelyToKeepUp
pause()
bufferEmpty
waitingpaused playingplay() likelyToKeepUp
pause()
pause()
bufferEmpty
waitingpaused playing
playImmediately(atRate:)
play() likelyToKeepUp
pause()
pause()
bufferEmpty
playImmediately(atRate:)
Might not mean what you thought it meantAVPlayer.rate
Might not mean what you thought it meantAVPlayer.rate
AVPlayer.rate the app's requested playback rate
Might not mean what you thought it meantAVPlayer.rate
AVPlayer.rate the app's requested playback rate
AVPlayerItem.timebase.rate the rate at which playback is actually occurring
Might not mean what you thought it meantAVPlayer.rate
AVPlayer.rate the app's requested playback rate
AVPlayerItem.timebase.rate the rate at which playback is actually occurring
AVPlayer.timeControlStatus Paused, WaitingToPlayAtSpecifiedRate, Playing
NEW
Might not mean what you thought it meantAVPlayer.rate
AVPlayer.rate the app's requested playback rate
AVPlayerItem.timebase.rate the rate at which playback is actually occurring
AVPlayer.timeControlStatus Paused, WaitingToPlayAtSpecifiedRate, Playing
AVPlayer.reasonForWaitingToPlay
NEW
NEW
Might not mean what you thought it meantAVPlayer.rate
AVPlayer.rate the app's requested playback rate
AVPlayerItem.timebase.rate the rate at which playback is actually occurring
AVPlayer.timeControlStatus Paused, WaitingToPlayAtSpecifiedRate, Playing
AVPlayer.reasonForWaitingToPlay
waiting
NEW
NEW
Might not mean what you thought it meantAVPlayer.rate
AVPlayer.rate the app's requested playback rate
AVPlayerItem.timebase.rate the rate at which playback is actually occurring
AVPlayer.timeControlStatus Paused, WaitingToPlayAtSpecifiedRate, Playing
AVPlayer.reasonForWaitingToPlay
waiting
1.0
NEW
NEW
Might not mean what you thought it meantAVPlayer.rate
AVPlayer.rate the app's requested playback rate
AVPlayerItem.timebase.rate the rate at which playback is actually occurring
AVPlayer.timeControlStatus Paused, WaitingToPlayAtSpecifiedRate, Playing
AVPlayer.reasonForWaitingToPlay
waiting
1.0
0.0
NEW
NEW
Might not mean what you thought it meantAVPlayer.rate
AVPlayer.rate the app's requested playback rate
AVPlayerItem.timebase.rate the rate at which playback is actually occurring
AVPlayer.timeControlStatus Paused, WaitingToPlayAtSpecifiedRate, Playing
AVPlayer.reasonForWaitingToPlay
waiting
1.0
0.0
WaitingToPlayAtSpecifiedRateNEW
NEW
Might not mean what you thought it meantAVPlayer.rate
AVPlayer.rate the app's requested playback rate
AVPlayerItem.timebase.rate the rate at which playback is actually occurring
AVPlayer.timeControlStatus Paused, WaitingToPlayAtSpecifiedRate, Playing
AVPlayer.reasonForWaitingToPlay
waiting
1.0
0.0
WaitingToPlayAtSpecifiedRate
WaitingToMinimizeStallsReason
NEW
NEW
DemoAutowait
Moritz Wittenhagen
rate vs timeControlStatus
AVPlayer.rate AVPlayer.timeControlStatus
0.0
1.0
1.0
waiting
paused
playing
Finding the Network Link Conditioner
Finding the Network Link Conditioner
Cautions
Cautions
Enabled automatically if app linked on or after iOS 10, OSX 10.12, tvOS 10• AVPlayer.automaticallyWaitsToMinimizeStalling = true
Cautions
Enabled automatically if app linked on or after iOS 10, OSX 10.12, tvOS 10• AVPlayer.automaticallyWaitsToMinimizeStalling = true
Opt out if using setRate(..., time:..., atHostTime:...) to synchronize playback with external timeline• AVPlayer.automaticallyWaitsToMinimizeStalling = false
• Otherwise, NSException
Cautions
Enabled automatically if app linked on or after iOS 10, OSX 10.12, tvOS 10• AVPlayer.automaticallyWaitsToMinimizeStalling = true
Opt out if using setRate(..., time:..., atHostTime:...) to synchronize playback with external timeline• AVPlayer.automaticallyWaitsToMinimizeStalling = false
• Otherwise, NSException
Never use the player rate to project currentTime into the future• Use currentItem's timebase rate for that instead
Made easierLooping
When end reached, rewind?How Do You Loop an AVPlayerItem?
AVPlayer
AVPlayerItem
When end reached, rewind?How Do You Loop an AVPlayerItem?
AVPlayer
- AVPlayerItem
When end reached, rewind?How Do You Loop an AVPlayerItem?
AVPlayerItemAVPlayerItem AVPlayerItem
Latency Preroll
When end reached, rewind?How Do You Loop an AVPlayerItem?
AVPlayerItem
AVPlayerItem
AVPlayerItem
Preroll
AVQueuePlayer
AVPlayerItem
AVQueuePlayer
AVPlayerItem AVPlayerItem
AVQueuePlayer
AVPlayerItem
AVQueuePlayer
AVPlayerItem AVPlayerItem
AVAsset
AVPlayerItem
The "Treadmill"
AVQueuePlayer
AVPlayerItem AVPlayerItem
AVPlayerItem
The "Treadmill"
AVQueuePlayer
AVPlayerItem AVPlayerItem
AVPlayerItem
The "Treadmill"
AVPlayerItem
AVQueuePlayer
AVPlayerItem AVPlayerItem
AVPlayerItem
The "Treadmill"
AVPlayerItem
AVQueuePlayer
AVPlayerItem AVPlayerItem
AVPlayerItem
The "Treadmill"
AVPlayerItem
AVQueuePlayer
AVPlayerItem AVPlayerItem AVPlayerItem
// Looping using AVQueuePlayer
override func observeValue(forKeyPath keyPath: String?, of object: AnyObject?, change:
Make sure audio and video tracks are same lengthOptimizing Movies for Looping
Video
Audio
Make sure audio and video tracks are same lengthOptimizing Movies for Looping
Video
Audio
Video
Audio
Video
Audio
Make sure audio and video tracks are same lengthOptimizing Movies for Looping
Video
Audio
Video
Audio
Video
Audio
Make sure audio and video tracks are same lengthOptimizing Movies for Looping
Video
Audio
Video
Audio
Video
Audio
Under the hoodPlayback Refinements
When Tracks Come and Go During Playback
Video
English Audio
English Subtitles
French Audio
Spanish Subtitles
When Tracks Come and Go During Playback
Video
English Audio
English Subtitles
French Audio
Spanish Subtitles
Where once there were glitches Some More Smoothness
• Adding / Removing the only AVPlayerLayer on playing AVPlayer• Changing subtitle language on playing AVPlayer• Changing audio language on playing AVPlayer• Manually disabling / enabling tracks on playing AVPlayer
Preparing for Wide Color Video
Color Space Tagging in Media Files
Color space information is part of the metadata of video tracks
Standard tag numbers defined in ISO/IEC 23001-8, "Coding Independent Code Points"
automaticallyWaitsToMinimizeStallingAVPlayerLooperEnabling and disabling tracks during playback is smoother
Summary
automaticallyWaitsToMinimizeStallingAVPlayerLooperEnabling and disabling tracks during playback is smootherPrepare for wide color video
Summary
automaticallyWaitsToMinimizeStallingAVPlayerLooperEnabling and disabling tracks during playback is smootherPrepare for wide color videoOptimize playback startup through cunning and measurement