【问题标题】:Videoclip export error: 'Invalid output file type' in objective-c视频剪辑导出错误:objective-c 中的“输出文件类型无效”
【发布时间】:2014-09-23 21:43:43
【问题描述】:

我正在尝试修剪现有的视频剪辑并将剪辑重新保存在与原始文件相同的位置。但是,当我运行我的应用程序时,出现此错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“无效的输出文件类型”

我找到了建议,但它们要求我更改 AVMediaTypeVideo 的输出文件类型。我想保留 AVMediaTypeVideo 因为这是原始视频文件保存的内容。

这是我目前所拥有的:

AVMutableComposition *finalClip = [[AVMutableComposition alloc]init];

NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"];

NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath];

AVURLAsset *videoclip = [AVURLAsset URLAssetWithURL:outputURL options:nil];

AVMutableCompositionTrack *finalClipTrack = [finalClip addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];

[finalClipTrack insertTimeRange:CMTimeRangeMake(CMTimeMake((duration*indexNum), 1), CMTimeMake(duration,1)) ofTrack:[[videoclip tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil];

NSString *outputPathwe = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"outputwe.mov"];

NSURL *outputURLwe = [[NSURL alloc] initFileURLWithPath:outputPathwe];

if ([[NSFileManager defaultManager] fileExistsAtPath:outputPathwe])
    [[NSFileManager defaultManager] removeItemAtPath:outputPathwe error:nil];

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:finalClip presetName:AVAssetExportPresetHighestQuality];

exporter.outputFileType = AVMediaTypeVideo;

exporter.outputURL=outputURLwe;

[exporter exportAsynchronouslyWithCompletionHandler:^{

    dispatch_async(dispatch_get_main_queue(), ^{

        [self exportDidFinish:exporter];

    });
}];

我觉得我只是想念它真的很容易。这是我第一次使用 AVFoundation,所以任何帮助都将不胜感激!

【问题讨论】:

    标签: objective-c avfoundation exporter


    【解决方案1】:

    AVMediaTypeVideo 是“媒体类型”而不是“输出文件类型”。您的原始视频具有 AVMediaTypeVideo 类型的音轨。原始视频的类型不是AVMediaTypeVideo

    AVAssetExportSession 的outputFileTypeNSString 类型的常量。允许的值在 AVFoundation/AVMediaFormat.h 中列出。对于视频,它们是:

    • AVFileTypeQuickTimeMovie
    • AVFileTypeMPEG4
    • AVFileTypeAppleM4V

    您必须为您的AVAssetExportSessionoutputFileType 选择一个允许的值。

    【讨论】:

    • 感谢您为我澄清这一点!
    猜你喜欢
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    • 2015-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多