继续上一个问题 ASSETWriterInput for Making Video from UIImages on Iphone Issues
我想要一个新线程,因为我喜欢发布一些代码,小评论部分不会这样做。
之前感谢 Peter Deweese,但我仍然遇到问题..
我有一个循环,捕获屏幕 30 次。每次我收到图像时,我都会调用“转换”以将该图像附加到视频中。之后,关闭视频文件
,这样我做错了什么。在这个特定的视频中,我没有收到视频
[self init_video]; for (索引=0;索引< 30;索引++) {
[self.view.layer renderInContext:ctx];
global_image = UIGraphicsGetImageFromCurrentImageContext();
//Once I have UIImageview of global_image I call convert
[self convert];
} [自我结束_视频];
/////////////////////////////////////////////////////////// //////////
-(void) init_video { ........视频设置和设置适配器
AVAssetWriterInputPixelBufferAdaptor * avAdaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput sourcePixelBufferAttributes:NULL];
[videoWriter addInput:writerInput]; [videoWriter开始写作];
[videoWriter startSessionAtSourceTime:kCMTimeZero]; }
////////////////////////////////////////////////////////////////////////////////////////// ////
-(void) 转换 {......获取图像像素缓冲区
CMTime frameTime = CMTimeMake(1, 15);
CMTimelastTime=CMTimeMake(索引, 15); //索引是上面循环的0到29
CMTimepresentTime=CMTimeAdd(lastTime,frameTime);
//根据 Peter DeWeese 的说法,需要调用两次才能使其工作。
[avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:lastTime];
[avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:presentTime];
}
////////////////////////////////////////////////////////////////////////////////////////// /////////
-(void) end_video { [writerInput 标记为完成];
//want 2 seconds of video, with 15 frame for each seconds.
[videoWriter endSessionAtSourceTime:CMTimeMake(30, 15)];
[videoWriter finishWriting];
}
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 = 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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论