2

我正在尝试使用 AVFoundation Framework 创建视频缩略图。我已正确添加并导入#import <AVFoundation/AVFoundation.以下是创建缩略图的代码:

AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:[NSURL URLWithString:moviePath] options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;
CMTime thumbTime = CMTimeMakeWithSeconds(0,30);

AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
    if (result != AVAssetImageGeneratorSucceeded) {
        NSLog(@"couldn't generate thumbnail, error:%@", error);
    }
    [imageButton setImage:[UIImage imageWithCGImage:im] forState:UIControlStateNormal];
    //UIImage *thumbImg=[UIImage imageWithCGImage:im];
};

CGSize maxSize = CGSizeMake(320, 180);
generator.maximumSize = maxSize;
[generator generateCGImagesAsynchronouslyForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:thumbTime]] completionHandler:handler];

当我构建它时,我收到以下错误:

Undefined symbols for architecture i386:_CMTimeMakeWithSeconds", referenced from:
  -[photojournal generateImage] in photojournal.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

我已经在 Google 和 Stack Overflow 上查看了类似的问题,共识似乎是添加丢失的文件来编译源代码。我的问题是 - AVFoundation 缺少哪些文件?当我导入框架时,它们不应该都来吗?谢谢。

4

2 回答 2

12

您需要将 Core Media 框架添加到您的项目中,并且

#import <CoreMedia/CoreMEdia.h>

CMTime 是核心媒体框架的一部分。我有同样的错误,这解决了它。

于 2012-09-26T16:34:17.913 回答
0

扩展andrewmobile的答案。除了#import <CoreMedia/CoreMedia.h>,您还需要在构建阶段下的“Link binary with libraries”中添加 CoreMedia.framework。

于 2013-04-14T22:35:30.017 回答