我正在嘗試使用圖片數組和音頻文件制作電影文件。為了制作帶有圖片陣列的電影,我在這里用了祖爾的大貼子。一切都太完美了,我的電影里有我的照片。但是,當我嘗試添加一些音軌時,會有很多問題。為了理解我把我的代碼:當我調用此方法時,圖片數組和歌曲文件已準備就緒:-(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 回答
- 0 關注
- 572 瀏覽
添加回答
舉報
0/150
提交
取消