iOS 获取视频的某一针和获取视频名字

#pragma mark 获取视频的某一针
- (UIImage*)getThumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time {
    
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
    NSParameterAssert(asset);
    AVAssetImageGenerator *assetImageGenerator =[[AVAssetImageGenerator alloc] initWithAsset:asset];
    assetImageGenerator.appliesPreferredTrackTransform = YES;
    assetImageGenerator.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;
    
    CGImageRef thumbnailImageRef = NULL;
    CFTimeInterval thumbnailImageTime = time;
    NSError *thumbnailImageGenerationError = nil;
    thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60)actualTime:NULL error:&thumbnailImageGenerationError];
    
    if(!thumbnailImageRef)
    NSLog(@"thumbnailImageGenerationError %@",thumbnailImageGenerationError);
    
    UIImage*thumbnailImage = thumbnailImageRef ? [[UIImage alloc]initWithCGImage: thumbnailImageRef] : [UIImage imageNamed:@"影像录入_附件_15"];
    
    return thumbnailImage;
}
#pragma mark 获取视频名字
- (NSString *)getVideoName:(NSString *)url {
    NSArray * urlArray = [url componentsSeparatedByString:@"?"];
    if (urlArray.count > 0) {
        NSArray * nameArray = [urlArray[0] componentsSeparatedByString:@"/"];
        if (nameArray.count > 0) {
            return nameArray.lastObject;
        }
    }
    NSDate *senddate = [NSDate date];
    NSString *date2 = [NSString stringWithFormat:@"%ld%@", (long)[senddate timeIntervalSince1970],@"1"];
    return  [NSString stringWithFormat:@"%@%@.mov",self.imageNameString,date2];
}

你可能感兴趣的:(ios随笔)