简体   繁体   English

Videoclip导出错误:Objective-C中的“无效的输出文件类型”

[英]Videoclip export error: 'Invalid output file type' in objective-c

I am trying to trim an existing videoclip and re-save the clip in the same location as the original file. 我正在尝试修剪现有的视频剪辑并将剪辑重新保存在与原始文件相同的位置。 However when I run my app I get this error: 但是,当我运行我的应用程序时,出现此错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid output file type' 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“无效的输出文件类型”

I have found recommendations but they require me to change the outputfiletype from AVMediaTypeVideo. 我找到了建议,但它们要求我从AVMediaTypeVideo更改outputfiletype。 I would like to keep AVMediaTypeVideo because this is what the original video file is saved as. 我想保留AVMediaTypeVideo,因为这是原始视频文件另存为的内容。

This is what I have so far: 这是我到目前为止的内容:

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];

    });
}];

I feel like it something really easy that I am just missing. 我觉得我真的很想念我。 This is my first time using AVFoundation so any help would be appreciated! 这是我第一次使用AVFoundation,因此将不胜感激!

AVMediaTypeVideo is a "media type" not an "output file type". AVMediaTypeVideo是“媒体类型”而不是“输出文件类型”。 Your original video has tracks that are of type AVMediaTypeVideo. 您的原始视频的轨道类型为AVMediaTypeVideo。 The original video is not of type AVMediaTypeVideo . 原始视频的类型不是AVMediaTypeVideo

The outputFileType of AVAssetExportSession are constants of type NSString . AVAssetExportSession的outputFileTypeNSString类型的常量。 The allowed values are listed in AVFoundation/AVMediaFormat.h. 允许的值在AVFoundation / AVMediaFormat.h中列出。 For video, they are: 对于视频,它们是:

  • AVFileTypeQuickTimeMovie AVFileTypeQuickTimeMovie
  • AVFileTypeMPEG4 AVFileTypeMPEG4
  • AVFileTypeAppleM4V AVFileType苹果M4V

You must choose one of the allowed values to use for your AVAssetExportSession 's outputFileType . 您必须选择一个允许值用于AVAssetExportSessionoutputFileType

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM