【问题标题】:iOS - AVAssetExportSession unknown error -12769iOS - AVAssetExportSession 未知错误 -12769
【发布时间】:2017-06-07 10:37:15
【问题描述】:

似乎 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 上的项目(它只是将视频导出到相机胶卷):

https://github.com/moonshaped/ExportSessionCrash

或者如果你不想使用 Github:

这是视频:

Dropbox 链接:https://www.dropbox.com/s/twgah26gqgsv9y9/localStoreTempVideoPath.mp4?dl=0

或WeTransfer链接:https://wetransfer.com/downloads/8f8ab257068461a2c9a051542610725220170606122640/8d934c

这是代码:

- (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;
            }
        });
    }];
}

【问题讨论】:

    标签: ios objective-c video avfoundation avassetexportsession


    【解决方案1】:

    我做了一个实验,得出了这个结论。如果您从 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);
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 非常感谢您的回复!请问你用的是哪个iPad模拟器?我只安装了:iPad 2、iPad Air、iPad Air 2、iPad Pro、iPad Retina。目前正在使用 iPad Air 2 进行测试,看看它是否有效。再次感谢
      • 对我来说,iPad Air 2 iOS 10.3 仍然会崩溃。我也可以问一下你是怎么试的吗?是我的代码还是其他什么?提前致谢。
      • 我用iPad pro iOS10.3试过了,你的代码没有错。
      • 非常感谢!不幸的是,模拟器 iPad Pro (9.7 inch) iOS 10.3.1 仍然崩溃……我将 Xcode 8.3.3 和“Base SDK”设置为最新的 iOS (10.3)。不确定我们的项目之间可能存在哪些差异会导致我这边崩溃。由于我已经在我的应用程序项目中对其进行了测试,因此我将尝试制作一个新项目并捆绑视频以查看它是否有效。
      • 我也尝试过使用 iphone 7(真实设备),但它崩溃了。它适用于旧设备/模拟器吗?也许我的代码或项目配置、构建设置有问题..
      猜你喜欢
      • 1970-01-01
      • 2016-07-08
      • 2017-08-30
      • 2011-08-03
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      • 2021-02-19
      相关资源
      最近更新 更多