IOS Camera captureOutput buffer




//
//  Camera.h
//  VideoPlayback
//
//  Created by Mac on 14-10-31.
//  Copyright (c) 2014年 fly. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@interface Camera : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate>
{
    AVCaptureDevice *avCaptureDevice;
    AVCaptureSession* _session;
}
- (void)setupCaptureSession;
-(void)stopcamera;
@end

//
//  Camera.m
//  VideoPlayback
//
//  Created by Mac on 14-10-31.
//  Copyright (c) 2014年 fly. All rights reserved.
//

#import "Camera.h"

@implementation Camera

- (AVCaptureDevice *)getFrontCamera
{
    //获取前置摄像头设备
    NSArray *cameras = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    for (AVCaptureDevice *device in cameras)
    {
        if (device.position == AVCaptureDevicePositionBack)
            return device;
    }
    return [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    
}

// Create and configure a capture session and start it running
- (void)setupCaptureSession
{
    //-- Create CVOpenGLESTextureCacheRef for optimal CVImageBufferRef to GLES texture conversion.
/*#if COREVIDEO_USE_EAGLCONTEXT_CLASS_IN_API
    CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, glContext, NULL, &_videoTextureCache);
#else
    CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, (__bridge void *)glContext, NULL, &_videoTextureCache);
#endif
    if (err)
    {
        NSLog(@"Error at CVOpenGLESTextureCacheCreate %d", err);
        return;
    }*/
    
    //-- Setup Capture Session.
    _session = [[AVCaptureSession alloc] init];
    [_session beginConfiguration];
    
    //-- Set preset session size.
    [_session setSessionPreset:AVCaptureSessionPreset640x480];
    
    //-- Creata a video device and input from that Device.  Add the input to the capture session.
    AVCaptureDevice * videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if(videoDevice == nil)
        assert(0);
    
    //-- Add the device to the session.
    NSError *error;
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
    if(error)
        assert(0);
    
    [_session addInput:input];
    
    //-- Create the output for the capture session.
    AVCaptureVideoDataOutput * dataOutput = [[AVCaptureVideoDataOutput alloc] init];
    [dataOutput setAlwaysDiscardsLateVideoFrames:YES]; // Probably want to set this to NO when recording
    
    //-- Set to YUV420.
    [dataOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange]
                                                             forKey:(id)kCVPixelBufferPixelFormatTypeKey]]; // Necessary for manual preview
    
    // Set dispatch to be on the main thread so OpenGL can do things with the data
    [dataOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
    
    [_session addOutput:dataOutput];
    [_session commitConfiguration];
    
    [_session startRunning];
}

#pragma mark -
#pragma mark AVCaptureVideoDataOutputSampleBufferDelegate
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
    CVReturn err;
    CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
    size_t width = CVPixelBufferGetWidth(pixelBuffer);
    size_t height = CVPixelBufferGetHeight(pixelBuffer);
    NSLog(@"captureOutput");
}

-(void)stopcamera
{
    [_session stopRunning];
}

@end


Virtual Camera for iOSiOS虚拟相机) 虚拟相机是一种在iOS设备上模拟相机功能的应用程序。它允许用户通过软件模拟相机的操作和功能,拍摄照片和录制视频,并进行相关的编辑和处理。 iOS虚拟相机的主要功能包括: 1. 拍摄照片:用户可以通过虚拟相机应用程序在iOS设备上拍摄照片,体验与实际相机相似的拍摄流程,包括对焦、曝光和拍摄模式的调整。 2. 录制视频:用户可以使用虚拟相机录制视频,选择不同的分辨率和帧率,实现高质量的视频录制。 3. 增强功能:虚拟相机通常具备滤镜、特效、画面裁剪和调整等功能,用户可以对拍摄的照片和视频进行编辑和美化。 4. 分享与保存:虚拟相机还可以方便地分享拍摄的照片和视频到社交媒体平台,或保存到本地相册中,方便用户管理和使用。 虚拟相机对于iOS设备的用户来说,具有以下几个优势: 1. 便携性:相比传统相机设备,虚拟相机应用程序可以直接安装在iOS设备上,随时随地使用,方便快捷。 2. 灵活性:虚拟相机通常具备多种拍摄模式和编辑功能,用户可以根据需求进行选择和调整,实现个性化的拍摄和编辑体验。 3. 节省成本:相比购买专业相机设备,虚拟相机应用程序通常是免费或付费较低,节省了成本。 4. 社交化:虚拟相机应用程序连接了用户与社交媒体的桥梁,用户可以轻松地与朋友分享拍摄的照片和视频。 综上所述,虚拟相机为iOS用户提供了一种方便、灵活和具有个性化的拍摄和编辑体验,使拍摄照片和录制视频变得更加有趣和便捷。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值