12

Am trying to create video from images using AVAssetWriter. Implemented code works fine most of time, but in random moments there is problem with writer

AVAssetWriter *videoWriter;
...
[videoWriter finishWriting];
NSLog(@"videoWriter error %@",videoWriter.error);

Received error is:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" 
UserInfo=0x1f839cd0 {NSLocalizedDescription=The operation could not be completed,
 NSUnderlyingError=0x1e59efb0 "The operation couldn’t be completed. (OSStatus error -12633.)", 
NSLocalizedFailureReason=An unknown error occurred (-12633)}

Writing images:

-(void)writeFrame:(WriteableFrame*)wF
{
    if([writerInput isReadyForMoreMediaData])
    {
        CMTime presentTime = CMTimeMake(wF.frameTime, 1000);
        CGImageRef tmpImgRef = [wF.currentImage CGImage];
        buffer = [self pixelBufferFromCGImage:tmpImgRef];
        if(buffer)
        {
            [adaptor appendPixelBuffer:buffer withPresentationTime:presentTime];
            CVPixelBufferRelease(buffer);
        }
    }
    else
    {
        NSLog(@"error");
    }
}

Is there someone with problem like this?

Ivan Alek
  • 1,899
  • 3
  • 19
  • 38

5 Answers5

22

I found the problem, it was putting two frames at the same frame time.

Ivan Alek
  • 1,899
  • 3
  • 19
  • 38
  • 2
    Can you elaborate? I am receiving this error and can not figure it out. Very frustrating. – rrbrambley Mar 02 '13 at 01:15
  • 1
    Sometimes there was situation where i was appending two different images at the exact same presentTime. You can log presentTime, and see if you have the same situation. [adaptor appendPixelBuffer:buffer withPresentationTime:presentTime]; – Ivan Alek Mar 12 '13 at 08:35
  • 3
    I think I ran into the same issue. This really helped! If only the error was more specific... I was using `finishWritingWithCompletionHandler` and found that the completion handler wasn't even executing in this situation, which made debugging even more difficult. – bsirang May 11 '13 at 00:51
  • 1
    how did you solve it can you please provide me snippet of code – Ronak May 18 '13 at 20:40
9

Direct from DTS

Error -12633 is a InvalidTimestamp

smdvlpr
  • 1,088
  • 9
  • 22
  • What is DTS, and can you provide a link to the relevant page? – Stan James Aug 11 '14 at 21:36
  • @StanJames Apple's Developer Technical Support, which I contacted over email. As a registered iOS/Mac developer you get 2 free incidences included in your subscription, but otherwise it is paid support. – smdvlpr Aug 12 '14 at 13:45
4

It may also happen if pushed frames is out of order

AlexeyVMP
  • 2,386
  • 3
  • 24
  • 31
  • Is there any documentation that says you can't append buffers out of order? – smdvlpr Apr 18 '14 at 18:01
  • None. I've figured it out by practice. But it's pretty logical because data should flow in order. – AlexeyVMP Apr 21 '14 at 07:05
  • I ask because I am successfully appending a handful of buffers out of order, and I only get a write error after some time (not the first or second out-of-order buffer, more like the 10th or 20th). I'm dealing with many undocumented errors as I step into this territory, OSStatus -12717 being one of them. I can't quite determine if this is due to out of order buffers, but I am working on debugging. – smdvlpr Apr 21 '14 at 18:16
  • Probably this issue arises only in case of significant difference in timestamp. As stated in docs the exporter tries to interleave video and audio in the flow, so helping them on this is good idea at my opinion. – AlexeyVMP Apr 23 '14 at 09:25
3

If you give a sampleBuffer to the AVAssetWriter, then destroy the associated AVAssetReader, future AVAssetReaders may try to reuse the sampleBuffer before AVAssetWriter is finished with it. This is in contradiction to the AVAssetWriter documentation in AVAssetWriterInput.h, and as far as I am aware there is no way to be sure AVAssetWriter is finished until you get the callback in finishWritingWithCompletionHandler, but this can result in the OSStatus error -12633.

@method appendSampleBuffer:

The receiver will retain the CMSampleBuffer until it is done with it, and then release it. Do not modify a CMSampleBuffer or its contents after you have passed it to this method.

Meekohi
  • 10,390
  • 6
  • 49
  • 58
0

I was getting the same error when the image in my pixel buffer was not of the same width/height dimensions that the input pixel buffer adapter expects based on what you set the sourcePixelBufferAttributes to for(kCVPixelBufferWidthKey, kCVPixelBufferHeightKey). Make sure the pixel buffer has those same dimensions. In my case, my application was sometimes drawing a 1x1 image because I intended to draw a solid color image but I neglected to upscale that single-color pixel to the full size.

zacarter
  • 1
  • 1