Top Banner
Renaissance 2014: Master Video @bobmccune Bob McCune
36

Master Video with AV Foundation

Jan 13, 2015

Download

Technology

Bob McCune

Slides for my Master Video session at Renaissance 2014. This session provided a high-level overview of some of AV Foundation's video playback and editing capabilities.

The demo app for this talk can be found at:
https://github.com/tapharmonic/AVFoundationEditor
Welcome message from author
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.
Transcript
Page 1: Master Video with AV Foundation

Renaissance 2014:Master Video

@bobmccuneBob McCune

Page 2: Master Video with AV Foundation

Anything look different?Vatican Square

Page 3: Master Video with AV Foundation

Anything look different?Vatican Square

Page 4: Master Video with AV Foundation

Anything look different?Vatican Square

Page 5: Master Video with AV Foundation

Anything look different?Vatican Square

Page 6: Master Video with AV Foundation
Page 7: Master Video with AV Foundation

OverviewAV Foundation

‣ Objective-C framework for advanced media processing‣ High performance, asynchronous processing‣ Hardware accelerated handling of AV media

‣ Available in its current form since iOS 4‣ Significant additions and enhancements iOS 6 and 7

‣ Apple’s focus for media apps on both iOS and Mac

Page 8: Master Video with AV Foundation

An Embarrassment of RichesiOS Media Environment

AV  Founda6on

UIKit MediaPlayerAssetsLibrary

CoreAudio CoreMedia CoreVideo CoreAnima6on

Page 9: Master Video with AV Foundation

Understanding AssetsMedia Assets

AVAssetTrack (Video)

AVAssetTrack (Audio)

AVAsset provides abstract representation of media resource‣ Abstracts away the format and location

AVAssetTrack models the individual media streams within an asset‣ Tracks are of a uniform type (video, audio, etc.)

Page 10: Master Video with AV Foundation

Media Playback

Page 11: Master Video with AV Foundation

‣ AVPlayer is a controller for managing playback- play- pause- seekToTime:

‣ Use KVO to observe playback readiness and state- status

‣ Timed Observations- addPeriodicTimeObserverForInterval:queue:usingBlock- addBoundaryTimeObserverForInterval:queue:usingBlock

Playback ControllerAVPlayer

Page 12: Master Video with AV Foundation

Static

Static vs Dynamic ModelsPlaying Media‣ AV Foundation distinguishes between static and dynamic

aspects of media

Dynamic

AVPlayerItemAVPlayerItemTrackAVPlayerItemTrackAVPlayerItemTrack

AVAssetAVAssetAVAsset

AVAssetTrack

Page 13: Master Video with AV Foundation

Playback In ActionVideo Playback

AVPlayerAVPlayerItem

AVPlayerItemTrackAVPlayerItemTrackAVPlayerItemTrack

AVAsset

AVAssetAVAssetAVAssetTrack

Page 14: Master Video with AV Foundation

AVPlayerAVPlayerItem

AVPlayerItemTrackAVPlayerItemTrackAVPlayerItemTrack

AVPlayerLayer

Playback In ActionVideo Playback

Page 15: Master Video with AV Foundation

Demo

Page 16: Master Video with AV Foundation

Composing Media

Page 17: Master Video with AV Foundation

Composing AssetsAVComposition‣ Concrete extension of AVAsset‣ Composes asset segments on a timeline

Page 18: Master Video with AV Foundation

Tracks and SegmentsComposing Assets

AVMutableComposition *composition = [AVMutableComposition composition];

AVComposition

Page 19: Master Video with AV Foundation

AVMutableCompositionTrack *audioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:1];

AVComposition

AVCompositionTrack (Video)

Tracks and SegmentsComposing Assets

AVCompositionTrack (Audio)

AVMutableCompositionTrack *videoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:0];

Page 20: Master Video with AV Foundation

AVAssetTrack *srcAudioTrack = // source audio track[audioTrack insertTimeRange:timeRange ofTrack:srcAudioTrack atTime:startTime error:&error];

Tracks and SegmentsComposing Assets

AVComposition

AVCompositionTrack (Video)

AVCompositionTrack (Audio)

AVCompositionTrackSegmentSeconds 10-30 of “goldengate.m4v”

AVCompositionTrackSegmentSeconds 20-60 of “wharf.m4v”

AVCompositionTrackSegmentSeconds 0-60 of “soundtrack.m4a”

AVAssetTrack *srcVideoTrack1 = // source video track 1[videoTrack insertTimeRange:timeRange ofTrack:srcVideoTrack1 atTime:startTime error:&error];

AVAssetTrack *srcVideoTrack2 = // source video track 2[videoTrack insertTimeRange:timeRange ofTrack:srcVideoTrack2 atTime:startTime error:&error];

Page 21: Master Video with AV Foundation

Demo

Page 22: Master Video with AV Foundation

Mixing Audio

Page 23: Master Video with AV Foundation

AVAudioMixAudio Mixing‣ Composition tracks play at their natural volume‣ AVAudioMix applies track-level volume adjustments‣ Composed of AVAudioMixInputParameters‣ Parameters control individual track volume over time

Time RangeTimeTime

Page 24: Master Video with AV Foundation

Demo

Page 25: Master Video with AV Foundation

Video Transitions

Page 26: Master Video with AV Foundation

AVVideoCompositionVideo Transitions

AVVideoComposition Defines how two or more video tracks are composited together

Configured through collection of composition instructions describing compositing behavior

AVVideoCompositionInstructionAVVideoCompositionInstructionAVVideoCompositionInstruction

Page 27: Master Video with AV Foundation

AVVideoCompositionInstructionVideo Transitions

AVVideoComposition

AVVideoCompositionInstructionAVVideoCompositionInstructionAVVideoCompositionInstruction Defines the time range of compositing behavior

Composed of layer instructions describing compositing behaviorAVAssetAVAssetAVVideoCompositionLayerInstruction

Page 28: Master Video with AV Foundation

AVVideoCompositionLayerInstructionVideo Transitions

Defines the transform and opacity ramps of input layersTransform and opacity changes modified over given time range

AVVideoComposition

AVVideoCompositionInstructionAVVideoCompositionInstructionAVVideoCompositionInstruction

AVAssetAVAssetAVVideoCompositionLayerInstruction

Page 29: Master Video with AV Foundation

Demo

Page 30: Master Video with AV Foundation

Layering Content

Page 31: Master Video with AV Foundation

Core AnimationLayering ContentCore Animation a natural choice‣ High performance, inherently time-based‣ CALayer subclasses used for all video rendering

CALayer: used to layer images and text

CAAnimation: used to animate layered content

CABasicAnimation

CAKeyframeAnimation

Page 32: Master Video with AV Foundation

AVSynchronizedLayerAnimation Timing‣ Core Animation operates on host time

‣ Starts at boot, marches towards infinity

‣ Timeline animations need to use movie time‣ Starts at time zero and runs to duration‣ Can be started, stopped, rewound, etc.

‣ Use AVSynchronizedLayer to use movie time‣ Confers player item timing on to its sublayer tree

AVSynchronizedLayer

CATextLayer

CABasicAnimation

AVPlayerItem

Timing

Page 33: Master Video with AV Foundation

Timeline vs Realtime AnimationsCore Animation

‣ Exactly the same, almost...‣ Animations with zero beginTime won’t be seen‣ Set beginTime = AVCoreAnimationBeginTimeZero

‣ Animations removed by default‣ Set removedOnCompletion = NO‣ Unable to use CAAnimationGroup?

Page 34: Master Video with AV Foundation

Demo

Page 35: Master Video with AV Foundation

Master iOS Video with AV Foundation!Summary‣ Powerful tools for audio and video playback

‣ AVPlayer, AVPlayerItem, AVPlayerLayer

‣ Powerful tools for composing/editing media:‣ AVComposition‣ AVAudioMix‣ AVVideoComposition‣ AVSynchronizedLayer

‣ Relatively steep learning curve, but worth the investment!

Page 36: Master Video with AV Foundation

ResourcesPresentation Materialshttp://www.speakerdeck.com/bobmccune/https://github.com/tapharmonic/AVFoundationEditor

Learning AV Foundationhttp://my.safaribooksonline.com/9780133563856

Contact Info

@bobmccunehttp://bobmccune.com