0

Trying this:

int frameCount = 30*10;
    for(int i = 0; i<frameCount; i++)
    {
        while (!append_ok && j < 30)
        {
            if (self.adaptor.assetWriterInput.readyForMoreMediaData)
            {

                CMTime frameTime = CMTimeMake(i,(int32_t) 10);

                NSLog(@"frameTime %f", CMTimeGetSeconds(frameTime));

                append_ok = [self.adaptor appendPixelBuffer:buffer withPresentationTime:frameTime];
                if(!append_ok){
                    NSError *error = self.assetWriter.error;
                    if(error!=nil) {
                        NSLog(@"Unresolved error %@,%@.", error, [error userInfo]);
                    }
                }

                [NSThread sleepForTimeInterval:0.05];
            }
            else
            {
                printf("adaptor not ready %d", j);
                [NSThread sleepForTimeInterval:0.1];
            }
            j++;
        }
        if (!append_ok)
        {
            printf("error appending image times %d\n", j);
        }
        CVBufferRelease(buffer);
    }

But I get this error:

MyApp(11658,0x3a98218c) malloc: * error for object 0x1782c690: double free

I just want to create a video with a 10 second duration, using a single image.

soleil
  • 12,133
  • 33
  • 112
  • 183
  • 2
    You are freeing buffer, then using it, and freeing it again in your loop multiple times. Move the CVBufferRelease statement out of the for loop – Jack Mar 26 '14 at 20:14
  • That does get rid of the error. Is there a way to append a pixel buffer for ten seconds, instead of appending one frame at a time? – soleil Mar 26 '14 at 21:19
  • 1
    Hmm I'm not too sure about this, but if you append a pixel buffer at time 0, then append the next frame at time 10 seconds, wouldn't the pixel buffer be shown for the whole duration? – Jack Mar 26 '14 at 21:24

1 Answers1

0

I know your pain dude, I got a similar method to work for me using one frame with one image for a specified duration according to an audio file (in CMTime). Try this (edited your code):

int frameCount = 1;
for(int i = 0; i<frameCount; i++)
{
    while (!append_ok && j < 30)
    {
        if (self.adaptor.assetWriterInput.readyForMoreMediaData)
        {

            CMTime frameTime = CMTimeMake(10, 1); //10 seconds

            NSLog(@"frameTime %f", CMTimeGetSeconds(frameTime));

            append_ok = [self.adaptor appendPixelBuffer:buffer withPresentationTime:frameTime];
            if(!append_ok){
                NSError *error = self.assetWriter.error;
                if(error!=nil) {
                    NSLog(@"Unresolved error %@,%@.", error, [error userInfo]);
                }
            }

            [NSThread sleepForTimeInterval:0.05];
        }
        else
        {
            printf("adaptor not ready %d", j);
            [NSThread sleepForTimeInterval:0.1];
        }
        j++;
    }
    if (!append_ok)
    {
        printf("error appending image times %d\n", j);
    }
    CVBufferRelease(buffer);
}