Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8137213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:02:03+00:00 2026-06-06T11:02:03+00:00

I am trying to implement video capture in my app using AVFoundation. I have

  • 0

I am trying to implement video capture in my app using AVFoundation. I have the following code under viewDidLoad:

session = [[AVCaptureSession alloc] init];
movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
videoInputDevice = [[AVCaptureDeviceInput alloc] init];
AVCaptureDevice *videoDevice = [self frontFacingCameraIfAvailable];

if (videoDevice)
{
    NSError *error;

    videoInputDevice = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];

    if (!error)
    {
        if ([session canAddInput:videoInputDevice])
            [session addInput:videoInputDevice];
        else 
            NSLog (@"Couldn't add input.");
    }

}


AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
NSError *audioError = nil;
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&audioError];

if (audioInput)
{
    [session addInput:audioInput];
}

movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];

Float64 TotalSeconds = 35;          //Total seconds
int32_t preferredTimeScale = 30;    //Frames per second
CMTime maxDuration = CMTimeMakeWithSeconds(TotalSeconds, preferredTimeScale);   
movieFileOutput.maxRecordedDuration = maxDuration;

movieFileOutput.minFreeDiskSpaceLimit = 1024 * 1024;                        

if ([session canAddOutput:movieFileOutput])
    [session addOutput:movieFileOutput];

[session setSessionPreset:AVCaptureSessionPresetMedium];
if ([session canSetSessionPreset:AVCaptureSessionPreset640x480])        //Check size based configs are supported before setting them
    [session setSessionPreset:AVCaptureSessionPreset640x480];

[self cameraSetOutputProperties];


[session startRunning];

This code is in the implementation for a button that is to start the capture, among other things:

NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"];
NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:outputPath])
{
    NSError *error;
    if ([fileManager removeItemAtPath:outputPath error:&error] == NO)
    {
        //Error - handle if requried
    }
}
[outputPath release];
//Start recording
[movieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
[outputURL release];

When I try to run it on a device, it crashes when I try to load the view that all of this is supposed to happen on. Xcode gives me a “Thread 1: EXC_BAD_ACCESS (code=1, address=0x4) at:

AVFoundation`-[AVCaptureDeviceInput _setDevice:]:
(stuff)
0x3793f608:  ldr    r0, [r1, r0]

The error is given at that last line. I assume this has something to do with the AVCaptureDeviceInput somewhere, but I am blanking on what it could be. Does anyone have any idea what I am missing here? Thanks.

Edit: After fiddling with breakpoints, I’ve figured out that the crash happens at this line:

AVCaptureDevice *videoDevice = [self frontFacingCameraIfAvailable];

So something to do with that method? Here’s the implementation file that I have for it, maybe something is wrong there.

NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *captureDevice = nil;
for (AVCaptureDevice *device in videoDevices)
{
    if (device.position == AVCaptureDevicePositionFront)
    {
        captureDevice = device;
        break;
    }
}

//  couldn't find one on the front, so just get the default video device.
if ( ! captureDevice)
{
    captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
}

return captureDevice;

Edit 2: Could it maybe be that I am using

AVCaptureDevice *videoDevice = [self frontFacingCameraIfAvailable];

and the ‘self’ is throwing a wrench in it somehow? I know that when creating a CALayer it is possible to do

CALayer *aLayer = [CALayer layer];

but I don’t know the AVCaptureDevice equivalent of this, if there is one. I am not sure what else it could be, by all accounts my code seems fine and I’ve tried cleaning the project, restarting Xcode, restarting the computer, etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:02:07+00:00Added an answer on June 6, 2026 at 11:02 am

    I’m pretty sure the problem is that you’re running the program on the simulator. The simulator can’t use those resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement HTML5 Video in a site and for that I'm using
I'm trying to build/implement a Flash video player to play videos. I have looked
I am trying to displaying a ProgressDialog before a video with the following code:
i am new to AVFoundation and i am trying to implement a video camera
I am now trying to implement a app like picking image and video from
I'm trying to get the RTSP video stream play in my Android App using
I am trying to implement video into my app and I am having a
I am trying to implement following: How can I start a flash video from
I'm trying to implement jQuery Flare Video Plugin for my website.. There's a dropdown
Trying to implement google C2DM service. registrationIntent.putExtra(app, PendingIntent.getBroadcast(context,0,new Intent(), 0)); registrationIntent.putExtra(sender,example@gmail.com); context.startService(registrationIntent); Almost every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.