0

以下は私のコードです

firstAsset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:_strThumbForegroundVideo] options:nil];

AVMutableComposition* mixComposition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *firstTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];

[firstTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, firstAsset.duration) ofTrack:[[firstAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil];

ログ:

_strThumbForegroundVideo の値は次のとおりです。

/private/var/mobile/Containers/Data/Application/80C71B40-87DA-449F-832C-1D27722727D8/tmp/90219F63-073E-4586-A1F6-DD68B627C3D1.mov

firstAsset の値は次のとおりです。

AVURLAsset: 0x1702362c0, URL = file:///private/var/mobile/Containers/Data/Application/80C71B40-87DA-449F-832C-1D27722727D8/tmp/90219F63-073E-4586-A1F6-DD68B627C3D1.mov

firstTrack の値は次のとおりです。

AVMutableCompositionTrack: 0x174033b20 trackID = 1, mediaType = vide, editCount = 0

「insertTimeRange」を実行しているときに、このエラーが発生します。

-[__NSArrayM objectAtIndex:]; // index 0 beyond bounds for empty array' while using insertTimeRange in AVMutableComposition

このリンクのチュートリアルを使用して 2 つのビデオをマージしようとしています。唯一の違いは、このチュートリアルでは、写真からビデオをインポートし、最近記録したビデオのパスを AVAsset に変換してから、同じ機能を実行していることです。私が記録したビデオは、ギャラリーと私が持っているのと同じパスで見つけることができます。

ここでは、オプションではないので、とにかくビデオ アセットが必要です。したがって、次のようなものは使用できません

NSArray *dataSourceArray = [NSArray arrayWithArray: [firstAsset tracksWithMediaType:AVMediaTypeVideo]];
[firstTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, firstAsset.duration)
                                                                   ofTrack:([dataSourceArray count]>0)?[dataSourceArray objectAtIndex:0]:nil
                                                                    atTime:kCMTimeZero
                                                                     error:nil]; 

実装はXcode 8.1で行われます

4

1 に答える 1