SlideShare a Scribd company logo
1 of 61
Capturing Stills, Sounds,
                     and Scenes with AV
                         Foundation
                                  Chris Adamson • @invalidname
                           Voices That Matter: iOS Developer Conference
                                    Nov. 12, 2011 • Boston, MA




Tuesday, November 15, 11
Road Map

               • Media capture technologies in iOS

               • AV Foundation capture concepts

               • Device-specific concerns

               • Doing stuff with captured media




Tuesday, November 15, 11
Capture?
               • Digital media encoding of some real-world source,
                 such as still images, moving images, and/or sound

                           • Contrast with synthetic media: musical
                             synthesizers, CG animation

               • Not the same as "recording", which implies storage

               • Capture devices include cameras and
                 microphones




Tuesday, November 15, 11
iOS Capture Devices




Tuesday, November 15, 11
Accessing Capture
                                Devices
               • Simple shoot-and-save -
                 UIImagePickerController

               • Core Audio - low level capture and real-time
                 processing

                           • More info in my talk tomorrow

               • AV Foundation


Tuesday, November 15, 11
AV Foundation
               • Introduced in iPhone OS 2.3 as Obj-C
                 wrapper for Core Audio playback, added
                 capture in 3.0

               • Repurposed in iOS 4 as audio/video capture,
                 editing, export, and playback framework

               • Ported to OS X in Lion, heir apparent to
                 QuickTime


Tuesday, November 15, 11
#import this!
               • AVFoundation.framework

               • CoreMedia.framework

               • Possibly also:

                    • CoreVideo, CoreImage, CoreGraphics

                    • AudioToolbox, AudioUnits


Tuesday, November 15, 11
Core Media
               • C-based helper framework for AVF

               • Structures to represent media buffers and
                 queues of buffers, media times and time
                 ranges

               • Low-level conversion and calculation functions

                           • Does not provide capture, editing, or
                             playback functionality


Tuesday, November 15, 11
AV Foundation
               • Editing / Playback classes

                    • Assets, compositions, and tracks. Player
                      and player layer. Asset readers and writers

               • Capture classes

                    • Devices, inputs, outputs, and the session



Tuesday, November 15, 11
How it fits together…




Tuesday, November 15, 11
Tuesday, November 15, 11
AVCaptureSession




Tuesday, November 15, 11
AVCaptureDevice




                           AVCaptureSession




Tuesday, November 15, 11
AVCaptureDevice

                           AVCaptureInput




                                   AVCaptureSession




Tuesday, November 15, 11
AVCaptureDevice                                AVCaptureDevice

                           AVCaptureInput




                                   AVCaptureSession




Tuesday, November 15, 11
AVCaptureDevice                                         AVCaptureDevice

                           AVCaptureInput     AVCaptureInput




                                   AVCaptureSession




Tuesday, November 15, 11
AVCaptureDevice                                         AVCaptureDevice

                           AVCaptureInput     AVCaptureInput




       AVCaptureVideo
                                   AVCaptureSession
        PreviewLayer




Tuesday, November 15, 11
AVCaptureDevice                                           AVCaptureDevice

                             AVCaptureInput     AVCaptureInput




       AVCaptureVideo
                                     AVCaptureSession
        PreviewLayer




                           AVCaptureOutput




Tuesday, November 15, 11
AVCaptureDevice                                           AVCaptureDevice

                             AVCaptureInput     AVCaptureInput




       AVCaptureVideo
                                     AVCaptureSession
        PreviewLayer




                           AVCaptureOutput




Tuesday, November 15, 11
AVCaptureDevice                                           AVCaptureDevice

                             AVCaptureInput     AVCaptureInput




       AVCaptureVideo
                                     AVCaptureSession
        PreviewLayer




                           AVCaptureOutput     AVCaptureOutput




Tuesday, November 15, 11
AVCaptureDevice                                           AVCaptureDevice

                             AVCaptureInput     AVCaptureInput




       AVCaptureVideo
                                     AVCaptureSession
        PreviewLayer




                           AVCaptureOutput     AVCaptureOutput




Tuesday, November 15, 11
AVCaptureSession


               • Coordinates the flow of capture from inputs to
                 outputs

               • Create, add inputs and outputs, start running


        captureSession = [[AVCaptureSession alloc] init];



Tuesday, November 15, 11
AVCaptureDevice
               • Represents a device that can perform media
                 capture (cameras, microphones)

               • Could be connected as external accessory or
                 Bluetooth

                    • You cannot make assumptions based on
                      device model



Tuesday, November 15, 11
Discovering Devices

               • AVCaptureDevice class methods devices,
                 deviceWithUniqueID, devicesWithMediaType,
                 defaultDeviceWithMediaType

               • Media types include audio, video, muxed
                 (audio and video in one stream), plus some
                 outliers (timecode, etc.)



Tuesday, November 15, 11
Inspecting Devices

               • position (property): is the camera on the front
                 or the back?

               • supportsAVCaptureSessionPreset: allows you
                 to inspect whether it can copy at one of
                 several predefined image resolutions




Tuesday, November 15, 11
Photo traits
        • Focus & exposure

             • isFocusModeSupported:, focusMode,
               focusPointOfInterestSupported, focusPointOfInterest,
               focusAdjusting

             • isExposureModeSupported:, exposureMode,
               exposurePointOfInterestSupported, etc.

        • White balance

             • isWhiteBalanceModeSupported:, whiteBalanceMode,
               whiteBalanceModeAdjusting

Tuesday, November 15, 11
Light up

               • Flash and Torch

                    • hasFlash, isFlashModeSupported:
                      flashMode, flashActive, flashAvailable

                    • hasTorch, isTorchModeSupported:,
                      torchMode, torchLevel, torchAvailable




Tuesday, November 15, 11
AVCaptureSession
                             sessionPreset
               • Constants for video capture quality. Allows
                 you to inspect capabilities, trade
                 performance/framerate for resolution

               • Default is AVCaptureSessionPresetHigh

               • For still photos:
                 AVCaptureSessionPresetPhoto



Tuesday, November 15, 11
iFrame
               • Session presets for use when capturing video
                 intended for subsequent editing

                    • AVCaptureSessionPresetiFrame960x540,
                      AVCaptureSessionPresetiFrame1280x720

               • No P- or B-frames; files are much larger than
                 typical H.264.




                   http://en.wikipedia.org/wiki/Video_compression_picture_types
Tuesday, November 15, 11
Capture inputs

               • Connect a device to the capture session

               • Instances of AVCaptureDeviceInput

               • create with -initWithDevice:error: or
                 deviceInputForDevice:error




Tuesday, November 15, 11
AVCaptureDevice *videoDevice =
      ! [AVCaptureDevice defaultDeviceWithMediaType:
      ! AVMediaTypeVideo];

      if (videoDevice) {
      ! AVCaptureDeviceInput *videoInput =
       ! [AVCaptureDeviceInput
      ! ! deviceInputWithDevice:videoDevice
      ! ! ! ! ! ! ! ! error:&setUpError];
      ! if (videoInput) {
      ! ! [captureSession addInput: videoInput];
      ! }
      }




Tuesday, November 15, 11
Capture preview
               • AVCapturePreviewLayer: A CALayer that
                 shows what's currently being captured from
                 video input

                    • Remember: CALayer, not UIView

               • videoGravity property determines how it will
                 deal with preview that doesn't match bounds:
                 aspect, fill, or resize


Tuesday, November 15, 11
AVCaptureVideoPreviewLayer *previewLayer =
    ! [AVCaptureVideoPreviewLayer
    ! ! layerWithSession:captureSession];
    previewLayer.frame = captureView.layer.bounds;
    previewLayer.videoGravity =
    ! AVLayerVideoGravityResizeAspect;
    [captureView.layer addSublayer:previewLayer];




Tuesday, November 15, 11
Capture Outputs
               • File output: AVCaptureMovieFileOutput and
                 AVCaptureAudioFileOutput

               • Photo output: AVCaptureStillImageOutput

               • Image processing: AVCaptureDataOutput

                    • More on this one later…



Tuesday, November 15, 11
AVCaptureFileOutput
               • startRecordingToOutputURL:recordingDelegate:

               • The delegate must be set and must implement two
                 callbacks:

                    • captureOutput:didStartRecordingToOutputFileAt 
                      URL:fromConnections:

                    • captureOutput:didFinishRecordingToOutputFileAt 
                      URL:fromConnections:

               • Then connect to capture session

Tuesday, November 15, 11
captureMovieOutput =
 ! [[AVCaptureMovieFileOutput alloc] init];

 if (! captureMovieURL) {
 ! captureMoviePath = [getCaptureMoviePath() retain];
 ! captureMovieURL = [[NSURL alloc]
 ! ! ! initFileURLWithPath:captureMoviePath];
 }

 NSLog (@"recording to %@", captureMovieURL);
 [captureSession addOutput:captureMovieOutput];




Tuesday, November 15, 11
Cranking it up
               • -[AVCaptureSession startRunning] starts
                 capturing from all connected inputs

                    • If you have a preview layer, it will start
                      getting updated

               • File outputs do not start writing to filesystem
                 until you call startRecording on them



Tuesday, November 15, 11
Demo
         AVRecPlay




            http://dl.dropbox.com/u/12216224/conferences/vtm10/mastering-media-with-av-
                                    foundation/VTM_AVRecPlay.zip

Tuesday, November 15, 11
Orientation issues
               • Default orientation of an iOS device is portrait

               • The AVCaptureConnections between the
                 device inputs and the session have a read-
                 write videoOrientation property.

               • Capture layer's orientation property should
                 match



Tuesday, November 15, 11
Capture Processing
               • Analyzing or manipulating capture data as it
                 comes in

               • Audio: real-time effects ("I Am T-Pain"),
                 oscilloscopes, etc.

                    • May make more sense to use Audio Units

               • Video: bar code readers, face-finders, etc.


Tuesday, November 15, 11
Data Outputs
               • Connects your code to the capture session
                 via a delegate callback

               • Delegate callback occurs on a serial GCD
                 queue that you provide (can be
                 dispatch_get_main_queue(), should not be
                 dispatch_get_current_queue(), must not be
                 NULL).



Tuesday, November 15, 11
Creating the data
                                output

      AVCaptureVideoDataOutput *captureOutput =
      ! [[AVCaptureVideoDataOutput alloc] init];
      captureOutput.alwaysDiscardsLateVideoFrames =
      ! YES;
      [captureOutput setSampleBufferDelegate:self
      ! ! ! ! queue:dispatch_get_main_queue()];




Tuesday, November 15, 11
Configuring the data
                                output
     NSString* key =
     ! (NSString*)kCVPixelBufferPixelFormatTypeKey;
     NSNumber* value =
     ! [NSNumber numberWithUnsignedInt:
     ! ! kCVPixelFormatType_32BGRA];
     NSDictionary* videoSettings = [NSDictionary
     ! dictionaryWithObject:value forKey:key];
     [captureOutput setVideoSettings:videoSettings];




Tuesday, November 15, 11
Analyzing the data
               • You get the callback captureOutput:
                 didOutputSampleBuffer:fromConnection:

               • Second parameter is a CMSampleBufferRef,
                 Core Media's opaque type for sample buffers

                    • Could be video… could be audio… (but you
                      can tell from the connection and its input
                      and output ports)


Tuesday, November 15, 11
Analyzing frames with
                          Core Video
    CVImageBufferRef imageBuffer =
    ! CMSampleBufferGetImageBuffer(sampleBuffer);
    /*Lock the image buffer*/
    CVPixelBufferLockBaseAddress(imageBuffer,0);
    /*Get information about the image*/
    size_t bytesPerRow =
    ! CVPixelBufferGetBytesPerRow(imageBuffer);
    size_t width = CVPixelBufferGetWidth(imageBuffer);
    size_t height = CVPixelBufferGetHeight(imageBuffer);

           This example is from the ZXing barcode reader
                  http://code.google.com/p/zxing/
Tuesday, November 15, 11
Demo
         ZXing




                           http://code.google.com/p/zxing/

Tuesday, November 15, 11
Audio considerations
               • Can process CMSampleBufferRef by using
                 CMSampleBufferGetAudioStreamPacket
                 Descriptions() and CMSampleBufferGet
                 AudioBufferListWithRetainedBlockBuffer()

                    • Then use Core Audio call that take these types

               • May make more sense to just capture in Core Audio
                 in the first place, especially if you're playing
                 captured data through an audio queue or audio units



Tuesday, November 15, 11
Face Finding in
                         iOS 5

               • iOS 5 introduces Core Image, which allows us
                 to chain effects on images

               • Also includes some interesting image
                 processing classes




Tuesday, November 15, 11
CIDetector
               • Core Image class to find features in a Core
                 Image buffer

               • Only supported detector type in iOS 5 is
                 CIDetectorTypeFace

               • featuresInImage: returns an NSArray of all
                 detected features in the image



Tuesday, November 15, 11
Convert CM to CV to CI
         CVPixelBufferRef cvPixelBuffer =
         ! CMSampleBufferGetImageBuffer(sampleBuffer);
         CFDictionaryRef attachmentsDict =
         ! CMCopyDictionaryOfAttachments(
         ! ! kCFAllocatorSystemDefault,
         ! ! sampleBuffer,
         ! ! kCMAttachmentMode_ShouldPropagate);
         CIImage *ciImage = [[CIImage alloc]
         ! ! initWithCVPixelBuffer:cvPixelBuffer
         ! ! options:(__bridge NSDictionary*)
         ! ! ! ! attachmentsDict];


Tuesday, November 15, 11
Creating the CIDetector
      NSDictionary *faceDetectorDict =
      ! ! [NSDictionary dictionaryWithObjectsAndKeys:
      ! ! ! CIDetectorAccuracyHigh,
       ! ! ! CIDetectorAccuracy,
      ! ! ! nil];
      CIDetector *faceDetector =
        [CIDetector detectorOfType:CIDetectorTypeFace
                           context:nil
                           options:faceDetectorDict];
      NSArray *faces = [faceDetector
      ! ! ! featuresInImage:ciImage];



Tuesday, November 15, 11
Demo
         VTMFaceFinder




       http://dl.dropbox.com/u/12216224/conferences/vtm11/VTMFaceFinder.zip

Tuesday, November 15, 11
Boxing the faces

 for (CIFaceFeature *faceFeature in self.facesArray) {
   CGRect boxRect = CGRectMake(
     faceFeature.bounds.origin.x * self.scaleToApply,
     faceFeature.bounds.origin.y * self.scaleToApply,
     faceFeature.bounds.size.width * self.scaleToApply,
     faceFeature.bounds.size.height * self.scaleToApply);
   CGContextSetStrokeColorWithColor(cgContext,
     [UIColor yellowColor].CGColor);
   CGContextStrokeRect(cgContext, boxRect);
 }



Tuesday, November 15, 11
CIFaceFeature

               • Inherits bounds from CIFeature

               • Adds CGPoint properties leftEyePosition,
                 rightEyePosition, and mouthPosition (with
                 "has" properties for each of these)




Tuesday, November 15, 11
Image Processing on
                             the fly
               • New CVOpenGLESTextureCache makes it
                 possible to render Core Video buffers in real
                 time

                    • These are what you get in the callback

               • See ChromaKey example from WWDC 2011
                 session 419. Requires mad OpenGL ES skillz.



Tuesday, November 15, 11
Erica's "Face Pong"




Tuesday, November 15, 11
Recap
               • Start with an AVCaptureSession

               • Discover devices and create inputs

               • Create and configure outputs

               • Start the session

               • Start recording or wait to start handling
                 callbacks


Tuesday, November 15, 11
Recap: Easy parts
               • Basic capture apps (preview-only or record to
                 file) will require little or no Core Media or other
                 C APIs.

               • Default devices are usually the one you want
                 (back megapixel camera on the iPhone, best
                 available microphone, etc.)

               • Capture API is pretty easy to understand and
                 remember (compare to the editing API)


Tuesday, November 15, 11
Recap: Hard parts
               • Core Media calls require high comfort level
                 with C, Core Foundation, functions that take 8
                 or more parameters, etc.

               • Lots of bit-munging when you parse a CV
                 buffer (pixel formats, strides)

               • Callbacks do not have an infinite amount of
                 time or resources to finish their work


Tuesday, November 15, 11
Resources
               • devforums.apple.com

                    • No mailing list at lists.apple.com

               • WWDC session videos and slides (four in
                 2011, three in 2010)

               • Stack Overflow



Tuesday, November 15, 11
Q&A




                           Watch my blog for updated sample code:
                               http://www.subfurther.com/blog
                                        @invalidname

Tuesday, November 15, 11

More Related Content

What's hot

Kernel Recipes 2017 - What's inside the input stack? - Benjamain Tissoires
Kernel Recipes 2017 - What's inside the input stack? - Benjamain TissoiresKernel Recipes 2017 - What's inside the input stack? - Benjamain Tissoires
Kernel Recipes 2017 - What's inside the input stack? - Benjamain Tissoires
Anne Nicolas
 
London Video Tech - Adventures in cutting every last millisecond from glass-t...
London Video Tech - Adventures in cutting every last millisecond from glass-t...London Video Tech - Adventures in cutting every last millisecond from glass-t...
London Video Tech - Adventures in cutting every last millisecond from glass-t...
Kieran Kunhya
 
Supersize your production pipe enjmin 2013 v1.1 hd
Supersize your production pipe    enjmin 2013 v1.1 hdSupersize your production pipe    enjmin 2013 v1.1 hd
Supersize your production pipe enjmin 2013 v1.1 hd
slantsixgames
 

What's hot (20)

Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)
Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)
Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)
 
Master Video with AV Foundation
Master Video with AV FoundationMaster Video with AV Foundation
Master Video with AV Foundation
 
Get On The Audiobus (CocoaConf Boston, October 2013)
Get On The Audiobus (CocoaConf Boston, October 2013)Get On The Audiobus (CocoaConf Boston, October 2013)
Get On The Audiobus (CocoaConf Boston, October 2013)
 
Glitch-Free A/V Encoding (CocoaConf Boston, October 2013)
Glitch-Free A/V Encoding (CocoaConf Boston, October 2013)Glitch-Free A/V Encoding (CocoaConf Boston, October 2013)
Glitch-Free A/V Encoding (CocoaConf Boston, October 2013)
 
Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)
Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)
Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)
 
Utilizing AVFoundation at dubsmash
Utilizing AVFoundation at dubsmashUtilizing AVFoundation at dubsmash
Utilizing AVFoundation at dubsmash
 
How to Hack Edison
How to Hack EdisonHow to Hack Edison
How to Hack Edison
 
Embedded Objective-C
Embedded Objective-CEmbedded Objective-C
Embedded Objective-C
 
Video Meets Documentation
Video Meets DocumentationVideo Meets Documentation
Video Meets Documentation
 
Emulating With JavaScript
Emulating With JavaScriptEmulating With JavaScript
Emulating With JavaScript
 
Movi presentation Singapore video tech meetup
Movi presentation Singapore video tech meetupMovi presentation Singapore video tech meetup
Movi presentation Singapore video tech meetup
 
XS Oracle 2009 PV USB
XS Oracle 2009 PV USBXS Oracle 2009 PV USB
XS Oracle 2009 PV USB
 
Polstra 44con2012
Polstra 44con2012Polstra 44con2012
Polstra 44con2012
 
Kernel Recipes 2017 - The Serial Device Bus - Johan Hovold
Kernel Recipes 2017 - The Serial Device Bus - Johan HovoldKernel Recipes 2017 - The Serial Device Bus - Johan Hovold
Kernel Recipes 2017 - The Serial Device Bus - Johan Hovold
 
Kernel Recipes 2017 - What's inside the input stack? - Benjamain Tissoires
Kernel Recipes 2017 - What's inside the input stack? - Benjamain TissoiresKernel Recipes 2017 - What's inside the input stack? - Benjamain Tissoires
Kernel Recipes 2017 - What's inside the input stack? - Benjamain Tissoires
 
VMworld 2010 - Building an Affordable vSphere Environment for a Lab or Small ...
VMworld 2010 - Building an Affordable vSphere Environment for a Lab or Small ...VMworld 2010 - Building an Affordable vSphere Environment for a Lab or Small ...
VMworld 2010 - Building an Affordable vSphere Environment for a Lab or Small ...
 
1483 Quayle
1483 Quayle1483 Quayle
1483 Quayle
 
London Video Tech - Adventures in cutting every last millisecond from glass-t...
London Video Tech - Adventures in cutting every last millisecond from glass-t...London Video Tech - Adventures in cutting every last millisecond from glass-t...
London Video Tech - Adventures in cutting every last millisecond from glass-t...
 
Native IP Decoding MPEG-TS Video to Uncompressed IP (and Vice versa) on COTS ...
Native IP Decoding MPEG-TS Video to Uncompressed IP (and Vice versa) on COTS ...Native IP Decoding MPEG-TS Video to Uncompressed IP (and Vice versa) on COTS ...
Native IP Decoding MPEG-TS Video to Uncompressed IP (and Vice versa) on COTS ...
 
Supersize your production pipe enjmin 2013 v1.1 hd
Supersize your production pipe    enjmin 2013 v1.1 hdSupersize your production pipe    enjmin 2013 v1.1 hd
Supersize your production pipe enjmin 2013 v1.1 hd
 

Viewers also liked

Aprendendo o árabe saadeddine abou nimri
Aprendendo o árabe   saadeddine abou nimriAprendendo o árabe   saadeddine abou nimri
Aprendendo o árabe saadeddine abou nimri
UNIPLETRAS
 

Viewers also liked (16)

Fpga video capturing
Fpga video capturingFpga video capturing
Fpga video capturing
 
Programas de Capacitação - HBK Consultoria - 2013
Programas de Capacitação - HBK Consultoria - 2013Programas de Capacitação - HBK Consultoria - 2013
Programas de Capacitação - HBK Consultoria - 2013
 
Guerra fria
Guerra friaGuerra fria
Guerra fria
 
Bazele gastronomiei
Bazele gastronomieiBazele gastronomiei
Bazele gastronomiei
 
Tnt consulting
Tnt consultingTnt consulting
Tnt consulting
 
Igor
IgorIgor
Igor
 
Recife
RecifeRecife
Recife
 
Davidshallarnas egen grafiska profil
Davidshallarnas egen grafiska profilDavidshallarnas egen grafiska profil
Davidshallarnas egen grafiska profil
 
Digital Media Makeover Marketing Profs B2B Forum July 2011
Digital Media Makeover  Marketing Profs B2B Forum July 2011Digital Media Makeover  Marketing Profs B2B Forum July 2011
Digital Media Makeover Marketing Profs B2B Forum July 2011
 
Filosofia medieval 01 pimel 24
Filosofia medieval 01 pimel 24Filosofia medieval 01 pimel 24
Filosofia medieval 01 pimel 24
 
Desbobramento de um tema
Desbobramento de um temaDesbobramento de um tema
Desbobramento de um tema
 
Aprendendo o árabe saadeddine abou nimri
Aprendendo o árabe   saadeddine abou nimriAprendendo o árabe   saadeddine abou nimri
Aprendendo o árabe saadeddine abou nimri
 
História da Língua Portuguesa - APP
História da Língua Portuguesa - APPHistória da Língua Portuguesa - APP
História da Língua Portuguesa - APP
 
Locations
LocationsLocations
Locations
 
Security Digital Connect
Security Digital ConnectSecurity Digital Connect
Security Digital Connect
 
Filosofia ensino médio
Filosofia   ensino médioFilosofia   ensino médio
Filosofia ensino médio
 

More from Chris Adamson

Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
Core Audio in iOS 6 (CocoaConf San Jose, April 2013) Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
Chris Adamson
 
Core Audio in iOS 6 (CocoaConf DC, March 2013)
Core Audio in iOS 6 (CocoaConf DC, March 2013)Core Audio in iOS 6 (CocoaConf DC, March 2013)
Core Audio in iOS 6 (CocoaConf DC, March 2013)
Chris Adamson
 

More from Chris Adamson (20)

Whatever Happened to Visual Novel Anime? (AWA/Youmacon 2018)
Whatever Happened to Visual Novel Anime? (AWA/Youmacon 2018)Whatever Happened to Visual Novel Anime? (AWA/Youmacon 2018)
Whatever Happened to Visual Novel Anime? (AWA/Youmacon 2018)
 
Whatever Happened to Visual Novel Anime? (JAFAX 2018)
Whatever Happened to Visual Novel Anime? (JAFAX 2018)Whatever Happened to Visual Novel Anime? (JAFAX 2018)
Whatever Happened to Visual Novel Anime? (JAFAX 2018)
 
Media Frameworks Versus Swift (Swift by Northwest, October 2017)
Media Frameworks Versus Swift (Swift by Northwest, October 2017)Media Frameworks Versus Swift (Swift by Northwest, October 2017)
Media Frameworks Versus Swift (Swift by Northwest, October 2017)
 
Fall Premieres: Media Frameworks in iOS 11, macOS 10.13, and tvOS 11 (CocoaCo...
Fall Premieres: Media Frameworks in iOS 11, macOS 10.13, and tvOS 11 (CocoaCo...Fall Premieres: Media Frameworks in iOS 11, macOS 10.13, and tvOS 11 (CocoaCo...
Fall Premieres: Media Frameworks in iOS 11, macOS 10.13, and tvOS 11 (CocoaCo...
 
CocoaConf Chicago 2017: Media Frameworks and Swift: This Is Fine
CocoaConf Chicago 2017: Media Frameworks and Swift: This Is FineCocoaConf Chicago 2017: Media Frameworks and Swift: This Is Fine
CocoaConf Chicago 2017: Media Frameworks and Swift: This Is Fine
 
Forward Swift 2017: Media Frameworks and Swift: This Is Fine
Forward Swift 2017: Media Frameworks and Swift: This Is FineForward Swift 2017: Media Frameworks and Swift: This Is Fine
Forward Swift 2017: Media Frameworks and Swift: This Is Fine
 
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
 
Firebase: Totally Not Parse All Over Again (Unless It Is)
Firebase: Totally Not Parse All Over Again (Unless It Is)Firebase: Totally Not Parse All Over Again (Unless It Is)
Firebase: Totally Not Parse All Over Again (Unless It Is)
 
Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...
Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...
Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...
 
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
 
Stupid Video Tricks, CocoaConf Seattle 2014
Stupid Video Tricks, CocoaConf Seattle 2014Stupid Video Tricks, CocoaConf Seattle 2014
Stupid Video Tricks, CocoaConf Seattle 2014
 
Stupid Video Tricks, CocoaConf Las Vegas
Stupid Video Tricks, CocoaConf Las VegasStupid Video Tricks, CocoaConf Las Vegas
Stupid Video Tricks, CocoaConf Las Vegas
 
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
 
Stupid Video Tricks (CocoaConf DC, March 2014)
Stupid Video Tricks (CocoaConf DC, March 2014)Stupid Video Tricks (CocoaConf DC, March 2014)
Stupid Video Tricks (CocoaConf DC, March 2014)
 
Stupid Video Tricks
Stupid Video TricksStupid Video Tricks
Stupid Video Tricks
 
Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
Core Audio in iOS 6 (CocoaConf San Jose, April 2013) Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
 
Core Audio in iOS 6 (CocoaConf DC, March 2013)
Core Audio in iOS 6 (CocoaConf DC, March 2013)Core Audio in iOS 6 (CocoaConf DC, March 2013)
Core Audio in iOS 6 (CocoaConf DC, March 2013)
 
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)
 
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
 
Core Audio Intro (Detroit Mobile City 2013)
Core Audio Intro (Detroit Mobile City 2013)Core Audio Intro (Detroit Mobile City 2013)
Core Audio Intro (Detroit Mobile City 2013)
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Capturing Stills, Sounds, and Scenes with AV Foundation

  • 1. Capturing Stills, Sounds, and Scenes with AV Foundation Chris Adamson • @invalidname Voices That Matter: iOS Developer Conference Nov. 12, 2011 • Boston, MA Tuesday, November 15, 11
  • 2. Road Map • Media capture technologies in iOS • AV Foundation capture concepts • Device-specific concerns • Doing stuff with captured media Tuesday, November 15, 11
  • 3. Capture? • Digital media encoding of some real-world source, such as still images, moving images, and/or sound • Contrast with synthetic media: musical synthesizers, CG animation • Not the same as "recording", which implies storage • Capture devices include cameras and microphones Tuesday, November 15, 11
  • 5. Accessing Capture Devices • Simple shoot-and-save - UIImagePickerController • Core Audio - low level capture and real-time processing • More info in my talk tomorrow • AV Foundation Tuesday, November 15, 11
  • 6. AV Foundation • Introduced in iPhone OS 2.3 as Obj-C wrapper for Core Audio playback, added capture in 3.0 • Repurposed in iOS 4 as audio/video capture, editing, export, and playback framework • Ported to OS X in Lion, heir apparent to QuickTime Tuesday, November 15, 11
  • 7. #import this! • AVFoundation.framework • CoreMedia.framework • Possibly also: • CoreVideo, CoreImage, CoreGraphics • AudioToolbox, AudioUnits Tuesday, November 15, 11
  • 8. Core Media • C-based helper framework for AVF • Structures to represent media buffers and queues of buffers, media times and time ranges • Low-level conversion and calculation functions • Does not provide capture, editing, or playback functionality Tuesday, November 15, 11
  • 9. AV Foundation • Editing / Playback classes • Assets, compositions, and tracks. Player and player layer. Asset readers and writers • Capture classes • Devices, inputs, outputs, and the session Tuesday, November 15, 11
  • 10. How it fits together… Tuesday, November 15, 11
  • 13. AVCaptureDevice AVCaptureSession Tuesday, November 15, 11
  • 14. AVCaptureDevice AVCaptureInput AVCaptureSession Tuesday, November 15, 11
  • 15. AVCaptureDevice AVCaptureDevice AVCaptureInput AVCaptureSession Tuesday, November 15, 11
  • 16. AVCaptureDevice AVCaptureDevice AVCaptureInput AVCaptureInput AVCaptureSession Tuesday, November 15, 11
  • 17. AVCaptureDevice AVCaptureDevice AVCaptureInput AVCaptureInput AVCaptureVideo AVCaptureSession PreviewLayer Tuesday, November 15, 11
  • 18. AVCaptureDevice AVCaptureDevice AVCaptureInput AVCaptureInput AVCaptureVideo AVCaptureSession PreviewLayer AVCaptureOutput Tuesday, November 15, 11
  • 19. AVCaptureDevice AVCaptureDevice AVCaptureInput AVCaptureInput AVCaptureVideo AVCaptureSession PreviewLayer AVCaptureOutput Tuesday, November 15, 11
  • 20. AVCaptureDevice AVCaptureDevice AVCaptureInput AVCaptureInput AVCaptureVideo AVCaptureSession PreviewLayer AVCaptureOutput AVCaptureOutput Tuesday, November 15, 11
  • 21. AVCaptureDevice AVCaptureDevice AVCaptureInput AVCaptureInput AVCaptureVideo AVCaptureSession PreviewLayer AVCaptureOutput AVCaptureOutput Tuesday, November 15, 11
  • 22. AVCaptureSession • Coordinates the flow of capture from inputs to outputs • Create, add inputs and outputs, start running captureSession = [[AVCaptureSession alloc] init]; Tuesday, November 15, 11
  • 23. AVCaptureDevice • Represents a device that can perform media capture (cameras, microphones) • Could be connected as external accessory or Bluetooth • You cannot make assumptions based on device model Tuesday, November 15, 11
  • 24. Discovering Devices • AVCaptureDevice class methods devices, deviceWithUniqueID, devicesWithMediaType, defaultDeviceWithMediaType • Media types include audio, video, muxed (audio and video in one stream), plus some outliers (timecode, etc.) Tuesday, November 15, 11
  • 25. Inspecting Devices • position (property): is the camera on the front or the back? • supportsAVCaptureSessionPreset: allows you to inspect whether it can copy at one of several predefined image resolutions Tuesday, November 15, 11
  • 26. Photo traits • Focus & exposure • isFocusModeSupported:, focusMode, focusPointOfInterestSupported, focusPointOfInterest, focusAdjusting • isExposureModeSupported:, exposureMode, exposurePointOfInterestSupported, etc. • White balance • isWhiteBalanceModeSupported:, whiteBalanceMode, whiteBalanceModeAdjusting Tuesday, November 15, 11
  • 27. Light up • Flash and Torch • hasFlash, isFlashModeSupported: flashMode, flashActive, flashAvailable • hasTorch, isTorchModeSupported:, torchMode, torchLevel, torchAvailable Tuesday, November 15, 11
  • 28. AVCaptureSession sessionPreset • Constants for video capture quality. Allows you to inspect capabilities, trade performance/framerate for resolution • Default is AVCaptureSessionPresetHigh • For still photos: AVCaptureSessionPresetPhoto Tuesday, November 15, 11
  • 29. iFrame • Session presets for use when capturing video intended for subsequent editing • AVCaptureSessionPresetiFrame960x540, AVCaptureSessionPresetiFrame1280x720 • No P- or B-frames; files are much larger than typical H.264. http://en.wikipedia.org/wiki/Video_compression_picture_types Tuesday, November 15, 11
  • 30. Capture inputs • Connect a device to the capture session • Instances of AVCaptureDeviceInput • create with -initWithDevice:error: or deviceInputForDevice:error Tuesday, November 15, 11
  • 31. AVCaptureDevice *videoDevice = ! [AVCaptureDevice defaultDeviceWithMediaType: ! AVMediaTypeVideo]; if (videoDevice) { ! AVCaptureDeviceInput *videoInput = ! [AVCaptureDeviceInput ! ! deviceInputWithDevice:videoDevice ! ! ! ! ! ! ! ! error:&setUpError]; ! if (videoInput) { ! ! [captureSession addInput: videoInput]; ! } } Tuesday, November 15, 11
  • 32. Capture preview • AVCapturePreviewLayer: A CALayer that shows what's currently being captured from video input • Remember: CALayer, not UIView • videoGravity property determines how it will deal with preview that doesn't match bounds: aspect, fill, or resize Tuesday, November 15, 11
  • 33. AVCaptureVideoPreviewLayer *previewLayer = ! [AVCaptureVideoPreviewLayer ! ! layerWithSession:captureSession]; previewLayer.frame = captureView.layer.bounds; previewLayer.videoGravity = ! AVLayerVideoGravityResizeAspect; [captureView.layer addSublayer:previewLayer]; Tuesday, November 15, 11
  • 34. Capture Outputs • File output: AVCaptureMovieFileOutput and AVCaptureAudioFileOutput • Photo output: AVCaptureStillImageOutput • Image processing: AVCaptureDataOutput • More on this one later… Tuesday, November 15, 11
  • 35. AVCaptureFileOutput • startRecordingToOutputURL:recordingDelegate: • The delegate must be set and must implement two callbacks: • captureOutput:didStartRecordingToOutputFileAt  URL:fromConnections: • captureOutput:didFinishRecordingToOutputFileAt  URL:fromConnections: • Then connect to capture session Tuesday, November 15, 11
  • 36. captureMovieOutput = ! [[AVCaptureMovieFileOutput alloc] init]; if (! captureMovieURL) { ! captureMoviePath = [getCaptureMoviePath() retain]; ! captureMovieURL = [[NSURL alloc] ! ! ! initFileURLWithPath:captureMoviePath]; } NSLog (@"recording to %@", captureMovieURL); [captureSession addOutput:captureMovieOutput]; Tuesday, November 15, 11
  • 37. Cranking it up • -[AVCaptureSession startRunning] starts capturing from all connected inputs • If you have a preview layer, it will start getting updated • File outputs do not start writing to filesystem until you call startRecording on them Tuesday, November 15, 11
  • 38. Demo AVRecPlay http://dl.dropbox.com/u/12216224/conferences/vtm10/mastering-media-with-av- foundation/VTM_AVRecPlay.zip Tuesday, November 15, 11
  • 39. Orientation issues • Default orientation of an iOS device is portrait • The AVCaptureConnections between the device inputs and the session have a read- write videoOrientation property. • Capture layer's orientation property should match Tuesday, November 15, 11
  • 40. Capture Processing • Analyzing or manipulating capture data as it comes in • Audio: real-time effects ("I Am T-Pain"), oscilloscopes, etc. • May make more sense to use Audio Units • Video: bar code readers, face-finders, etc. Tuesday, November 15, 11
  • 41. Data Outputs • Connects your code to the capture session via a delegate callback • Delegate callback occurs on a serial GCD queue that you provide (can be dispatch_get_main_queue(), should not be dispatch_get_current_queue(), must not be NULL). Tuesday, November 15, 11
  • 42. Creating the data output AVCaptureVideoDataOutput *captureOutput = ! [[AVCaptureVideoDataOutput alloc] init]; captureOutput.alwaysDiscardsLateVideoFrames = ! YES; [captureOutput setSampleBufferDelegate:self ! ! ! ! queue:dispatch_get_main_queue()]; Tuesday, November 15, 11
  • 43. Configuring the data output NSString* key = ! (NSString*)kCVPixelBufferPixelFormatTypeKey; NSNumber* value = ! [NSNumber numberWithUnsignedInt: ! ! kCVPixelFormatType_32BGRA]; NSDictionary* videoSettings = [NSDictionary ! dictionaryWithObject:value forKey:key]; [captureOutput setVideoSettings:videoSettings]; Tuesday, November 15, 11
  • 44. Analyzing the data • You get the callback captureOutput: didOutputSampleBuffer:fromConnection: • Second parameter is a CMSampleBufferRef, Core Media's opaque type for sample buffers • Could be video… could be audio… (but you can tell from the connection and its input and output ports) Tuesday, November 15, 11
  • 45. Analyzing frames with Core Video CVImageBufferRef imageBuffer = ! CMSampleBufferGetImageBuffer(sampleBuffer); /*Lock the image buffer*/ CVPixelBufferLockBaseAddress(imageBuffer,0); /*Get information about the image*/ size_t bytesPerRow = ! CVPixelBufferGetBytesPerRow(imageBuffer); size_t width = CVPixelBufferGetWidth(imageBuffer); size_t height = CVPixelBufferGetHeight(imageBuffer); This example is from the ZXing barcode reader http://code.google.com/p/zxing/ Tuesday, November 15, 11
  • 46. Demo ZXing http://code.google.com/p/zxing/ Tuesday, November 15, 11
  • 47. Audio considerations • Can process CMSampleBufferRef by using CMSampleBufferGetAudioStreamPacket Descriptions() and CMSampleBufferGet AudioBufferListWithRetainedBlockBuffer() • Then use Core Audio call that take these types • May make more sense to just capture in Core Audio in the first place, especially if you're playing captured data through an audio queue or audio units Tuesday, November 15, 11
  • 48. Face Finding in iOS 5 • iOS 5 introduces Core Image, which allows us to chain effects on images • Also includes some interesting image processing classes Tuesday, November 15, 11
  • 49. CIDetector • Core Image class to find features in a Core Image buffer • Only supported detector type in iOS 5 is CIDetectorTypeFace • featuresInImage: returns an NSArray of all detected features in the image Tuesday, November 15, 11
  • 50. Convert CM to CV to CI CVPixelBufferRef cvPixelBuffer = ! CMSampleBufferGetImageBuffer(sampleBuffer); CFDictionaryRef attachmentsDict = ! CMCopyDictionaryOfAttachments( ! ! kCFAllocatorSystemDefault, ! ! sampleBuffer, ! ! kCMAttachmentMode_ShouldPropagate); CIImage *ciImage = [[CIImage alloc] ! ! initWithCVPixelBuffer:cvPixelBuffer ! ! options:(__bridge NSDictionary*) ! ! ! ! attachmentsDict]; Tuesday, November 15, 11
  • 51. Creating the CIDetector NSDictionary *faceDetectorDict = ! ! [NSDictionary dictionaryWithObjectsAndKeys: ! ! ! CIDetectorAccuracyHigh, ! ! ! CIDetectorAccuracy, ! ! ! nil]; CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:faceDetectorDict]; NSArray *faces = [faceDetector ! ! ! featuresInImage:ciImage]; Tuesday, November 15, 11
  • 52. Demo VTMFaceFinder http://dl.dropbox.com/u/12216224/conferences/vtm11/VTMFaceFinder.zip Tuesday, November 15, 11
  • 53. Boxing the faces for (CIFaceFeature *faceFeature in self.facesArray) { CGRect boxRect = CGRectMake( faceFeature.bounds.origin.x * self.scaleToApply, faceFeature.bounds.origin.y * self.scaleToApply, faceFeature.bounds.size.width * self.scaleToApply, faceFeature.bounds.size.height * self.scaleToApply); CGContextSetStrokeColorWithColor(cgContext, [UIColor yellowColor].CGColor); CGContextStrokeRect(cgContext, boxRect); } Tuesday, November 15, 11
  • 54. CIFaceFeature • Inherits bounds from CIFeature • Adds CGPoint properties leftEyePosition, rightEyePosition, and mouthPosition (with "has" properties for each of these) Tuesday, November 15, 11
  • 55. Image Processing on the fly • New CVOpenGLESTextureCache makes it possible to render Core Video buffers in real time • These are what you get in the callback • See ChromaKey example from WWDC 2011 session 419. Requires mad OpenGL ES skillz. Tuesday, November 15, 11
  • 56. Erica's "Face Pong" Tuesday, November 15, 11
  • 57. Recap • Start with an AVCaptureSession • Discover devices and create inputs • Create and configure outputs • Start the session • Start recording or wait to start handling callbacks Tuesday, November 15, 11
  • 58. Recap: Easy parts • Basic capture apps (preview-only or record to file) will require little or no Core Media or other C APIs. • Default devices are usually the one you want (back megapixel camera on the iPhone, best available microphone, etc.) • Capture API is pretty easy to understand and remember (compare to the editing API) Tuesday, November 15, 11
  • 59. Recap: Hard parts • Core Media calls require high comfort level with C, Core Foundation, functions that take 8 or more parameters, etc. • Lots of bit-munging when you parse a CV buffer (pixel formats, strides) • Callbacks do not have an infinite amount of time or resources to finish their work Tuesday, November 15, 11
  • 60. Resources • devforums.apple.com • No mailing list at lists.apple.com • WWDC session videos and slides (four in 2011, three in 2010) • Stack Overflow Tuesday, November 15, 11
  • 61. Q&A Watch my blog for updated sample code: http://www.subfurther.com/blog @invalidname Tuesday, November 15, 11