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
170
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
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.3k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
810
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
200
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
320
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
420
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
2.5k
subpath importsで始めるモック生活
10tera
0
150
Importmapを使ったJavaScriptの 読み込みとブラウザアドオンの影響
swamp09
4
1.4k
as(型アサーション)を書く前にできること
marokanatani
6
1.5k
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
510
外部システム連携先が10を超えるシステムでのアーキテクチャ設計・実装事例
kiwasaki
1
280
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
95
5.2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Music & Morning Musume
bryan
46
6.2k
A Philosophy of Restraint
colly
203
16k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
700
How to Ace a Technical Interview
jacobian
276
23k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.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