Some of my favourite bits of AVFoundation. Topics include capture, composition, a custom player and scrubber interface, synchronized CAAnimations, and real-time VFX.
3. AVFoundation
• Mid-level Objective-C framework for playing,
recording and editing time-based media
• Available on iOS 4.0+ and Mac OS X 10.7+
AV Foundation
Core Audio Core Media Core Animation
Media Player
UIKit
5. A Brief History
iOS AVFoundation Features
2.2 AVAudioPlayer
3.0 AVAudioRecorder,AVAudioSession
4.0 Capture, playback and editing
4.1 Read/write sample buffers, queue player
5.0 OpenGLES compatibility,AirPlay
6. New in iOS 6.0
• Real-time access to video buffers
• Face tracking during capture
• Better support for encrypted streams
• Advanced synchronization features
7. AVAsset (abstract base class)
• AVURLAsset: local or remote
• AVComposition
• AVMutableComposition
AVAsset
AVAssetTrack
AVAssetTrackSegment
audio
video
8. @protocol AVAsynchronousKeyValueLoading
• Handler invoked on arbitrary thread;
dispatch_async to main queue
- (void)loadValuesAsynchronouslyForKeys:(NSArray *)keys
completionHandler:(void (^)())handler;
- (AVKeyValueStatus)statusOfValueForKey:(NSString *)key
error:(NSError **)outError;
10. CMTime
• C struct representing rational number
• numerator: value, denominator: scale
• time in seconds = value / scale
• Flags: valid, +/-ve infinity, has been rounded
• Time scale of 600 can conveniently
represents 24, 25 and 30 fps exactly
24. AVSynchronizedLayer
• Confers timing state upon sublayers
• Timing synced with AVPlayerItem instance
• +synchronizedLayerWithPlayerItem:
• When creating CAAnimations:
• Use AVCoreAnimationBeginTimeAtZero
• -setRemovedOnCompletion:NO
30. AVPlayerItemVideoDataOutput
• Access pixel buffers during playback
• Request wakeup, poll w/ display link
running pausedCADisplayLink
request change
notification
media data
will change
buffer for
time?
NO
YES
process &
display
entry
point