Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Intro to AVFoundation | #inspect2014
Search
Ivan Acosta-Rubio
June 25, 2014
Programming
0
180
Intro to AVFoundation | #inspect2014
Intro to Apple's AVFoundation
Ivan Acosta-Rubio
June 25, 2014
Tweet
Share
More Decks by Ivan Acosta-Rubio
See All by Ivan Acosta-Rubio
RubyMotion @ MagmaConf
ivanacostarubio
1
800
CHINDOGU: LEVENSHTEIN Y METHOD MISSNG
ivanacostarubio
0
1.2k
A (re)-factoring Story
ivanacostarubio
1
1.7k
REST: Code Retreat Universidad Simón Bolívar
ivanacostarubio
1
1.6k
Replicating ActiveRecord objects to MongoDB
ivanacostarubio
2
2.4k
Other Decks in Programming
See All in Programming
GAEログのコスト削減
mot_techtalk
0
110
Introduction to kotlinx.rpc
arawn
0
630
How mixi2 Uses TiDB for SNS Scalability and Performance
kanmo
30
11k
ISUCON14公式反省会LT: 社内ISUCONの話
astj
PRO
0
180
ARA Ansible for the teams
kksat
0
150
Amazon Q Developer Proで効率化するAPI開発入門
seike460
PRO
0
110
バックエンドのためのアプリ内課金入門 (サブスク編)
qnighy
8
1.7k
Writing documentation can be fun with plugin system
okuramasafumi
0
120
チームリードになって変わったこと
isaka1022
0
190
Honoとフロントエンドの 型安全性について
yodaka
4
250
Amazon Bedrock Multi Agentsを試してきた
tm2
1
280
【PHP】破壊的バージョンアップと戦った話〜決断と説得
satoshi256kbyte
0
120
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
The Cult of Friendly URLs
andyhume
78
6.2k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.5k
YesSQL, Process and Tooling at Scale
rocio
171
14k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
366
25k
GitHub's CSS Performance
jonrohan
1030
460k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
51k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.8k
Transcript
None
@ivanacostarubio
AVFoundation record, display, edit
None
github.com/ivanacostarubio/helu
1 @helu = Helu.new("loosing_weight_10")! 2 @helu.fail = lambda { |transaction|
}! 5 @helu.winning = lambda { |transaction| }! 8 ! @helu.restore = lambda { ... }!
ivanacostarubio/motion-social
None
AVFoundation audio + video
None
None
@Dain Fagerholm
AVFoundation audio + video FTFW!
Capture Playback Edit
OLD & HUGE
IOS4 / OS10.7 Lion
Almost Identical
Screen Camera Microphone
None
1 @tape = ScreenRecorder.new("my_file")! 2 @tape.start! 3 @tape.stop!
1 class ScreenRecorder! 2 def initialize(file_name)! 3 end! 4 !
5 def start! 6 end! 7 ! 8 def stop! 9 end! 10 ! 11 def setup_video! 12 end! 13 ! 14 def setup_audio! 15 end! 16 ! 17 def setup_recording! 18 end! 19 end
Session AVCaptureSession Input AVCaptureScreenInput! AVCaptureDeviceInput
! 1 def setup_video! 2 @session = AVCaptureSession.alloc.init! 5 !
6 @device = AVCaptureScreenInput.alloc.! 7 initWithDisplayID(CGMainDisplayID())! ! 10 if @session.canAddInput(@device)! 12 @session.addInput(@device)! 15 end! 16 ! 17 setup_audio! 18 @session.startRunning()! 19 end! ! ! ! ! 8 @device.capturesMouseClicks = true! 3 @session.sessionPreset = AVCaptureSessionPresetHigh! !
22 def setup_audio! 23 audioDevice = AVCaptureDevice.defaultDeviceWithMediaType(! 25 AVMediaTypeAudio)! 26
audioInput = AVCaptureDeviceInput.deviceInputWithDevice(! 28 audioDevice, error:nil)! ! 29 if @session.canAddInput(audioInput)! 30 @session.addInput(audioInput)! 31 end! ! 32 end
1 class ScreenRecorder! 2 def initialize(file_name)! 3 end! 4 !
5 def start! 6 end! 7 ! 8 def stop! 9 end! 10 ! 11 def setup_video! 12 end! 13 ! 14 def setup_audio! 15 end! 16 ! 17 def setup_recording! 18 end! 19 end
Session AVCaptureSession Device AVCaptureScreenInput! AVCaptureDeviceInput Output AVCaptureMovieFileOutput
36 def setup_recording! 37 @captureMovieFileOutput = AVCaptureMovieFileOutput.new! 39 @captureMovieFileOutput.setDelegate(self)! !
40 if @session.canAddOutput(@captureMovieFileOutput)! 42 @session.addOutput(@captureMovieFileOutput)! 43 end! ! 44 end! 45 ! 46 def start! 47 @captureMovieFileOutput. ! 48 startRecordingToOutputFileURL(video_path, ! 49 recordingDelegate:self)! 50 end! ! Stops Recording: @captureMovieFileOutput.stopRecording! ! !
None
video.softwarecriollo.com
UIKit CoreAudio AVFoundation CoreMedia CoreAnimation Media Player
When not to use • Capture photo or video •
Play a movie
When to use • Inspect Media Properties • Custom UI
• Compose / Combine media. • Detailed control over capture. • Adjust exposure, etc
Class Groups • Capture (AVCaptureSession, AVCaptureMovieFileOutput) • Playback (AVAsset, AVPlayer,
AVPlayerItem, AVPlayerLayer) • Edit (AVMutableComposition) • Read / Write (AVExportSession)
None
UIView AVPlayerLayer AVPlayer CALayer insertSublayer
1 view = UIView.alloc.init! 2 player = AVPlayer.alloc.initWithURL(file_url)! 3 layer
= AVPlayerLayer.playerLayerWithPlayer(player)! 5! 7 view.layer.insertSublayer(layer, atIndex:1)! 8! 10 player.play
UIView AVPlayerLayer AVPlayer CALayer insertSublayer
None
None
1 @video_cut = VideoCut.new! 2 @video_cut.start_time = @start! 3 @video_cut.end_time
= @end! 4 @video_cut.movie_file = "full_video"! 5 @video_cut.compose_movies!
CMTime • It is not an object. It is a
C Struck • value / timescale • CMTimeRangeMake(start_time, duration) ! (main)> CMTimeMakeWithSeconds(10,1)! => #<CMTime value=10 timescale=1 flags=1 epoch=0>
AVURLAsset AVAssetExportSession AVMutableComposition
1 def asset! 2 @asset ||= AVURLAsset.URLAssetWithURL(file_url,options:nil) 4 end! !
5 ! 6 def compose_movies! 7 @composition = AVMutableComposition.composition! 8! error = Pointer.new(:object)! 10 duration = CMTimeSubtract(end_time, start_time) ! 11 ! 12 ! 13 result = @composition.insertTimeRange(! 14 CMTimeRangeMake(start_time, duration)! 15 , ofAsset:asset, atTime:KCMTimeZero, ! 16 error: error)! 25 end!
1 def write_to_file! 2 @exportSession = AVAssetExportSession.alloc.! 3 initWithAsset(@composition, !
4 presetName: ! 5 “AVAssetExportPreset640x480")! ! 6 @exportSession.outputURL = NSURL.fileURLWithPath(“name”)! 7 ! ! 9 @exportSession.outputFileType = "com.apple.quicktime-movie"! 10 ! 11 ! 12 c = Proc.new { ... }! 13 @exportSession.exportAsynchronouslyWithCompletionHandler(c)! 14 end!
RECAP
None
Session AVCaptureSession Device AVCaptureScreenInput! AVCaptureDeviceInput Output AVCaptureMovieFileOutput Recording
UIView AVPlayerLayer AVPlayer CALayer insertSublayer Display
AVURLAsset AVAssetExportSession AVMutableComposition Editing / Composing
None