gpt4 book ai didi

iphone - 有 AVMutableComposition 视频创建问题

转载 作者:行者123 更新时间:2023-11-29 10:58:45 25 4
gpt4 key购买 nike

我正在尝试合并 .mp4 和 .caf 文件,所以我使用以下代码,

AVMutableCompositionTrack *compositionVideoTrack = 
[mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)
ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
atTime:kCMTimeZero
error:nil];

但是我得到了错误

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' *** First throw call stack: (0x32c4d2a3 0x3aae397f 0x32b98b75 0x748e7 0x74e61 0x34b400c5 0x34b40077 0x34b40055 0x34b3f90b 0x34b3fe01 0x34a685f1 0x34a55801 0x34a5511b 0x367495a3 0x32c22683 0x32c21ee9 0x32c20cb7 0x32b93ebd 0x32b93d49 0x367482eb 0x34aa9301 0x6f767 0x6f708) libc++abi.dylib: terminate called throwing an exception


所有需要的框架和 .dylib 文件都包含在内。

最佳答案

打印您的数组计数。它必须是一个空数组,这就是您的应用程序崩溃的原因。检查一下。 NSlog(@"array count => %d",[videoAsset tracksWithMediaType:AVMediaTypeVideo]);

并用以下代码替换您的代码以防止崩溃。

 AVMutableCompositionTrack *compositionVideoTrack = 
[mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
NSArray *dataSourceArray = [NSArray arrayWithArray: [videoAsset tracksWithMediaType:AVMediaTypeVideo];
NSlog(@"array count => %d",[dataSourceArray count]);
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)
ofTrack:([dataSourceArray count]>0)?[dataSourceArray objectAtIndex:0]:nil
atTime:kCMTimeZero
error:nil];

关于iphone - 有 AVMutableComposition 视频创建问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17064382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com