Note that there are some explanatory texts on larger screens.

plurals
  1. POConsecutive calls to startRecordingToOutputFileURL:
    primarykey
    data
    text
    <p><a href="http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVCaptureFileOutput_Class/Reference/Reference.html" rel="noreferrer">The Apple docs</a> seem to indicate that while recording video to a file, the app can change the URL on the fly with no problem. But I'm seeing a problem. When I try this, the recording delegate gets called with an error...</p> <blockquote> <p>The operation couldn’t be completed. (OSStatus error -12780.) Info dictionary is: { AVErrorRecordingSuccessfullyFinishedKey = 0; }</p> </blockquote> <p><em>(funky single quote in "couldn't" comes from logging [error localizedDescription])</em></p> <p>Here's the code, which is basically tweaks to WWDC10 AVCam sample:</p> <p><strong>1) Start recording. Start timer to change the output URL every few seconds</strong></p> <pre><code>- (void) startRecording { // start the chunk timer self.chunkTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(chunkTimerFired:) userInfo:nil repeats:YES]; AVCaptureConnection *videoConnection = [AVCamCaptureManager connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self movieFileOutput] connections]]; if ([videoConnection isVideoOrientationSupported]) { [videoConnection setVideoOrientation:[self orientation]]; } if ([[UIDevice currentDevice] isMultitaskingSupported]) { [self setBackgroundRecordingID:[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}]]; } NSURL *fileUrl = [[ChunkManager sharedInstance] nextURL]; NSLog(@"now recording to %@", [fileUrl absoluteString]); [[self movieFileOutput] startRecordingToOutputFileURL:fileUrl recordingDelegate:self]; } </code></pre> <p><strong>2) When the timer fires, change the output file name without stopping recording</strong></p> <pre><code>- (void)chunkTimerFired:(NSTimer *)aTimer { if ([[UIDevice currentDevice] isMultitaskingSupported]) { [self setBackgroundRecordingID:[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}]]; } NSURL *nextUrl = [self nextURL]; NSLog(@"changing capture output to %@", [[nextUrl absoluteString] lastPathComponent]); [[self movieFileOutput] startRecordingToOutputFileURL:nextUrl recordingDelegate:self]; } </code></pre> <p>Note: [self nextURL] generates file urls like file-0.mov, file-5.mov, file-10.mov and so on.</p> <p><strong>3) This gets called each time the file changes, and every other invocation is an error...</strong></p> <pre><code>- (void) captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error { id delegate = [self delegate]; if (error &amp;&amp; [delegate respondsToSelector:@selector(someOtherError:)]) { NSLog(@"got an error, tell delegate"); [delegate someOtherError:error]; } if ([self backgroundRecordingID]) { if ([[UIDevice currentDevice] isMultitaskingSupported]) { [[UIApplication sharedApplication] endBackgroundTask:[self backgroundRecordingID]]; } [self setBackgroundRecordingID:0]; } if ([delegate respondsToSelector:@selector(recordingFinished)]) { [delegate recordingFinished]; } } </code></pre> <p>When this runs, file-0 gets written, then we see error -12780 right after changing the url to file-5, file-10 gets written, then an error, then okay, and so on.</p> <p>It's appears that changing the URL on the fly doesn't work, but it stops the writing which allows the next URL change to work.</p> <p>Any help would be much appreciated.</p>
    singulars
    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