日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS开发-UI控件:UIImagePickerController 视频录制操作,视频大小,时间长度

發布時間:2023/12/29 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS开发-UI控件:UIImagePickerController 视频录制操作,视频大小,时间长度 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉自:?http://www.cnblogs.com/cocoajin/p/3494290.html

簡介:

使用 iOS 系統?UIImagePickerController

  • 獲取視頻大小
  • 獲取視頻長度- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.self.title = @"AVVideo Demo";CGRect theFrame = CGRectMake(10, 15, 130, 20);[self addOpBtnWith:@"pick Video" frame:theFrame action:@selector(pickVideoTaped)];theFrame = CGRectMake(150, 15, 130, 20);[self addOpBtnWith:@"轉成mp4" frame:theFrame action:@selector(revoverToMp4)];}#pragma mark action//轉換格式為 mp4 - (void)revoverToMp4 {AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:_videoURL options:nil];NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];if ([compatiblePresets containsObject:AVAssetExportPresetHighestQuality]){AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAssetpresetName:AVAssetExportPresetHighestQuality];NSDateFormatter* formater = [[NSDateFormatter alloc] init];[formater setDateFormat:@"yyyy-MM-dd-HH:mm:ss"];NSString* _mp4Path = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/output-%@.mp4", [formater stringFromDate:[NSDate date]]];exportSession.outputURL = [NSURL fileURLWithPath: _mp4Path];exportSession.shouldOptimizeForNetworkUse = YES;exportSession.outputFileType = AVFileTypeMPEG4;[exportSession exportAsynchronouslyWithCompletionHandler:^{switch ([exportSession status]) {case AVAssetExportSessionStatusFailed:{UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error"message:[[exportSession error] localizedDescription]delegate:nilcancelButtonTitle:@"OK"otherButtonTitles: nil];[alert show];break;}case AVAssetExportSessionStatusCancelled:NSLog(@"Export canceled");break;case AVAssetExportSessionStatusCompleted:NSLog(@"Successful!");NSLog(@"%@",_mp4Path);NSLog(@"file Size %ldk",(long)[self getFileSize:_mp4Path]);break;default:break;}}];}else{UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error"message:@"AVAsset doesn't support mp4 quality"delegate:nilcancelButtonTitle:@"OK"otherButtonTitles: nil];[alert show];}}//彈出視頻拍攝- (void)pickVideoTaped {pickVideo = [[UIImagePickerController alloc]init];pickVideo.sourceType = UIImagePickerControllerSourceTypeCamera;NSArray* availableMedia = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];pickVideo.mediaTypes = [NSArray arrayWithObject:availableMedia[1]];pickVideo.delegate = self;[self presentViewController:pickVideo animated:YES completion:nil];} #pragma mark - UIImagePickerControllerDelegate//拍照完成代理 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {NSLog(@"%@",info);_videoURL = info[UIImagePickerControllerMediaURL];NSString * size = [NSString stringWithFormat:@"%ld kb", (long)[self getFileSize:[[_videoURL absoluteString] substringFromIndex:16]]];NSString *length = [NSString stringWithFormat:@"%.0f s", [self getVideoDuration:_videoURL]];NSLog(@"-------------%@%@",size,length);[picker dismissViewControllerAnimated:YES completion:nil];}//取消代理- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {[picker dismissViewControllerAnimated:YES completion:nil]; }//獲取視頻時間 - (CGFloat) getVideoDuration:(NSURL*) URL {NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]forKey:AVURLAssetPreferPreciseDurationAndTimingKey];AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:URL options:opts];float second = 0;second = urlAsset.duration.value/urlAsset.duration.timescale;return second; }//獲取視頻 大小 - (NSInteger) getFileSize:(NSString*) path {NSFileManager * filemanager = [[NSFileManager alloc]init];if([filemanager fileExistsAtPath:path]){NSDictionary * attributes = [filemanager attributesOfItemAtPath:path error:nil];NSNumber *theFileSize;if ( (theFileSize = [attributes objectForKey:NSFileSize]) )return [theFileSize intValue]/1024;elsereturn -1;}else{return -1;} }- (void)addOpBtnWith:(NSString *)name frame:(CGRect)frame action:(SEL)action {UIButton *aBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];aBtn.frame = frame;[aBtn setTitle:name forState:UIControlStateNormal];[aBtn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:aBtn]; }

總結

以上是生活随笔為你收集整理的iOS开发-UI控件:UIImagePickerController 视频录制操作,视频大小,时间长度的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。