407 Editing Media With Av Foundation
-
Upload
brian-jordan -
Category
Documents
-
view
1.565 -
download
0
Transcript of 407 Editing Media With Av Foundation
![Page 1: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/1.jpg)
Eric LeeiPhone Engineering
Overview and best practices
Editing Media with AV Foundation
2
![Page 2: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/2.jpg)
What You’ll Learn
• Why and when you should use AV Foundation editing• Concepts underlying manipulation of timed-based media• What editing tasks you can accomplish using AV Foundation
3
![Page 3: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/3.jpg)
Sample Code for This Session
• AVPlayerDemo• AVEditDemo
Materials available at:http://developer.apple.com/wwdc/attendee/
4
![Page 4: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/4.jpg)
Technology Framework
CoreAnimationCoreAudio CoreMedia
AVFoundation
UIKit
MediaPlayer
5
![Page 5: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/5.jpg)
A user featureEditing in iPhone OS 3.x
ThumbnailsTrim UI
6
![Page 6: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/6.jpg)
Editing APIs in AV FoundationScenarios
• Create an image for a time• Trim a movie to a time range• Cutting together multiple clips• Audio mixing• Video transitions• Incorporating Core Animation in movies
7
![Page 7: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/7.jpg)
Fundamentals
CoreAnimationCoreAudio
AVFoundation
UIKit
MediaPlayer
CoreMedia
8
![Page 8: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/8.jpg)
CMTimeStruct type for rational time
• CMTime t = CMTimeMake( time value, time scale );• kCMTimeZero, kCMTimeInvalid
• x = CMTimeAdd( y, z );• if( CMTIME_COMPARE_INLINE( t1, <=, t2 ) ) { ... }
• CMTimeRange r = CMTimeRangeMake( start time, duration );
• CMTimeMapping m = CMTimeMappingMake( source range, target range );
9
![Page 9: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/9.jpg)
AVFoundation
CoreMedia
Moving Up
CoreAnimationCoreAudio
UIKit
MediaPlayer
AVFoundation
CoreMedia
10
![Page 10: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/10.jpg)
Movie
Movies and AVAssets
• AVURLAsset represents movies in files• An AVAssetTrack represents a particular track inside the movie• Use AVPlayerItem to play an AVAsset
AVAssetTracks
AVAsset
11
![Page 11: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/11.jpg)
Editing APIs in AV FoundationScenarios
• Create an image for a time
• Trim a movie to a time range
• Cutting together multiple clips
• Audio mixing
• Video transitions
• Incorporating Core Animation in movies
• Create an image for a time
• Trim a movie to a time range
• Cutting together multiple clips
• Audio mixing
• Video transitions
• Incorporating Core Animation in movies
12
![Page 12: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/12.jpg)
Custom playback UIDemo
AVPlayerDemo
13
![Page 13: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/13.jpg)
Grab images from an AVAsset using AVAssetImageGeneratorGrab Image at Time
AVAssetImageGenerator *imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:myAsset];
[imageGenerator generateCGImagesAsynchronouslyForTimes:timeArray completionHandler:handlerBlock];
// need to retain imageGenerator until you get the images
14
![Page 14: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/14.jpg)
NSError *errorCGImageRef image
Image Generation Completion BlockCheck the result
AVAssetImageGeneratorCompletionHandler handlerBlock = ^(CMTime requestedTime, , CMTime actualTime, AVAssetImageGeneratorResult result, ){ switch (result) { case AVAssetImageGeneratorSucceeded:! ! /* image is valid */ break; case AVAssetImageGeneratorFailed: /* error */ break;! case AVAssetImageGeneratorCancelled: /* cancelled */ break; }}
CGImageRef imageNSError *error
15
![Page 15: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/15.jpg)
Editing APIs in AV FoundationScenarios
• Create an image for a time
• Trim a movie to a time range
• Cutting together multiple clips
• Audio mixing
• Video transitions
• Incorporating Core Animation in movies
• Create an image for a time
• Trim a movie to a time range
• Cutting together multiple clips
• Audio mixing
• Video transitions
• Incorporating Core Animation in movies
16
![Page 16: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/16.jpg)
Export an AVAsset to a new file using AVAssetExportSession
• Presets for different sizes, bitrates, etc.• Optionally set timeRange to trim• Optionally add metadata
Export and Trimming
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetMediumQuality];
exportSession.outputURL = ...;exportSession.outputFileType = AVFileTypeQuickTimeMovie;
exportSession.timeRange = CMTimeRangeMake(startTime, duration);
exportSession.metadata = ...;
[exportSession exportAsynchronouslyWithCompletionHandler:handlerBlock];
17
![Page 17: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/17.jpg)
Export Completion BlockCheck the status
void (^handlerBlock)(void) = ^{! switch (exportSession.status) {! case AVAssetExportSessionStatusCompleted: /* export complete */ break; case AVAssetExportSessionStatusFailed: /* export error (see exportSession.error) */ break; case AVAssetExportSessionStatusCancelled: /* export cancelled */ break; }}
18
![Page 18: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/18.jpg)
Handle failures gracefully
• AVAssetExportSession will not overwrite files• AVAssetExportSession will not write files outside of your sandbox
A Word on Error Handling
19
![Page 19: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/19.jpg)
Export and MultitaskingHandle failures gracefully
• Other apps that start playback will interrupt a background export• Even in the foreground, an incoming phone call will interrupt export
20
![Page 20: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/20.jpg)
Editing APIs in AV FoundationScenarios
• Create an image for a time
• Trim a movie to a time range
• Cutting together multiple clips
• Audio mixing
• Video transitions
• Incorporating Core Animation in movies
21
![Page 21: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/21.jpg)
Cornerstones of editingAVAsset and AVComposition
22
![Page 22: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/22.jpg)
AVAsset as a Source Object
AVPlayerItem
AVAssetImageGeneratorAVAsset
Movie File
AVAssetExportSession
23
![Page 23: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/23.jpg)
AVComposition
a subclass of AVAsset
AVPlayerItem
AVAssetImageGenerator
AVAssetExportSession
Movie Files
AVComposition
24
![Page 24: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/24.jpg)
Editing APIs in AV FoundationScenarios
• Create an image for a time
• Trim a movie to a time range
• Cutting together multiple clips
• Audio mixing
• Video transitions
• Incorporating Core Animation in movies
25
![Page 25: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/25.jpg)
Cutting together movie clipsDemo
Sample code: AVEditDemo (see SimpleEditor.m)
26
![Page 26: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/26.jpg)
Composing a Timeline
27
![Page 27: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/27.jpg)
AVComposition
AVCompositionTrack (audio)
AVCompositionTrack (video)
AVCompositionAVComposition assembles asset segments on a timeline
AVCompositionTrackSegment “seconds 1–2 of
video track of beach.mov”
AVCompositionTrackSegment “seconds 5–10 of
video track of flowers.mov”
AVCompositionTrackSegment “seconds 3–6 of
audio track of cat.mov”
AVCompositionTrackSegment “seconds 1–2 of
audio track of beach.mov”
AVCompositionTrackSegment “seconds 5–10 of
audio track of flowers.mov”
AVCompositionTrackSegment “ of
of ”cat.movcat.movvideo trackvideo trackseconds 3–6seconds 3–6
28
![Page 28: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/28.jpg)
AVMutableComposition
• You can edit across all tracks of a composition:■ [composition insertTimeRange:... ofAsset:... atTime:... error:...];
• You can edit a single track:■ [compositionTrack insertTimeRange:... ofTrack:... atTime:... error:...];
• You can change the segment array directly:■ [compositionTrack setSegments:...];
29
![Page 29: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/29.jpg)
AVEditDemo
AVMutableComposition *composition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:...];
[compositionVideoTrack insertTimeRange:... ofTrack:clipVideoTrack atTime:... error:...];
See buildSequenceComposition in SimpleEditor.m
30
![Page 30: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/30.jpg)
When Not to Mutate CompositionsDon’t modify an AVMutableComposition during playback, image generation, or export
• Make a copy for these tasks; then it’s safe to modify the original: AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset: [[mutableComposition copy] autorelease]];
• Switch player to new item: [player replaceCurrentItemWithPlayerItem:playerItem];
31
![Page 31: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/31.jpg)
Editing APIs in AV FoundationScenarios
• Create an image for a time
• Trim a movie to a time range
• Cutting together multiple clips
• Audio mixing
• Video transitions
• Incorporating Core Animation in movies
• Create an image for a time
• Trim a movie to a time range
• Cutting together multiple clips
• Audio mixing
• Video transitions
• Incorporating Core Animation in movies
32
![Page 32: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/32.jpg)
Mixing in additional audioDemo
Sample code: AVEditDemo (see SimpleEditor.m)
33
![Page 33: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/33.jpg)
Empty segment
Adding a Commentary Track
Audio volume ramp
34
![Page 34: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/34.jpg)
AVComposition
AVAudioMix
AVComposition and AVAudioMix
35
![Page 35: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/35.jpg)
AVAudioMixTool for adding volume adjustments
• Has array of AVAudioMixInputParameters■ Each adjusts the volume level of one track■ Tracks without AVAudioMixInputParameters get default volume
36
![Page 36: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/36.jpg)
AVMutableAudioMix
AVMutableAudioMixInputParameters *trackMix = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:mainAudioTrack];
[trackMix setVolume:1.0 atTime:kCMTimeZero];
[trackMix setVolumeRampFromStartVolume:1.0 toEndVolume:0.2 timeRange:CMTimeRangeMake(x,y-x)];...
AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
audioMix.inputParameters = [NSArray arrayWithObject:trackMix];
1.0
0.2
x y
37
![Page 37: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/37.jpg)
Using AVAudioMix
• To apply AVAudioMix for playback:■ playerItem.audioMix = audioMix;
• To apply AVAudioMix for export:■ exportSession.audioMix = audioMix;
38
![Page 38: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/38.jpg)
Editing APIs in AV FoundationScenarios
• Create an image for a time
• Trim a movie to a time range
• Cutting together multiple clips
• Audio mixing
• Video transitions
• Incorporating Core Animation in movies
• Create an image for a time
• Trim a movie to a time range
• Cutting together multiple clips
• Audio mixing
• Video transitions
• Incorporating Core Animation in movies
39
![Page 39: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/39.jpg)
Video transitionsDemo
Sample code: AVEditDemo (see SimpleEditor.m)
40
![Page 40: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/40.jpg)
AVComposition
AVComposition and AVVideoComposition
AVVideoComposition
A AA/B B/AB
41
![Page 41: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/41.jpg)
AVVideoComposition
■ Each instruction describes the output video in terms of input layers (AVVideoCompositionLayerInstruction)■ Each layer has an opacity and an affine transform■ Opacity can be tweened — e.g., for a cross-fade■ Affine transform can be tweened — e.g., for a push transition
AVVideoComposition
A
• Has an array of AVVideoCompositionInstructions
AB
B BA
A
42
![Page 42: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/42.jpg)
AVVideoCompositionInstruction
AVMutableVideoCompositionInstruction *transition = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
transition.timeRange = ...;
AVMutableVideoCompositionLayerInstruction *fromLayer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:trackA];
// Fade out trackA by setting a ramp from 1.0 to 0.0.[fromLayer setOpacityRampFromStartOpacity:1.0 toEndOpacity:0.0 timeRange:...];
AVMutableVideoCompositionLayerInstruction *toLayer = ...
transition = [NSArray arrayWithObjects:fromLayer, toLayer, nil];
AVVideoComposition
A AB
B BA
AAB
43
![Page 43: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/43.jpg)
AVVideoComposition
AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];
videoComposition.instructions = [NSArray arrayWithObject:transition];
videoComposition.frameDuration = CMTimeMake(1, 30);
videoComposition.renderSize = CGSizeMake(1280, 720);
videoComposition.renderScale = 0.5; // for playback only
44
![Page 44: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/44.jpg)
Using AVVideoComposition
• For playback:■ playerItem.videoComposition = videoComposition;
• For image generation:■ assetImageGenerator.videoComposition = videoComposition;
• For export:■ assetExportSession.videoComposition = videoComposition;
45
![Page 45: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/45.jpg)
Pitfalls
• AVVideoComposition must not be shorter than AVComposition
AVComposition
AVVideoComposition
• AVVideoCompositionInstructions must not overlap or contain gaps
AVComposition
AVVideoComposition
46
![Page 46: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/46.jpg)
Hardware Requirements for Video Composition
• iPhone 3GS or later• iPod touch (3rd generation)
47
![Page 47: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/47.jpg)
P P I P P PAVComposition
P P I P P PP P P I P I P I P P P P
• Not restricted to editing at key frames• Use AVVideoComposition and alternating segments between two video tracks to give AV Foundation more time for catchup decoding
Temporal Video Compression
I P P P P I P P P P I P P P P I P P P P ...
I P P
AVVideoComposition
B A B
48
![Page 48: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/48.jpg)
Other Uses for AVVideoComposition
• Two assets with different video sizes inserted into an AVComposition will end up in different video tracks by default■ AVPlayer will only play one of them■ Add an AVVideoComposition
• Movies captured in portrait or reverse landscape orientation will have a preferredTransform set on the video track■ The transform will be ignored if the asset is placed in an AVComposition■ Use AVVideoComposition to reinstate the rotation
49
![Page 49: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/49.jpg)
Editing APIs in AV FoundationScenarios
• Create an image for a time
• Trim a movie to a time range
• Cutting together multiple clips
• Audio mixing
• Video transitions
• Incorporating Core Animation in movies
• Create an image for a time
• Trim a movie to a time range
• Cutting together multiple clips
• Audio mixing
• Video transitions
• Incorporating Core Animation in movies
50
![Page 50: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/50.jpg)
Core Animation in MoviesDemo
Sample code: AVEditDemo (see SimpleEditor.m)
51
![Page 51: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/51.jpg)
AVComposition
CALayers
Core Animation in Movies
spin stars fade out after 10 secMagic!
CAAnimations
52
![Page 52: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/52.jpg)
AVEditDemo: Core Animation
CABasicAnimation
Fade out after 10 sec
CABasicAnimation
Spin
Magic!
titleLayer ringOfStarsLayer
animatedTitleLayer
Attend Sessions 424 and 425 for more information on Core Animation
53
![Page 53: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/53.jpg)
Animation, Video, and Time
real time“seconds since boot”
movie time“seconds since start of movie”
AVPlayerLayer
UIView
5000 5001 5002 5003 5004 5005 5006 5007
0 1 2 3 4 5 6 7 8 9
Magic!
Video AVSynchronizedLayer
54
![Page 54: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/54.jpg)
Playback with Core Animation
• Use AVSynchronizedLayer to make animation use movie timing
55
![Page 55: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/55.jpg)
Export with Core Animation
• Use AVVideoCompositionCoreAnimationTool to integrateCore Animation as a “post-processing” video stage
• Set compositionInstruction.enablePostProcessing to NO to skipCore Animation rendering when not needed
videoLayer
parentLayer
AVVideoCompositionCoreAnimationTool
Magic!
animationTitleLayer
56
![Page 56: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/56.jpg)
Multitasking
• Core Animation use in the background will cause the export to fail
57
![Page 57: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/57.jpg)
Core Animation GotchasCore Animation features that are convenient for real-time animation but don’t work well in movies
• Zero beginTime is automatically translated to CACurrentMediaTime()• Use a small nonzero number: e.g., 1e-100 or -1e-100 (AVCoreAnimationBeginTimeZero)
• Animations are automatically removed after Core Animation thinks they have passed• animation.removedOnCompletion = NO;
58
![Page 58: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/58.jpg)
Core Animation GotchasCore Animation features that are convenient for real-time animation but don’t work well in movies
• Disable implicit animations
[CATransaction begin]; [CATransaction setDisableActions:YES]; // your layer code here[CATransaction commit];
59
![Page 59: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/59.jpg)
Stretch It Out
• Core Animation contributions may continue past the end of an AVComposition
AVComposition
Core Animation Animations a
• Need to explicitly indicate how long playback or export should run■ Set playerItem.forwardPlaybackEndTime for playback■ Set assetExportSession.timeRange for export
60
![Page 60: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/60.jpg)
Summary
• Create an image for a time• Outputting a movie• Combining multiple clips• Audio volume adjustment• Video transitions• Incorporating Core Animation
AVAssetImageGeneratorAVAssetExportSessionAVCompositionAVAudioMixAVVideoCompositionAVSynchronizedLayer and AVVideoCompositionCoreAnimationTool
• Create an image for a time• Outputting a movie• Combining multiple clips• Audio volume adjustment• Video transitions• Incorporating Core Animation
61
![Page 61: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/61.jpg)
Eryk VershenMedia Technologies [email protected]
DocumentationAV Foundation Framework Referencehttp://developer.apple.com/iphone
Apple Developer Forumshttp://devforums.apple.com
More Information
62
![Page 62: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/62.jpg)
Discovering AV Foundation (Repeat) Nob HillThursday 4:30PM
Using the Camera with AV Foundation PresidioTuesday 4:30PM
Related Sessions
Core Animation in Practice, Part 1 Nob HillThursday 11:30AM
Core Animation in Practice, Part 2 Nob HillThursday 2:00PM
Introducing Blocks and Grand Central Dispatch on iPhone Russian HillWednesday 11:30AM
63
![Page 63: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/63.jpg)
AV Foundation Lab #2 Graphics & Media Lab BFriday 11:30AM
AV Foundation Lab #1 Graphics & Media Lab CWednesday 9:00AM
Core Animation Lab Graphics & Media Lab DThursday 3:15PM
Labs
64
![Page 64: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/64.jpg)
65
![Page 65: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/65.jpg)
66
![Page 66: 407 Editing Media With Av Foundation](https://reader034.fdocuments.net/reader034/viewer/2022042613/5535b3325503467c7a8b46cc/html5/thumbnails/66.jpg)
67