Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS-AVAssetExportSession未知错误-12769_Ios_Objective C_Video_Avfoundation_Avassetexportsession - Fatal编程技术网

iOS-AVAssetExportSession未知错误-12769

iOS-AVAssetExportSession未知错误-12769,ios,objective-c,video,avfoundation,avassetexportsession,Ios,Objective C,Video,Avfoundation,Avassetexportsession,似乎AVFoundation不能接受我的一个视频。我真的不知道为什么。它适用于其他视频,但不适用于此视频 我甚至没有修改视频,我只是用视频曲目进行合成,并以预设AVAssetExportPresetHighestQuality导出它 我得到这个错误: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x600000

似乎AVFoundation不能接受我的一个视频。我真的不知道为什么。它适用于其他视频,但不适用于此视频

我甚至没有修改视频,我只是用视频曲目进行合成,并以预设AVAssetExportPresetHighestQuality导出它

我得到这个错误:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x60000045a8e0 {Error Domain=NSOSStatusErrorDomain Code=-12769 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-12769), NSLocalizedDescription=The operation could not be completed}
您知道我的代码中是否有错误,或者该视频是否不受AVFoundation支持

这是Github上的项目,它只是将视频导出到摄影机卷:

或者,如果您不想使用Github:

以下是视频:

Dropbox链接:

或湿传输链路:

下面是代码:

- (void)exportVideo:(AVAsset *)videoAsset
      videoDuration:(Float64)videoAssetDuration
                 to:(NSString *)resultPath{

    [Utilities deleteFileIfExists:resultPath];

    AVMutableComposition *mainComposition = [[AVMutableComposition alloc] init];
    AVMutableCompositionTrack *compositionVideoTrack = [mainComposition addMutableTrackWithMediaType:AVMediaTypeVideo
                                                                                    preferredTrackID:kCMPersistentTrackID_Invalid];

    int timeScale = 100000;
    int videoDurationI = (int) (videoAssetDuration * (float) timeScale);
    CMTime videoDuration = CMTimeMake(videoDurationI, timeScale);
    CMTimeRange videoTimeRange = CMTimeRangeMake(kCMTimeZero, videoDuration);

    NSArray<AVAssetTrack *> *videoTracks = [videoAsset tracksWithMediaType:AVMediaTypeVideo];
    AVAssetTrack *videoTrack = [videoTracks objectAtIndex:0];

    [compositionVideoTrack insertTimeRange:videoTimeRange
                                   ofTrack:videoTrack
                                    atTime:kCMTimeZero
                                     error:nil];

    NSURL *outptVideoUrl = [NSURL fileURLWithPath:resultPath];
    self.exporter = [[AVAssetExportSession alloc] initWithAsset:mainComposition
                                                     presetName:AVAssetExportPresetHighestQuality];

    self.exporter.outputURL = outptVideoUrl;
    self.exporter.outputFileType = AVFileTypeMPEG4;
    self.exporter.shouldOptimizeForNetworkUse = YES;

    [self.exporter exportAsynchronouslyWithCompletionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            switch (self.exporter.status) {
                case AVAssetExportSessionStatusFailed:{
                    @throw [NSException exceptionWithName:@"failed export"
                                                   reason:[self.exporter.error description]
                                                 userInfo:nil];
                }
                case AVAssetExportSessionStatusCancelled:
                    @throw [NSException exceptionWithName:@"cancelled export"
                                                   reason:@"Export cancelled"
                                                 userInfo:nil];

                case AVAssetExportSessionStatusCompleted: {
                    NSLog(@"Export finished");
                }
                    break;

                default:
                    break;
            }
        });
    }];
}

您尝试测试的设备无法对其进行解码。请在一些较新的设备上试用,例如iPhone 6。我在iPad模拟器iOS10.3上测试了你的媒体,它在那里工作得很好,所以这一定与编码有关。

我做了一个实验,得出了这个结论。如果你从videoTimeRange中减少1毫秒或更多毫秒,那么它就会工作。尝试替换以下代码块:

int timeScale = 100000;
Float64 seconds = CMTimeGetSeconds([videoAsset duration]) - 0.001;
NSUInteger videoDurationI = (NSUInteger) (seconds * (float) timeScale);
CMTime videoDuration = CMTimeMake(videoDurationI, timeScale);
CMTimeRange videoTimeRange = CMTimeRangeMake(kCMTimeZero, videoDuration);

非常感谢您的回复!我能问一下你用的是哪款iPad模拟器吗?我只安装了:iPad 2、iPad Air、iPad Air 2、iPad Pro、iPad视网膜。目前正在使用iPadAir 2进行测试,看看它是否有效。再次感谢你告诉我iPad Air 2 iOS 10.3仍然会崩溃。我也可以问一下你是如何尝试的吗?是我的代码还是别的什么?提前谢谢。我试过iPad pro iOS10.3,你的代码没有错。非常感谢!不幸的是,我仍然与模拟器iPad Pro 9.7英寸iOS 10.3.1崩溃。。。我已经将Xcode 8.3.3和基本SDK设置为最新的iOS 10.3。不确定我们的项目之间可能存在哪些差异,从而导致我方的崩溃。。因为我已经在我的应用程序项目中测试了它,所以我将尝试制作一个新项目并打包视频,看看它是否有效。我还尝试了一个iphone 7 real设备,结果它崩溃了。。它是否适用于旧设备/模拟器?可能我的代码或项目配置、生成设置中有错误。。