这是我用来将视频合并在一起的方法的开始
-(void) mergeVideosAndAudio:(AVAsset *)audioAsset{
//Load Video Assets
NSError *error;
NSArray *dirFiles;
if ((dirFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[self documentsDirectory] error:&error]) == nil) {
// handle the error
};
// find all the temp files
NSArray *movFiles = [dirFiles filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self BEGINSWITH 'temp'"]];
NSLog(@"The are %i temp files",movFiles.count);
//Create assets array
NSMutableArray *assets = [[NSMutableArray alloc]init];
for (int i = 0; i < movFiles.count; i++) {
NSString *videoURL = [[self documentsDirectory] stringByAppendingPathComponent:
[NSString stringWithFormat:@"temp%i.mov", i]];
NSURL *url = [NSURL fileURLWithPath:videoURL];
AVURLAsset *videoAsset …Run Code Online (Sandbox Code Playgroud) 我知道之前已经回答了视频类型问题的持续时间,但我在.mp4使用AVAsset和获取文件的持续时间方面遇到了麻烦AVURLAsset.我正在使用以下代码
NSString *itemPathString = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0] stringByAppendingPathComponent:obmodel.actualname];
NSURL *itemPathURL = [NSURL URLWithString:itemPathString];
if([[NSFileManager defaultManager] fileExistsAtPath:itemPathString]){
NSLog(@"File Exists");
}
AVAsset *videoAsset = (AVAsset *)[AVAsset assetWithURL:itemPathURL];
AVAssetTrack *videoAssetTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
NSLog(@"duration: %.2f", CMTimeGetSeconds(videoAssetTrack.timeRange.duration));
if(CMTimeGetSeconds(videoAsset.duration) >= 59.0){
}
Run Code Online (Sandbox Code Playgroud)
但每次它返回0
我也导入以下headers
#import <AVFoundation/AVAsset.h>
#import <CoreMedia/CoreMedia.h>
#import <AVFoundation/AVFoundation.h>
Run Code Online (Sandbox Code Playgroud)
我也尝试了一些我知道的其他代码但是没有人能为我工作.如果我播放它iExplorer,我的视频工作正常,我的路径很好,但不知道我错过了什么.我想分享一下,我发现我AVAssets的装载不正确请告诉我应该做些什么.