簡體   English   中英

使用AVAssetReaderVideoCompositionOutput導出中途,然后使用AVFoundationErrorDomain Code = -11800退出

[英]Exporting with AVAssetReaderVideoCompositionOutput goes partway and then exits with AVFoundationErrorDomain Code=-11800

我已經從AVAssets構建了AVMutableComposition和VideoComposition,並且能夠播放它。 我也可以使用AVAssetExportSession導出它,但是AVAssetExportSession不能提供很多設置控制,所以我使用AVAssetReader / AVAssetWriter導出它,但不幸的是我收到了一個我不理解的錯誤,只是部分寫了輸出文件。

這是我到目前為止的代碼。 我已經遺漏了作者和盡可能多的其他東西(包括一些錯誤檢查),我認為這與使代碼更容易閱讀無關,因為它很多。 請注意,我還沒有處理音頻軌道 - 我試圖一步一步,但也許這是我的問題?

可變asset是AVMutableComposition。

// ------- reader
_assetReader = [AVAssetReader assetReaderWithAsset:asset error:error];

_assetReader.timeRange = CMTimeRangeMake(kCMTimeZero, asset.duration);
_duration = asset.duration;

// --- video reader
NSArray *videoTracks = [asset tracksWithMediaType:AVMediaTypeVideo];

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

_assetReaderOutput = [AVAssetReaderVideoCompositionOutput assetReaderVideoCompositionOutputWithVideoTracks:videoTracks
                                                                                             videoSettings:videoOptions];
((AVAssetReaderVideoCompositionOutput *)_assetReaderOutput).videoComposition = composition;
[_assetReader addOutput:_assetReaderOutput];


// -- leaving out the export settings and construction
//    of the assetWriter since that doesn't seem to be the issue


// -- here's the actual export:

[self.assetWriter startWriting];
[self.assetWriter startSessionAtSourceTime:kCMTimeZero];
[self.assetReader startReading];


CMSampleBufferRef buffer;


while ( [self.assetReader status]==AVAssetReaderStatusReading )
{
    if(![self.assetWriterInput isReadyForMoreMediaData])
        continue;

    buffer = [self.assetReaderOutput copyNextSampleBuffer];


    NSLog(@"READING");

    if(buffer)
        [self.assetWriterInput appendSampleBuffer:buffer];

    NSLog(@"WRITTING...");


}
if( self.assetReader.status == AVAssetReaderStatusFailed ) {
    NSLog( @"%@", self.assetReader.error ); //<--------- I get a problem here
}


//Finish the session:
[self.assetWriterInput markAsFinished];
[self.assetWriter finishWriting];
NSLog(@"Write Ended");

問題是循環退出很短的時間后我得到這個輸出:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x17f1dfa0 {NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x191617f0 "The operation couldn’t be completed. (OSStatus error -308.)", NSLocalizedFailureReason=An unknown error occurred (-308)}

我似乎遵循了一些不好的示例代碼,而不是正確的示例代碼,這非常清楚,如果非常冗長,關於如何執行此操作:

https://developer.apple.com/library/Mac/DOCUMENTATION/AudioVideo/Conceptual/AVFoundationPG/Articles/05_Export.html#//apple_ref/doc/uid/TP40010188-CH9-SW2

雖然我已經完全重寫了我的代碼,但我認為我遇到的具體問題不是在[self.assetReaderOutput copyNextSampleBuffer]返回的CMSampleBufferRef上調用CFRelease。 你需要在循環中做到這一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM