1

i am trying to create a MPEG4 with about 20 images using AVAssetWriter..

for 10 images i am able to create a file in my app directory but with 20 images i am unable to create a file.

here is my path where i am trying to save my images mpeg4 format file(device path):

var/mobile/Applications/FED8E776-92CC-47BC-AA47-845DAED5CBE7/Library/Caches/videoOutput1234videoOutput1234.mp4

here my question is: is there any limit with folder created in app directory, if so what is the limit and how to find the size of created file

and here is my code:

-(void)writeImageAsMovie:(NSMutableArray *)array toPath:(NSString*)path size:(CGSize)size duration:(int)duration 
{
CFDataRef imgData;
CGDataProviderRef imgDataProvider;
CGImageRef image1;




if ([[NSFileManager defaultManager] fileExistsAtPath:path])
    [[NSFileManager defaultManager] removeItemAtPath:path error:nil];


NSError *error = nil;

AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:path] fileType:AVFileTypeMPEG4 error:&error];


NSParameterAssert(videoWriter);

NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                               AVVideoCodecH264, AVVideoCodecKey,
                               [NSNumber numberWithInt:size.width], AVVideoWidthKey,
                               [NSNumber numberWithInt:size.height], AVVideoHeightKey,
                               nil];
AVAssetWriterInput* writerInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings] retain];


AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput sourcePixelBufferAttributes:nil];


NSParameterAssert(writerInput);
NSParameterAssert([videoWriter canAddInput:writerInput]);

writerInput.expectsMediaDataInRealTime = YES;
[videoWriter addInput:writerInput];


[videoWriter startWriting];
[videoWriter startSessionAtSourceTime:kCMTimeZero];


CVPixelBufferRef buffer = NULL;


int frameCount = 0;

for(int i = 0; i<[array count]; i++)
{
    imgData = (CFDataRef)[array objectAtIndex:i];
    imgDataProvider = CGDataProviderCreateWithCFData (imgData);
    image1 = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);

    buffer = [self pixelBufferFromCGImage:image1];

    BOOL append_ok = NO;
    int j = 0;
    while (!append_ok && j < 30) 
    {
        if (adaptor.assetWriterInput.readyForMoreMediaData) 
        {
            printf("appending %d attemp %d\n", frameCount, j);
            CMTime frameTime;


            int64_t value = [[dataBaseTimeArray objectAtIndex:i] intValue];
            int32_t preferredTimeScale = 1;
            frameTime = CMTimeMake(value, preferredTimeScale);


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

if (AVAssetWriterStatusCompleted) {
    [writerInput markAsFinished];
    [videoWriter finishWriting];
}
}
Steve Gear
  • 757
  • 2
  • 16
  • 44
  • You have some debugging output, which is good. Could you please include the text sent to the console when this runs? – Cowirrie May 15 '12 at 11:47
  • Take a look at [this](http://stackoverflow.com/a/10362812/251513). – Mat May 15 '12 at 11:47

0 Answers0