我又来这里找AVFoundation的帮助了。抱歉,我的英语不太好。
我现在在编视频编辑。首先,我从库中加载视频并将其放到AVAsset实例中。然后,每次用户选择某个视频区域并在那里设置速度参数时,我都会这样做:
AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *track = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
[track insertTimeRange:CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(startOfEditedFrame, 600))
ofTrack:[self.videoAsset tracksWithMediaType:AVMediaTypeVideo][0] atTime:mixComposition.duration error:&error];
[track insertTimeRange:CMTimeRangeFromTimeToTime(CMTimeMakeWithSeconds(startOfEditedFrame, 600), CMTimeMakeWithSeconds(endOfEditedFrame, 600))
ofTrack:[self.videoAsset tracksWithMediaType:AVMediaTypeVideo][0] atTime:mixComposition.duration error:nil];
[track scaleTimeRange:CMTimeRangeFromTimeToTime(CMTimeMakeWithSeconds(startOfEditedFrame, 600), CMTimeMakeWithSeconds(endOfEditedFrame, 600))
toDuration:CMTimeMultiplyByFloat64(CMTimeMakeWithSeconds(endOfEditedFrame - startOfEditedFrame, 600), 1/[self.speeds[self.currentFrameStartIndex] floatValue])];
[track insertTimeRange:CMTimeRangeFromTimeToTime(CMTimeMakeWithSeconds(endOfEditedFrame, 600), self.videoAsset.duration)
ofTrack:[self.videoAsset tracksWithMediaType:AVMediaTypeVideo][0] atTime:mixComposition.duration error:nil];
self.videoAsset = mixComposition;第一次工作正常,但是第二次我有"insertTimeRange“错误,作文的持续时间为零。请告诉我,如果你有什么想法,这里出了什么问题,或有任何建议,如何以不同的方式/更正确的做法。
发布于 2014-04-02 16:59:47
我可以提供的一个指针是查看AVMutableComposition的头文件。
insertTimeRange方法的注释讨论了tracks参数:
指定包含要插入的轨道的资产。只支持
AVURLAsset的实例。
因此,您从轨道插入的曲目必须属于AVURLAsset类,并且只属于这个类。
https://stackoverflow.com/questions/21589058
复制相似问题