为了账号安全,请及时绑定邮箱和手机立即绑定

使用AVAsset制作带有图片数组和歌曲文件的电影文件

使用AVAsset制作带有图片数组和歌曲文件的电影文件

iOS
一只斗牛犬 2019-12-10 13:08:03
我正在尝试使用图片数组和音频文件制作电影文件。为了制作带有图片阵列的电影,我在这里用了祖尔的大贴子。一切都太完美了,我的电影里有我的照片。但是,当我尝试添加一些音轨时,会有很多问题。为了理解我把我的代码:当我调用此方法时,图片数组和歌曲文件已准备就绪:-(void) writeImagesToMovieAtPath:(NSString *) path withSize:(CGSize) size{    NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];    NSArray *dirContents = [[NSFileManager defaultManager] directoryContentsAtPath:documentsDirectoryPath];    for (NSString *tString in dirContents) {        if ([tString isEqualToString:@"essai.mp4"])         {            [[NSFileManager defaultManager]removeItemAtPath:[NSString stringWithFormat:@"%@/%@",documentsDirectoryPath,tString] error:nil];        }    }    NSLog(@"Write Started");    NSError *error = nil;    AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:                                  [NSURL fileURLWithPath:path] fileType:AVFileTypeMPEG4                                                              error:&error];        NSParameterAssert(videoWriter);    NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:                                   AVVideoCodecH264, AVVideoCodecKey,                                   [NSNumber numberWithInt:size.width], AVVideoWidthKey,                                   [NSNumber numberWithInt:size.height], AVVideoHeightKey,                                   nil];    AudioChannelLayout channelLayout;    memset(&channelLayout, 0, sizeof(AudioChannelLayout));    channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;音频文件的AssetWriterInput的状态始终为“ NO”。我的问题:如何使用AVFoundation将音频添加到视频文件?因此,请有人告诉我是否忘记某事或某事有误,可以帮助我。非常感谢你
查看完整描述

3 回答

?
陪伴而非守候

TA贡献1757条经验 获得超8个赞

AVChannelLayoutKey应该指向一个包含AudioChannelLayout的NSData实例。

您指向一个NSNumber。


查看完整回答
反对 回复 2019-12-11
  • 3 回答
  • 0 关注
  • 502 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信