1

I used This code for create video from images. it will create perfectly for fix time for one image. but my problem is to create video for not fixed timimg of one frame. this is my code.

imageArray is array of all images and in array there are time interval of each objects. please help me.

CVPixelBufferRef buffer = NULL;

int frameCount = 0;
NSUInteger fps = 60;

for (int i=0; i<[imageArray count]; i++)
{
    double numberOfSecondsPerFrame = [[[array  objectAtIndex:i] objectForKey:@"timeinterval"] doubleValue];
    double frameDuration = fps * numberOfSecondsPerFrame;

    UIImage *img = [imageArray objectAtIndex:i];
    buffer = [self pixelBufferFromCGImage:[img CGImage]size:size];


    BOOL append_ok = NO;
    int j = 0;
    while (!append_ok && j < 60)
    {
        if (adaptor.assetWriterInput.readyForMoreMediaData)
        {
            //print out status:
            NSLog(@"Processing video frame (%d,%d)",frameCount,[imageArray count]);

            CMTime frameTime = CMTimeMake(frameCount*frameDuration,(int32_t) fps);
            append_ok = [adaptor appendPixelBuffer:buffer withPresentationTime:frameTime];
            if(!append_ok)
            {
                NSError *error = videoWriter.error;
                if(error!=nil)
                {
                    NSLog(@"Unresolved error %@,%@.", error, [error userInfo]);
                }
            }
        }
        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, with error.", frameCount, j);
    }
    frameCount++;
}

NSLog(@"**************************************************");

//Finish the session:
[videoWriterInput markAsFinished];
[videoWriter finishWriting];
NSLog(@"Write Ended");

I have some issues to understand CMTIME. Please help me for this problem.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • check This http://stackoverflow.com/questions/5373932/ios-how-to-generate-a-video-file-via-images-audio Check this also http://ios.biomsoft.com/2012/02/01/create-movie-from-array-of-images/ – srinivas n Jun 07 '14 at 11:56
  • i have seen and also tried it but i can't make it. – Maulik Vekariya Jun 07 '14 at 12:05
  • Within the inner loop, you're always creating the same frame number. I think you want to use either `j` or `(frameCount + j)` instead of `frameCount`. Otherwise the `frameTime` will be the same for every iteration of the `while` loop. – user1118321 Jun 07 '14 at 15:03
  • its working for same time. like if i have 5 image and is et all image to 3 sec then above code is working perfect. i will get 15 sec video from this. problem is for changing time for each frame.Please help me – Maulik Vekariya Jun 07 '14 at 16:12

0 Answers0