Video on Demand (VOD) - Online streaming - Adaptive streaming - Live streaming - Program stream vs Transport stream - Streaming Protocol / Manifest / HLS - DRM
into multiple files (segments) - /video/s0.mp4, /video/s1.mp4, ... - Separate for Audio and Video - /video/s0.mp4, /audio/s0.mp4 - Various durations (2-10 seconds) - Various qualities - /audio/128kbps/segment0.mp4 … - Various languages - audio tracks - /audio/french/128kbps/segment0.mp4 … - Various subtitles - /audio/french/segment0.vtt …
position - Basic static http hosting only needed - Change quality or language on fly - Adaptive streaming - Quick start - No need to download whole media
- /video/720p/segment0.mp4 - /video/1080p/segment0.mp4 - /audio/english/128kbps/segment0.mp4 - /audio/english/256kbps/segment0.mp4 - /audio/french/256kbps/segment0.mp4 - Even worse when audio and video in one file. - Network bandwidth and stability - Complicated download for offline playback
segmented - Freshly created segments are quickly consumed by video players - Delayed compared to TV stream (segment duration + encoding time + request / response + latencies + playhead) - Streaming Protocol / Manifest to help identify existing segments
(M3U) - Describes media - Available video and audio qualities - Segment duration - Languages - Available segments (for live) - Some are codec/encoding agnostic Streaming Protocol / Manifest
Streaming protocol developed by Apple - Launched in summer 2009 (with iPhone 3) - Replaced Quicktime - Manifests/playlists in the M3U8 format (M3U encoded in UTF-8) - Main index (playlist) usually points to other playlists - quality/language specific - Supports closed captions - Codec/Encoding H264/H265 + AAC (more options for audio) - Container MPEG-2 Transport Stream (.ts files)
limit the use of digital content - Inhibits the non desired use of content - Prevents copying, converting, redistributing - Hardware accelerated - HLS -> AES encryption - A layer of security (not Hollywood grade) - AES-128 (all segments same key) - SAMPLE-AES (each segment by its own AES) - FairPlay - Developed by Apple in and used in iTunes initially - Regular MP4 container with encrypted AAC audio layer (by AES)
layer and define it as AVPlayerLayer • Use your own layer animation for resizing if you need special effects • Check if player.currentItem?.status == AVPlayerItem.Status.readyToPlay ◦ Now you can use player.seek() to resume playback • Unhappy with black screen and spinner? ◦ Use your own stalled playback detection ▪ player.rate > 0 ▪ videoTrack.currentVideoFrameRate > 5 ▪ playerLayer.isReadyForDisplay - check during the playback progress ◦ Use playback recovery techniques ▪ player.pause() and player.resume() ▪ player.replaceCurrentItem(with: nil) and player.replaceCurrentItem(with: playerItem)
configuration = URLSessionConfiguration.background(withIdentifier: urlBackgroundIdentifier) configuration.isDiscretionary = false (consider carefully if you set to true - recommended by Apple configuration.sessionSendsLaunchEvents = true configuration.shouldUseExtendedBackgroundIdleMode = true downloadQueue.qualityOfService = .userInteractive (not on battery, use .utility - recommended by Apple) sessionManager = URLSession(configuration: configuration, delegate: self, delegateQueue: downloadQueue)
- download assets (media selection options) programmatically func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didResolve resolvedMediaSelection: AVMediaSelection) { // save resolvedMediaSelection somewhere } • AVURLAsset ◦ holds asset cache AVAssetCache • AVAssetCache ◦ check which assets have been loaded and load the remaining • AVMediaCharacteristic.audible, AVMediaCharacteristic.legible • AVMediaSelectionGroup ◦ list of media selection options [AVMediaSelectionOption] • AVMediaSelectionOption ◦ check if this selection option is in cache, if not downlaod it