【问题标题】:AVAssetTrack Combine video not okay in iOS 7AVAssetTrack 在 iOS 7 中组合视频不好
【发布时间】:2014-03-17 05:57:31
【问题描述】:

我可以在 iOS 6 中成功地将 2 个视频合并为 1 个。但我不知道在 iOS 7 中会发生什么。我遇到了这样的数组错误。

由于未捕获的异常 'NSRangeException' 导致应用程序终止,原因:'* -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

这是我编写的代码的一部分。我已经在代码中显示了哪里错误。我该怎么办?

NSMutableArray *array = [[NSMutableArray alloc]init ];

for(int kk=0;kk < trackRecordingVideoName+1; kk++)
{
    [array addObject:[[self userPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%d.mp4",recordingVideoName,kk]]];
    NSLog(@"%d is added",kk);
}

videoPathArray= [[NSArray alloc]initWithArray:array];
[videoPathArray retain];


AVMutableComposition *composition = [AVMutableComposition composition];

AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];


CMTime startTime = kCMTimeZero;


NSLog(@"videoPathArray.count is %d",videoPathArray.count);
for (NSInteger i=0; i < videoPathArray.count; i++) {

    NSLog(@"For loop now is %d and name is %@",i,[videoPathArray objectAtIndex:i]);
    NSString *path = (NSString*)[videoPathArray objectAtIndex:i];

    NSURL *url = [[NSURL alloc] initFileURLWithPath:path];

    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];

    [url release];

    //*************************************
    AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];//This is the error
    //*************************************


    if(i == 0)
    {
        [compositionVideoTrack setPreferredTransform:videoTrack.preferredTransform];
    }

    Boolean ok = [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [asset duration]) ofTrack:videoTrack atTime:startTime error:nil];

    if(ok)
    {NSLog(@"can combine in for loop");}
    else{NSLog(@"cannot combine in for loop");}

    startTime = CMTimeAdd(startTime, [asset duration]);
}

【问题讨论】:

    标签: objective-c ipad ios7 ios6 record


    【解决方案1】:

    检查url是否正确,它应该指向一个真实的视频文件,你的AVURLAsset不包含任何视频媒体类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多