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 4548752
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:15:52+00:00 2026-05-21T16:15:52+00:00

I made an app with a feature to capture and save video. I have

  • 0

I made an app with a feature to capture and save video.
I have used AVFoundation for that and Apple’s AVCam has been my guide.

I hope I can make it clear:
Everything works fine until I release the videoViewController that handles the AVCamCaptureManager for the first time (In AVCam that would be AVCamViewController). After that when I create it again, the video freezes right after camera switch. Even re-run will not help, nor will clean, or device reset. (Sometimes one of the things help, but it is not a rule).

I release the videoViewController when not needed to save memory.

Code for switching the camera is basically the same as in AVCam:

NSError *error;
AVCaptureDeviceInput *newVideoInput;
AVCaptureDevicePosition position = currentVideoInput.device.position;

if (position == AVCaptureDevicePositionBack)
    newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:frontFacingCamera error:&error];
else if (position == AVCaptureDevicePositionFront)
    newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error];

if (newVideoInput != nil) {
    [session beginConfiguration];
    [session removeInput:currentVideoInput];
    if ([session canAddInput:newVideoInput]) {
        [session addInput:newVideoInput];
        [self setVideoInput:newVideoInput];
} else {
    [session addInput:currentVideoInput];
}
    [session commitConfiguration];
    [newVideoInput release];
} else if (error) {
    NSLog(@"%@",[error localizedDescription]);
}

Code with which I dismiss videoView

[self.videoViewController.view removeFromSuperview];
self.videoViewController = nil;

My current “workaround” is to simply leave it be, even if I do not need it.

Can someone explain why is this happening and how to solve it.

EDIT: Solved
As W Dyson pointed out in his response I should have stopped the session before releasing my videoViewController like so:

[[[self.videoViewController captureManager] session] stopRunning];
[self.videoViewController.view removeFromSuperview];
self.videoViewController = nil;

Thanks W Dyson.

  • 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-05-21T16:15:53+00:00Added an answer on May 21, 2026 at 4:15 pm

    Are you getting error logs? If not, you need to fix the code above and see what they say.
    What version of AVCam are you using? They’ve recently updated the project to version 1.2, which is much more efficient and uses blocks.

    From my experience, you shouldn’t be creating and recreating a session, you can just leave it on. Maybe you need to structure your app a little differently. What exactly is your app about? Maybe we can help you. If your app is centred around the camera, then it’s easier to leave the session on, if your just taking video modally, then maybe using AVCam is overkill.

    Your actual problem, to me, sounds like it’s with AVCaptureDeviceInput. Download the original AVCam package and see if you’ve changed any retain counts, or safety if statements. If there’s any other code, please post.

    UPDATE: Can you change

    } else if (error) {
        NSLog(@"%@",[error localizedDescription]);
    }
    

    to

    } if (error) {
        NSLog(@"%@",[error localizedDescription]);
    }
    

    and tell me if there’s an error?

    Also, before you release the view controller that owns the session, make sure you stop the session and set the capture manager to nil.

    UPDATE 2: Try this toggle code. It’s what I have been using. AVCamMirringMode is a struct as follows:

    enum {
        AVCamMirroringOff   = 1,
        AVCamMirroringOn    = 2,
        AVCamMirroringAuto  = 3
    };
    typedef NSInteger AVCamMirroringMode;
    
    
    - (BOOL) toggleCamera
    {
        BOOL success = NO;
    
        if ([self cameraCount] > 1) {
            NSError *error;
            AVCaptureDeviceInput *newVideoInput;
            AVCaptureDevicePosition position = [[videoInput device] position];
    
            BOOL mirror;
            if (position == AVCaptureDevicePositionBack){
                newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self frontFacingCamera] error:&error];
                switch ([self mirroringMode]) {
                    case AVCamMirroringOff:
                        mirror = NO;
                        break;
                    case AVCamMirroringOn:
                        mirror = YES;
                        break;
                    case AVCamMirroringAuto:
                    default:
                        mirror = YES;
                        break;
                }
            }
            else if (position == AVCaptureDevicePositionFront){
                newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self backFacingCamera] error:&error];
                switch ([self mirroringMode]) {
                    case AVCamMirroringOff:
                        mirror = NO;
                        break;
                    case AVCamMirroringOn:
                        mirror = YES;
                        break;
                    case AVCamMirroringAuto:
                    default:
                        mirror = NO;
                        break;
                }
            }
            else
                goto bail;
    
            if (newVideoInput != nil) {
                [[self session] beginConfiguration];
                [[self session] removeInput:[self videoInput]];
                if ([[self session] canAddInput:newVideoInput]) {
                    [[self session] addInput:newVideoInput];
                    AVCaptureConnection *connection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
                    if ([connection isVideoMirroringSupported]) {
                        [connection setVideoMirrored:mirror];
                    }
                    [self setVideoInput:newVideoInput];
                } else {
                    [[self session] addInput:[self videoInput]];
                }
                [[self session] commitConfiguration];
                success = YES;
                [newVideoInput release];
    
            } else if (error) {
                if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) {
                    [[self delegate] captureManager:self didFailWithError:error];
                }
            }
        }
    
    bail:
        return success;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been support a web app that is used by a user base
I have made an app that gets an array of addresses from a web
I have made an app that implements the iPhone's camera. When the user finishes
I have made a winform app where i have used vectors of array[n][n] type
I have a rails app (running on version 2.2.2) that has a model called
I have made a testing application for In-app Billing, For testing the feature of
I have an App made with phonegap (Cordova 1.5). The audio is in wav
I've made an app in C++ that uses mysql to connect to a server,
I've made an app that displays a menu of a restaurant (in a tableview).
This is the case: I made an app using the Audio Streamer library that

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.