Youstanzr
Youstanzr

Reputation: 634

Trying to make a 15 seconds video CMTimeMake

I am trying to do a 15 seconds video out of a UIImage's array which the array content numbers will change.

NSUInteger fps = 30;
int frameCount = 0;
float numberOfSecondsPerFrame = 15/[imageArray count];
float frameDuration = fps * numberOfSecondsPerFrame;

 NSLog(@"**************************************************");
 for(UIImage * img in imageArray)
    {
    buffer = [self pixelBufferFromCGImage:[img CGImage]];

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


            CMTime frameTime = CMTimeMake(frameCount*frameDuration,(int32_t) fps);

            NSLog(@"seconds = %f, %u, %d", CMTimeGetSeconds(frameTime),fps,j);
            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++;
}

I need to make to each picture duration show time = 15/[imageArray count] but I can't figure out how this CMTimeMake work

I know its so simple to fix my problem but I couldn't figure it out

Any hint or help will be really appreciated

Upvotes: 0

Views: 564

Answers (1)

Youstanzr
Youstanzr

Reputation: 634

Finally I figured it out by myself

This is the corrected version to do the video for 15 seconds :D

CMTime frameTime = CMTimeMake(frameCount*15, [imageArray count]);

Upvotes: 2

Related Questions