Note that there are some explanatory texts on larger screens.

plurals
  1. POAVCaptureMovieFileOutput -- trimming the file while writing
    primarykey
    data
    text
    <p>I am recording video using <code>AVCaptureMovieFileOutput</code>. Instead of retaining the captured video for the entire recording time, however, I would like only to retain the last 2 minutes of video. In essence, I would like to create a trailing buffer of video.</p> <p>I have tried to implement this by setting <code>movieFragmentInterval</code> equal to 15 seconds. As these 15 seconds buffered, the first 15 seconds of the MOV file would be trimmed off using this code:</p> <pre><code>//This would be called 7 seconds after the video stream started buffering. -(void)startTrimTimer { trimTimer = [NSTimer scheduledTimerWithTimeInterval:15 target:self selector:@selector(trimFlashbackBuffer) userInfo:nil repeats:YES]; } -(void)trimFlashbackBuffer { //make sure that there is enough video before trimming off 15 seconds if(trimReadyCount&lt;3){ trimReadyCount++; return; } AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/flashbackBuffer.MOV",tripDirectory]] options:nil]; AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:videoAsset presetName:AVAssetExportPresetHighestQuality]; exportSession.outputURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/flashbackBuffer.MOV",tripDirectory]]; exportSession.outputFileType = AVFileTypeQuickTimeMovie; CMTimeRange timeRange = CMTimeRangeMake(CMTimeMake(15000, 1000), CMTimeMake(120000, 1000)); exportSession.timeRange = timeRange; [exportSession exportAsynchronouslyWithCompletionHandler:^{ switch (exportSession.status) { case AVAssetExportSessionStatusCompleted: // Custom method to import the Exported Video [self loadAssetFromFile:exportSession.outputURL]; break; case AVAssetExportSessionStatusFailed: // NSLog(@"Failed:%@",exportSession.error); break; case AVAssetExportSessionStatusCancelled: // NSLog(@"Canceled:%@",exportSession.error); break; default: break; } }]; } </code></pre> <p>However, I am receiving the following error every time <code>trimFlashbackBuffer</code> is called:</p> <pre><code>Failed:Error Domain=AVFoundationErrorDomain Code=-11823 "Cannot Save" UserInfo=0x12e710 {NSLocalizedRecoverySuggestion=Try saving again., NSLocalizedDescription=Cannot Save} </code></pre> <p>Is this because the file is already being written to by <code>AVCaptureMovieFileOutput</code>?</p> <p>How could I achieve the effect of a seamless trailing video buffer, if this method cannot work?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload