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
160
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
790
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
Deep Dive 大規模システムアーキテクチャ/開発組織エンジニアリング / Deep Dive Large-Scale System Architecture, Development Organization Engineering
nrslib
15
2.9k
「コンパイル時のユニットテスト」導入するとユニットテストを 書かなくてよくなるのか?
tomohisa
9
2.1k
ここ1~2年くらいで 使えるようになった(主要ブラウザーの最新版 がすべて対応した ) ウェブの新機能について ランダムに喋る!
myzkyy
9
6.4k
App Router への移行は「改善」となり得るのか?/ Can migration to App Router be an improvement
takefumiyoshii
1
110
WinUI 3デモ - "CommunityToolkit.Mvvm"NuGetパッケージ編
andrewkeepcoding
0
130
プロンプトエンジニアリング入門
tomokusaba
2
970
SwiftUI, Jetpack Composeの導入で変化した「家族アルバム みてね」のアプリ開発体験
hicka04
6
390
Building a Smaller App Binary
kateinoigakukun
2
200
Kotlinを用いたDSL的な設計手法と使用上の注意
kohii00
3
530
PHP 8.3で追加されたjson_validate()を徹底的に深掘りしてみよう
mashirou1234
1
720
オブジェクト指向コードレビューの新しいアプローチ
akkie76
3
1.1k
もうすぐ新年度、Babylon.jsがお勧めな3個の理由
hideg
0
160
Featured
See All Featured
Building Applications with DynamoDB
mza
88
5.6k
A better future with KSS
kneath
230
16k
How To Stay Up To Date on Web Technology
chriscoyier
781
250k
The Invisible Customer
myddelton
114
12k
Stop Working from a Prison Cell
hatefulcrawdad
265
19k
Bash Introduction
62gerente
604
210k
Debugging Ruby Performance
tmm1
68
11k
Code Reviewing Like a Champion
maltzj
512
39k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
101
6.6k
What’s in a name? Adding method to the madness
productmarketing
PRO
14
2.6k
Visualization
eitanlees
135
14k
Automating Front-end Workflow
addyosmani
1353
200k
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