标签: avcapturesession

使用AVFoundation录制到电影文件时出错

这是一个奇怪的问题.我没有更改任何涉及此项目的代码,但我的视频录制已经随机停止工作.当我尝试将电影保存到文件时,我收到以下错误:

错误域= NSOSStatusErrorDomain代码= -12780"操作无法完成.(OSStatus错误-12780.)"

我使用以下代码开始捕获:

- (void)initVideoCapture {
self.captureSession = [[AVCaptureSession alloc] init];

AVCaptureDevice *videoCaptureDevice = [self frontFacingCameraIfAvailable];
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:nil];
[self.captureSession addInput:videoInput];

aMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];    
[self.captureSession addOutput:aMovieFileOutput];
[self detectVideoOrientation:aMovieFileOutput];

[self.captureSession setSessionPreset:AVCaptureSessionPresetMedium];

[self.captureSession startRunning];
Run Code Online (Sandbox Code Playgroud)

}

然后我从viewController调用此方法开始录制:

- (void) startRecord {
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyyMMddHHmmss"];
NSString *newDateString = [outputFormatter stringFromDate:[NSDate date]];
[outputFormatter release];

NSString * fileString = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mov",newDateString]];
recordFileURL = [[NSURL alloc] initFileURLWithPath:fileString];        

[aMovieFileOutput startRecordingToOutputFileURL:recordFileURL recordingDelegate:self];
Run Code Online (Sandbox Code Playgroud)

}

这时我在这个函数中得到了错误.

  • (void)captureOutput:(AVCaptureFileOutput*)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL*)outputFileURL …

video-capture avfoundation ios4 avcapturesession

2
推荐指数
1
解决办法
2145
查看次数

iOS相机应用程序,从前后切换相机时闪烁

我正在尝试模仿相机应用程序从前到后相机的过渡..它使用UIViewAnimationOptionTransitionFlipFromLeft ..

我目前的方法是使用前置摄像头拍摄照片,切换到后置摄像头,使用后置摄像头拍摄照片,将其加载到两个UIImageViews中并使用图像视图执行转换..(在此过程中隐藏当前的摄像头流)..

问题是,当我从前置摄像头切换到后置摄像头时,cameraView(一个AVCapturePreviewLayer)会在我隐藏它之前立即切换视图(这发生在最后一行的flipCameraToFront中.. [_captureSession commitConfiguration])...

希望这是有道理的,继承人的一些代码我省略了一些,如果你认为它会帮助我知道,我会发布其余部分.
任何帮助将不胜感激,谢谢

//class:RecordViewController
//iVars for this class..   
RecordVideoHandler *_recordHandler;
UIImage *_firstImageForFlip;
UIImage *_secondImageForFlip;
UIImageView *_firstImageViewForFlip;
BOOL isUsingFrontInput;
AVCaptureVideoPreviewLayer *_capturePreviewLayer;
UIView *_capturePreviewView;

- (void)doCameraFlip:(UIButton *)sender
{
    [_recordHandler addStillImageOutput];
    //This method calls imageReturned:(UIImage *)inImage;
    [_recordHandler captureAndReturnStillImage];


}   
- (void)imageReturned:(UIImage *)inImage{

    if(_firstImageForFlip == nil){
        [_capturePreviewLayer setFrame:CGRectZero];
        _firstImageForFlip = inImage;
        _firstImageViewForFlip = [[UIImageView alloc] initWithImage:_firstImageForFlip];


        if(isUsingFrontInput)
            [_firstImageViewForFlip setTransform:CGAffineTransformMakeScale(-1.0, 1.0)];


        [_firstImageViewForFlip setFrame:_capturePreviewView.bounds];
        [_capturePreviewView addSubview:_firstImageViewForFlip];


        if(isUsingFrontInput){
            [_recordHandler flipCameraToBack];
        }else{
            [_recordHandler flipCameraToFront];
        }
        [_recordHandler captureAndReturnStillImage];
    }else{
        _secondImageForFlip = inImage;
        [_recordHandler removeStillImageOutput]; …
Run Code Online (Sandbox Code Playgroud)

camera ios avcapturesession

2
推荐指数
1
解决办法
3350
查看次数

AVCaptureSession启动内存警告

每次我启动AVCaptureSession时都会收到内存警告,导致一段时间后崩溃.
我正在异步启动会话,而Instruments工具说该应用程序消耗大约2 MB的内存.你知道如何克服这个问题吗?2MB分配的内存太多了吗?

Thankx![iOS 4.3,ARC]

@autoreleasepool {
    //Init capture session
    session = [[AVCaptureSession alloc] init];
    session.sessionPreset = AVCaptureSessionPresetPhoto;


    //Resize container view
    CGRect cameraContainerFrame = cameraContainerView.frame;
    cameraContainerFrame.size = CGSizeMake(320, 426);
    cameraContainerView.frame = cameraContainerFrame;

    CALayer *viewLayer = [cameraContainerView layer];
    [viewLayer setMasksToBounds:YES];

    //Create preview layer
    captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

    CGRect bounds = [cameraContainerView bounds];
    [captureVideoPreviewLayer setFrame:bounds];


    if ([captureVideoPreviewLayer isOrientationSupported]) {
        [captureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait];
    }    
    [captureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

    [viewLayer addSublayer:captureVideoPreviewLayer];

    //Get input device
    captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

    if ([captureDevice lockForConfiguration:nil]){
        captureDevice.focusMode = AVCaptureFocusModeContinuousAutoFocus;
        captureDevice.whiteBalanceMode = …
Run Code Online (Sandbox Code Playgroud)

memory-management objective-c ios avcapturesession

2
推荐指数
1
解决办法
1616
查看次数

AVFoundation - 如何将AVCaptureMovieFileDataOutput保存到文件中?

我一直在阅读AV基金会编程指南.特别是我一直试图让"媒体捕获"部分的"全部放在一起"部分工作.我对本教程中的代码进行了一些小的更改,但没有什么应该产生太大的影响.我对它如何从AVCaptureMovieFileDataOutput实际保存电影文件感到困惑.我使用以下内容设置捕获会话:

//Create session.
AVCaptureSession *session = [[AVCaptureSession alloc] init];

//Set preset to low.
if ([session canSetSessionPreset:AVCaptureSessionPresetLow]) {
    session.sessionPreset = AVCaptureSessionPresetLow;
}
else {
    // Handle the failure.
}

//Get camera device.
AVCaptureDevice *device =
[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

NSError *error = nil;
AVCaptureDeviceInput *input =
[AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
    //Handle the error appropriately.
}
[session addInput:input];

//Create output.
AVCaptureMovieFileOutput *output = [[AVCaptureMovieFileOutput alloc] init];
[session addOutput:output];

[session startRunning];
Run Code Online (Sandbox Code Playgroud)

我可能只是在开发人员文档中遗漏了一些我没有看到的内容,但我还没有看到如何实际获取会话来创建文件.有什么建议?非常感谢!

objective-c avfoundation ios avcapturesession avcapturemoviefileoutput

2
推荐指数
2
解决办法
3921
查看次数

AVCam保存全屏捕获的图像

我使用苹果公司制作的AVCam作为我的自定义相机视图.老实说,AVCamViewController如果你第一次看到它,那么理解课堂上发生的事情并不简单.

现在我感兴趣他们如何设置捕获图像的帧.我试图找到一些名人或类似的东西,但我没有找到任何.

我在谷歌搜索,发现AVCam的答案不在全屏

但是当我实现该解决方案时,我才意识到它只是制作了与我的视图相同大小的实时相机预览图层,但是当应用程序将图像保存- (IBAction)snapStillImage:(id)sender在图库中的方法中时,图像仍然是左右两个条纹.

我的问题是如何删除此条纹或源代码中的哪一行苹果设置这个东西?

另外作为额外的子问题我如何设置类型创建只是照片,因为该应用程序请求我"麦克风设置",我不需要它只需要拍一张照片,就是这样.

来自apple源的此代码将图像保存到照片库.

- (IBAction)snapStillImage:(id)sender
{
    dispatch_async([self sessionQueue], ^{
        // Update the orientation on the still image output video connection before capturing.
        [[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];

        // Flash set to Auto for Still Capture
        [AVCamViewController setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];

        // Capture a still image.
        [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {

            if (imageDataSampleBuffer)
            {
                NSData *imageData = [AVCaptureStillImageOutput …
Run Code Online (Sandbox Code Playgroud)

objective-c ios avcapturesession avcam

2
推荐指数
1
解决办法
1564
查看次数

如何在Swift2和Xcode7 beta中添加用于capturesession的输入设备?

我正在按照本教程制作相机应用程序,但是教程是在Swift中,我正在使用Xcode 7 beta和Swift2.

http://jamesonquave.com/blog/taking-control-of-the-iphone-camera-in-ios-8-with-swift-part-1/

我听说Swift2现在有一个不同的错误处理方法,所以我想这部分代码需要改变.但我不确定如何.谁能帮我这个?谢谢!

var err : NSError? = nil
        captureSession.addInput(AVCaptureDeviceInput(device: captureDevice, error: &err))

        if err != nil {
            println("error: \(err?.localizedDescription)")
        }
Run Code Online (Sandbox Code Playgroud)

device avfoundation ios avcapturesession swift2

2
推荐指数
1
解决办法
2194
查看次数

AVCaptureSession VS UIImagePickerController相机预览

我正在开发类似于Instagram iOS应用程序的应用程序.Instagram有自定义相机预览.我想开发类似的东西,问题是 - 为此目的更好地使用什么 - 具有自定义cameraOverlayView属性的UIImagePickerController还是应该使用AVCaptureSession?也许有人有这样的经历,可以给我一个建议.将不胜感激.

preview uiimagepickercontroller ios avcapturesession camera-overlay

2
推荐指数
1
解决办法
1233
查看次数

在前后摄像头之间切换

我正在尝试制作一个自定义的cameraView,它到目前为止一直有效.但是我在前后摄像头之间切换时遇到了问题.我试图通过自定义枚举来处理它.但是当switchCamera调用该方法时.它似乎冻结相机?那怎么样?

相机变量

var camera = CameraType.Back
Run Code Online (Sandbox Code Playgroud)

viewDidLoad中

    switchButton = UIButton(frame: CGRectMake(rightButtonXPoint, 35, 30, 30))
    switchButton.setImage(UIImage(named: "Switch"), forState: UIControlState.Normal)
    switchButton.addTarget(self, action: "switchCamera", forControlEvents: UIControlEvents.TouchUpInside)
    actionView.addSubview(switchButton)
Run Code Online (Sandbox Code Playgroud)

viewWillAppear中

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    reloadCamera()


}
Run Code Online (Sandbox Code Playgroud)

SwitchCamera

func switchCamera() {

    if camera == CameraType.Back {
        camera = CameraType.Front
    } else {
        camera = CameraType.Back
    }
    reloadCamera()
}
Run Code Online (Sandbox Code Playgroud)

ReloadCamera

func reloadCamera() {

    captureSession = AVCaptureSession()


   // let backCamera = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
    var captureDevice:AVCaptureDevice! = nil
    if (camera == CameraType.Front) {
        let videoDevices = …
Run Code Online (Sandbox Code Playgroud)

ios avcapturesession swift

2
推荐指数
1
解决办法
2067
查看次数

AVCaptureSession和预览层无法填满整个屏幕

所以,我试图用相机我的手机在我的应用程序,我是成功的,但不幸的是,使用预览时,该层不填充整个屏幕下面是一个图像向您展示它是什么样子

这是我的代码:

if let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) {
        self.previewLayer = previewLayer
        self.view.layer.addSublayer(self.previewLayer)
        self.previewLayer.frame = self.view.layer.frame
        captureSession.startRunning()

        let dataOutput = AVCaptureVideoDataOutput()
        dataOutput.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString):NSNumber(value:kCVPixelFormatType_32BGRA)]

        dataOutput.alwaysDiscardsLateVideoFrames = true

        if captureSession.canAddOutput(dataOutput) {
            captureSession.addOutput(dataOutput)
        }

        captureSession.commitConfiguration()


        let queue = DispatchQueue(label: "com.Osmo.captureQueue")
        dataOutput.setSampleBufferDelegate(self, queue: queue)
    }
Run Code Online (Sandbox Code Playgroud)

avfoundation ios avcapturesession swift3

2
推荐指数
2
解决办法
2524
查看次数

使用相机应用程序拍摄方形照片

我目前正在构建一个相机应用程序,并希望让相机像 Instagram 一样拍摄 375x375 的方形图像并像这样保存。

我能够调整相机的取景器,但它没有以正确的方式拍摄照片,而且当我保存它时,它会以全视图方式保存它。我环顾了那里的其他问答,但似乎没有一个适用于我的代码。

有人可以帮我解决这个问题。

import Foundation
import UIKit
import AVFoundation

class CameraViewController: UIViewController{

var captureSession = AVCaptureSession()
var frontCameraDeviceInput: AVCaptureDeviceInput?
var backCameraDeviceInput: AVCaptureDeviceInput?
var currentCamera: AVCaptureDevice?

var photoOutput: AVCapturePhotoOutput?

var cameraPreviewLayer: AVCaptureVideoPreviewLayer?

var image: UIImage?

override func viewDidLoad() {
    super.viewDidLoad()

    setupCaptureSession()
    setupDevice()
    setupInputOutput()
    setupPreviewLayer()
    startRunningCaptureSession()
}

func setupCaptureSession() {
    captureSession.sessionPreset = AVCaptureSession.Preset.photo
}

func setupDevice() {
    let frontCamera = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front)
    let backCamera = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back)

    frontCameraDeviceInput = try? AVCaptureDeviceInput(device: frontCamera!) …
Run Code Online (Sandbox Code Playgroud)

avfoundation avcapturesession swift

2
推荐指数
1
解决办法
2583
查看次数