试试这个:
int frameCount = 30*10;
for(int i = 0; i<frameCount; i++)
{
while (!append_ok && j < 30)
{
if (self.adaptor.assetWriterInput.readyForMoreMediaData)
{
CMTime frameTime = CMTimeMake(i,(int32_t) 10);
NSLog(@"frameTime %f", CMTimeGetSeconds(frameTime));
append_ok = [self.adaptor appendPixelBuffer:buffer withPresentationTime:frameTime];
if(!append_ok){
NSError *error = self.assetWriter.error;
if(error!=nil) {
NSLog(@"Unresolved error %@,%@.", error, [error userInfo]);
}
}
[NSThread sleepForTimeInterval:0.05];
}
else
{
printf("adaptor not ready %d", j);
[NSThread sleepForTimeInterval:0.1];
}
j++;
}
if (!append_ok)
{
printf("error appending image times %d\n", j);
}
CVBufferRelease(buffer);
}
但是我收到了这个错误:
对象0x1782c690的MyApp(11658,0x3a98218c)malloc: * 错误:双倍免费
我只想使用单张图片创建持续时间为10秒的视频。
答案 0 :(得分:0)
我知道你的痛苦,我有一个类似的方法为我工作使用一个帧与一个图像指定的持续时间根据音频文件(在CMTime中)。试试这个(编辑你的代码):
int frameCount = 1;
for(int i = 0; i<frameCount; i++)
{
while (!append_ok && j < 30)
{
if (self.adaptor.assetWriterInput.readyForMoreMediaData)
{
CMTime frameTime = CMTimeMake(10, 1); //10 seconds
NSLog(@"frameTime %f", CMTimeGetSeconds(frameTime));
append_ok = [self.adaptor appendPixelBuffer:buffer withPresentationTime:frameTime];
if(!append_ok){
NSError *error = self.assetWriter.error;
if(error!=nil) {
NSLog(@"Unresolved error %@,%@.", error, [error userInfo]);
}
}
[NSThread sleepForTimeInterval:0.05];
}
else
{
printf("adaptor not ready %d", j);
[NSThread sleepForTimeInterval:0.1];
}
j++;
}
if (!append_ok)
{
printf("error appending image times %d\n", j);
}
CVBufferRelease(buffer);
}