簡體   English   中英

AVAssetExportSession錯誤-11820

[英]AVAssetExportSession Error -11820

我正在編寫一個使用AVFoundation處理視頻的應用程序。

我的應用程序的行為很簡單:我從相機膠卷中獲取視頻,然后創建一個帶有一些音軌的AVMutableComposition。 使用混合合成我初始化AVAssetExportSession,將視頻文件存儲在我的應用程序的文檔目錄中。

在此之前,一切都沒問題:我的視頻已存儲,我可以在另一個控制器中播放。 如果我將剛剛存儲在我的文檔文件夾中的視頻進行一些編輯(與第一次AVmutableComposition,AVAssetExportSession相同)再次沒問題。

但是我第三次執行此過程來編輯視頻,AVAssetExportSession狀態變為“Fail”並出現此錯誤:

"Domain=AVFoundationErrorDomain Code=-11820 "Cannot Complete Export" UserInfo=0x1a9260 {NSLocalizedRecoverySuggestion=Try exporting again., NSLocalizedDescription=Cannot Complete Export}"

我讀過這是一個無法導出會話的一般錯誤。 這是什么意思? 為什么我第三次進行編輯過程? 這可能是內存管理錯誤嗎? 一個bug? 這是我的AVAssetExportSession的代碼:

 _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];   
_assetExport.shouldOptimizeForNetworkUse = YES;

///data odierna
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"ddMMyyyyHHmmss"];

NSDate *now = [[NSDate alloc] init];

NSString *dateString = [format stringFromDate:now];
[now release];
[format release];
NSString* ext = @".MOV";
NSString* videoName=[NSString stringWithFormat:@"%@%@", dateString, ext];

///data odierna
NSString *exportPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:videoName];

if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) 
{
    [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
}


_assetExport.outputFileType = AVFileTypeQuickTimeMovie;

[_assetExport setTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)];
NSURL    *exportUrl = [NSURL fileURLWithPath:exportPath] ;

_assetExport.outputURL = exportUrl ;

[_assetExport exportAsynchronouslyWithCompletionHandler:^
{
    switch (_assetExport.status) 
    {
        case AVAssetExportSessionStatusFailed:
        {
            NSLog (@"FAIL %@",_assetExport.error);
            if ([[NSFileManager defaultManager] fileExistsAtPath:[_assetExport.outputURL path]]) 
            {
                [[NSFileManager defaultManager] removeItemAtPath:[_assetExport.outputURL path] error:nil];
            }

            [self performSelectorOnMainThread:@selector (ritenta)
                                   withObject:nil
                                waitUntilDone:NO];
            break;
        }
        case AVAssetExportSessionStatusCompleted: 
        {
            NSLog (@"SUCCESS");

            [self performSelectorOnMainThread:@selector (saveVideoToAlbum:)
                                   withObject:exportPath
                                waitUntilDone:NO];
            break;
        }
        case AVAssetExportSessionStatusCancelled: 
        {
            NSLog (@"CANCELED");

            break;
        }
    };
}];

我在網上做了很多搜索,有些人在會話的outputURL中遇到了問題,但是我已經嘗試了,似乎在我的代碼中都可以。 要為文件指定唯一的名稱,我使用NSDate。 出於調試目的,我嘗試恢復標准字符串名稱,但問題仍然存在。 有任何想法嗎? 有人可以向我建議一種替代方法,導出到文檔文件夾,資產與AssetWriter insted AVassetExportSession?

問題是_assetExport.outputFileType您已將類型設置為AVFileTypeQuickTimeMovie 哪種類型不太可能受支持。

嘗試使用以下代碼找出_assetExport支持的輸出文件類型,並使用合適的代碼。

NSLog (@"created exporter. supportedFileTypes: %@", exporter.supportedFileTypes);

要么
只是改變了

_assetExport.outputFileType = AVFileTypeQuickTimeMovie;

exporter.outputFileType = @"com.apple.m4a-audio";

也不要忘記更改擴展名

NSString* ext = @".MOV";  to @".m4a" 

這應該工作。 它對我有用。

暫無
暫無

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

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