要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *cover = [UIImage imageNamed:@"cover.png"];
NSDictionary *settings = [PMMovieMaker videoSettingsWithCodec:AVVideoCodecH264 withWidth:cover.size.width andHeight:cover.size.height];
_movieMaker = [[PMMovieMaker alloc] initWithSettings:settings];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths firstObject];
NSString *tempPath = [documentsDirectory stringByAppendingFormat:@"/upload.mov"];
[_movieMaker setOutputPath:tempPath];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"cover" ofType:@"png"];
NSString *audioPath = [[NSBundle mainBundle] pathForResource:@"audio" ofType:@"m4a"];
[_movieMaker createMovieFromImagesPath:@[imagePath] audioPath:audioPath withCompletion:^(NSURL *fileURL) {
NSLog(@"Video saved to: %@", [fileURL absoluteString]);
}];
}
PMMovieMaker 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "PMMovieMaker"
alegch, [email protected]
PMMovieMaker 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。