继续关于ASSETWriterInput的上一个问题,即在Iphone问题上从UIImages制作视频

时间:2010-10-23 20:19:58

标签: video-processing assetslibrary avassetwriter

我想要一个新线程,因为我想发布一些代码,小评论部分不会这样做。

先谢谢彼得·德威斯,但我仍有问题......

我有一个循环,获得30次屏幕截图。每次我得到一张图片时,我都会调用convert来将该图片附加到视频中。之后,关闭视频文件

所以,我做错了什么。在这个特定的一个我没有得到视频

[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 {    ........视频设置和设置适配器

AVAssetWriterInputPixelBufferAdaptor *     avAdaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput sourcePixelBufferAttributes:NULL];

[videoWriter addInput:writerInput]; [videoWriter startWriting];

[videoWriter startSessionAtSourceTime:kCMTimeZero]; }

/////////////////////////////////////////////// //////

- (void)转换 {..........获取图像像素缓冲区

CMTime frameTime = CMTimeMake(1,15);

CMTime lastTime = CMTimeMake(index,15); // index是上面循环的0到29之间的

CMTime presentTime = CMTimeAdd(lastTime,frameTime);

//根据Peter DeWeese的说法,需要调用两次才能使其正常工作。

[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];

}

0 个答案:

没有答案