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.5k
Replicating ActiveRecord objects to MongoDB
ivanacostarubio
2
2.4k
Other Decks in Programming
See All in Programming
CSC305 Lecture 26
javiergs
PRO
0
130
似たもの同士のPerlとPHP
uzulla
1
120
Security_for_introducing_eBPF
kentatada
0
110
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
440
AWS認定資格を勉強した先に何があったか
satoshi256kbyte
2
210
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
990
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
440
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
880
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
270
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
160
fs2-io を試してたらバグを見つけて直した話
chencmd
0
160
たのしいparse.y
ydah
3
120
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
We Have a Design System, Now What?
morganepeng
51
7.3k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Building Applications with DynamoDB
mza
91
6.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
BBQ
matthewcrist
85
9.4k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.3k
For a Future-Friendly Web
brad_frost
175
9.4k
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