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
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
130
Pythonでもちょっとリッチな見た目のアプリを設計してみる
ueponx
1
480
Grafana Cloudとソラカメ
devoc
0
140
Compose でデザインと実装の差異を減らすための取り組み
oidy
1
300
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
170
SwiftUIで単方向アーキテクチャを導入して得られた成果
takuyaosawa
0
260
[JAWS-UG横浜 #79] re:Invent 2024 の DB アップデートは Multi-Region!
maroon1st
1
140
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
270
Amazon Bedrock Multi Agentsを試してきた
tm2
1
280
Conform を推す - Advocating for Conform
mizoguchicoji
3
680
一休.com のログイン体験を支える技術 〜Web Components x Vue.js 活用事例と最適化について〜
atsumim
0
110
SRE、開発、QAが協業して挑んだリリースプロセス改革@SRE Kaigi 2025
nealle
3
4.1k
Featured
See All Featured
Side Projects
sachag
452
42k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
540
Practical Orchestrator
shlominoach
186
10k
Docker and Python
trallard
44
3.3k
KATA
mclloyd
29
14k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
8
270
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Into the Great Unknown - MozCon
thekraken
35
1.6k
Six Lessons from altMBA
skipperchong
27
3.6k
Faster Mobile Websites
deanohume
306
31k
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