我遇到了这个问题AVAssetWritter
.有时我的视频编写会话就会挂起.检查当前在我的设备上运行的线程后,我发现整个视频处理正在等待copyNextSampleBuffer
返回.我不知道是什么原因导致了这个问题.有没有人成功克服了这个问题?
下面是从乐器捕获的线程转储.它结束了mach_msg_trap
.
while ([self.assetWriterVideoInput isReadyForMoreMediaData] && !(*completedOrFailed) && !self.cancelled)
{
@autoreleasepool {
CMSampleBufferRef sampleBuffer = [self.assetReaderVideoOutput copyNextSampleBuffer];
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferRef croppedBuffer = NULL;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
[NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey, nil];
CVPixelBufferCreate(kCFAllocatorDefault, self.outputSize.width, self.outputSize.height, CVPixelBufferGetPixelFormatType(pixelBuffer), (__bridge CFDictionaryRef) options, &croppedBuffer);
CIImage *img = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer];
// img processing
[self.context render:img toCVPixelBuffer:croppedBuffer];
if (sampleBuffer != NULL)
{
BOOL success = [self.avPixelAdaptor appendPixelBuffer:croppedBuffer withPresentationTime:sampleTime];
CFRelease(sampleBuffer);
sampleBuffer = NULL;
*completedOrFailed = !success;
}
else
{
*completedOrFailed = YES;
}
CVPixelBufferRelease(croppedBuffer);
}
}
}
Run Code Online (Sandbox Code Playgroud)
资产阅读器的源资产AVMutableComposition
由几个AVURLAsset
指向照片库的资产组成(即url ="assets-library://asset/asset.MOV?id = 4CA9A2C6-F2D4-4FDF-AAEC-6335B9BD840A&ext = MOV") .从每个源资源获取2秒,这是在0.6s的源资产之后开始的.如果所有源资源都从0开始,那么视频处理永远不会挂起.
主要问题是:copyNextSampleBuffer
永远等待退出的条件是什么?文档没有提到这种情况.
我没有看到您将输入标记为已完成并在代码中结束了会话,如下所示。你调用了这些终结器吗?
//Finish the session:
[writerInput markAsFinished];
[videoWriter endSessionAtSourceTime:totalDuration];
[videoWriter finishWritingWithCompletionHandler:^{
// Handle videoWriter.status here
}];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
562 次 |
最近记录: |