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.