我遇到了这个问题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 …
Run Code Online (Sandbox Code Playgroud)