gpt4 book ai didi

ios - 此媒体所需的编码器正忙

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:23:29 26 4
gpt4 key购买 nike

尝试通过 AVAssetWriter 和 AVAssetWriterInput 方法将多个视频连接成一个时。在第 3 个视频之后,我收到来自 AVAssetWriter.error 的“无法编码”错误。

此外,我可以通过控制台看到成功读取缓冲区,但只有最后一次成功读取的视频才会出现在串联的 mov 中。对其中一个或两个问题的任何见解表示赞赏,来源和日志如下。谢谢

+(void)doWriteWithVideoWriter:(AVAssetWriter *)videoWriter withIndex:(int)index withWriterInputArray:(NSMutableArray *)writersArray withInstance:(VideoCombinerManager *)theInstance{
if ([writersArray count] > 0)
{
int newIndex = index+1;

NSError *readerError;
NSDictionary *videoOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] forKey:(id)kCVPixelBufferPixelFormatTypeKey];

AVAsset *sourceAsset = [theInstance.loadedAssetsForCompilationDictionary objectForKey:[theInstance.sortedKeysArray objectAtIndex:index]];
AVAssetTrack *videoTrack = [[sourceAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVAssetReaderTrackOutput *currentReaderTrackOutput = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack outputSettings:videoOptions];
AVAssetReader *currentReader = [[AVAssetReader alloc] initWithAsset:sourceAsset error:&readerError];
[currentReader addOutput:currentReaderTrackOutput];
[currentReader startReading];

AVAssetWriterInput *writerInput = [[writersArray objectAtIndex:0] retain];

dispatch_queue_t _processingQueue = dispatch_queue_create("asdf", NULL);
[writerInput requestMediaDataWhenReadyOnQueue:_processingQueue usingBlock:^{
if ([writerInput isReadyForMoreMediaData])
{
CMSampleBufferRef nextSampleBuffer;

if ([currentReader status] == AVAssetReaderStatusReading &&
(nextSampleBuffer = [currentReaderTrackOutput copyNextSampleBuffer])) {

if (nextSampleBuffer)
{
BOOL result = [writerInput appendSampleBuffer:nextSampleBuffer];
if (!result)
{
NSLog(@"videoWriter.error.userInfo: %@", videoWriter.error.userInfo);
}
CFRelease(nextSampleBuffer);
}
}
else
{
NSLog(@"writer done: %d", index);
dispatch_release(_processingQueue);

[writersArray removeObjectAtIndex:0];

[writerInput markAsFinished];
[writerInput release];

[currentReader release];
[currentReaderTrackOutput release];

[VideoCombinerManager doWriteWithVideoWriter:videoWriter withIndex:newIndex withWriterInputArray:writersArray withInstance:theInstance];
}
}
}];
}
else
[videoWriter finishWriting];

}

作家完成:0

作者完成:1

作家完成:2

videoWriter.error.userInfo: {
NSLocalizedDescription = "Cannot Encode";
NSLocalizedFailureReason = "The encoder required for this media is busy.";
NSLocalizedRecoverySuggestion = "Stop any other actions that encode media and try again.";
NSUnderlyingError = "Error Domain=NSOSStatusErrorDomain Code=-12915 \"The operation couldn\U2019t be completed. (OSStatus error -12915.)\"";
}

videoWriter.error.userInfo: {
NSLocalizedDescription = "Cannot Encode";
NSLocalizedFailureReason = "The encoder required for this media is busy.";
NSLocalizedRecoverySuggestion = "Stop any other actions that encode media and try again.";
NSUnderlyingError = "Error Domain=NSOSStatusErrorDomain Code=-12915 \"The operation couldn\U2019t be completed. (OSStatus error -12915.)\"";
}

最佳答案

至于 Cannot Encode 错误,您同时存在的 writer 和/或 writerInputs 太多。当我遇到同样的错误时,我意识到我必须释放所有以前使用的 writer 和 writerInputs 才能摆脱它。由于您确实释放了它们,您的问题可能是您同时拥有许多它们。

关于ios - 此媒体所需的编码器正忙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12647725/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com