AVCaptureSession Pause and Resume recording

坚强是说给别人听的谎言 提交于 2019-12-07 09:20:04

问题


I am making a movie app for iOS 5.0 using AVCaptureSession. I am giving the user ability to start-pause-start-stop recording a movie

The three buttons that I have defined are

  • Start Recording

  • Stop Recording

  • Pause Recording

I am able to successfully start & stop a recording. What I am unable to do is pause a recording and then resume it again. I looked at this question/answer on stack overflow but I have no idea how are they pausing and resuming the video? I did find some other posts here but none of them have any sample code that I can use to try it out. If AVAssetWrtier is the way to go how do you use it with AVCaptureSession?

ios - Pause video recording

Pause & resume video capture for same file with AVFoundation in iOS

Here is my code for three buttons

        -(IBAction) makeMovieNow
        {
            NSLog(@"makeMovieNow ...");

[session startRunning];
            [movieFileOutput startRecordingToOutputFileURL:movieURL recordingDelegate:self];

        }

    -(IBAction) makeMovieStop
    {
        NSLog(@"makeMovieStop ...");

        //stop recording
        [session stopRunning];
    }

    -(IBAction) makeMoviePause
    {
        NSLog(@"makeMoviePause ...");

        //pause video??? How?

    }

//********** DID FINISH RECORDING TO OUTPUT FILE AT URL **********
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
      fromConnections:(NSArray *)connections
                error:(NSError *)error
{

    NSLog(@"didFinishRecordingToOutputFileAtURL - enter");

    BOOL RecordedSuccessfully = YES;
    if ([error code] != noErr)
    {
        NSLog(@"ERROR RECODING MOVIE!!! - enter");

        // A problem occurred: Find out if the recording was successful.
        id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey];
        if (value)
        {
            RecordedSuccessfully = [value boolValue];
        }
    }
    if (RecordedSuccessfully)
    {
        //----- RECORDED SUCESSFULLY -----
        NSLog(@"didFinishRecordingToOutputFileAtURL - success");

        UISaveVideoAtPathToSavedPhotosAlbum(videoPath2, self, nil, nil);    

    }
}

回答1:


There's a sample iPhone at http://www.gdcl.co.uk/2013/02/20/iPhone-Pause.html that does exactly this. It uses a Data Output instead of a Movie File Output so that the data is passed to the app. The app then passes the sample to an AVAssetWriter if recording is enabled, and after a pause/resume, the timestamps are adjusted to remove the pause.

G




回答2:


I ended up creating two files and merged them together. Here is the sample code and tutorial

http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios



来源:https://stackoverflow.com/questions/15097320/avcapturesession-pause-and-resume-recording

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!