Continuing the prev question of ASSETWriterInput for making Video from UIImages on Iphone Issues
I want a new thread because I like to post some codes , the little comment section wouldn't do it.
Thanks peter Deweese previously, but I still have issues..
I have a loop, getting a screen capture 30 times. Each time I got an image I call convert to append that image to video. After that, close the video file
so, anything I did wrong. on this particular one I am not getting the video
[self init_video]; for (index=0; index< 30; index++) {
[self.view.layer renderInContext:ctx];
global_image = UIGraphicsGetImageFromCurrentImageContext();
//Once I have UIImageview of global_image I call convert
[self convert];
} [self end_video];
////////////////////////////////////////////////////////////
-(void) init_video { ........video setup and setup adaptor
AVAssetWriterInputPixelBufferAdaptor * avAdaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput sourcePixelBufferAttributes:NULL];
[videoWriter addInput:writerInput]; [videoWriter startWriting];
[videoWriter startSessionAtSourceTime:kCMTimeZero]; }
/////////////////////////////////////////////////////
-(void) convert {..........getting the image pixel buffer
CMTime frameTime开发者_StackOverflow中文版 = CMTimeMake(1, 15);
CMTime lastTime=CMTimeMake(index, 15); //index is from 0 to 29 of the loop above
CMTime presentTime=CMTimeAdd(lastTime, frameTime);
//according to Peter DeWeese, needs to call twice to make it work.
[avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:lastTime];
[avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:presentTime];
}
//////////////////////////////////////////////////////////
-(void) end_video { [writerInput markAsFinished];
//want 2 seconds of video, with 15 frame for each seconds.
[videoWriter endSessionAtSourceTime:CMTimeMake(30, 15)];
[videoWriter finishWriting];
}
精彩评论