2012-04-12 67 views
1

使用UIImagePickerController選擇視頻後,我可以從其 [defaultRepresentation size]中獲取視頻的文件大小。
但是,如果啓用了選取器的修剪選項,則[defaultRepresentation size]將返回與原始未修剪視頻相同的文件大小。從UIImagePickerController獲取修剪後的視頻文件大小

沒有人有檢索修整後的視頻文件的大小的方法?

非常感謝...

是的,我應該包括一些代碼。我不好。

我試圖做到的,是讓用戶選擇和修整現有的視頻,然後上傳修剪的版本。我想要修剪版本的文件大小,以便在上傳過程中填充進度欄。我也想修剪版本的持續時間。

的調用方法:

-(IBAction)selectVideoPressed:(id)sender 
{ 

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) 

{ 

    UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init]; 
    [videoPicker setDelegate: self]; 
    [videoPicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; 
    [videoPicker setMediaTypes:[NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil]]; 
    [videoPicker setVideoQuality:vvi.videoQuality]; 
    [videoPicker setAllowsEditing:YES]; 
    [videoPicker setModalTransitionStyle:gTransitionStyle]; 

    [self presentViewController:videoPicker animated:YES completion:Nil]; 

} 

} 

用戶已修剪和壓選擇後觸發的委託方法是:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 

[vvi setRawSourceVideoFileURL:[info objectForKey:UIImagePickerControllerMediaURL]]; 
[vvi setSourceVideoURL:[info objectForKey:UIImagePickerControllerReferenceURL]]; 

ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init]; 
ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *myAsset) 

{ 

    // Video metrics info. 

    [vvi setVideoDuration:[myAsset valueForProperty:ALAssetPropertyDuration]]; 
    [vvi setVideoOrientation:[myAsset valueForProperty:ALAssetPropertyOrientation]]; 
    NSDate *videoDate = [myAsset valueForProperty:ALAssetPropertyDate]; 
    [vvi setVideoDateString:[videoDate descriptionWithLocale:[NSLocale currentLocale]]]; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setDateFormat:gShortDateFormat]; 
    [vvi setShortVideoDateString:[dateFormatter stringFromDate:videoDate]]; 

    ALAssetRepresentation *myAssetRepresentation = [myAsset defaultRepresentation]; 
    [vvi setVideoAssetSize:[NSNumber numberWithLongLong:[myAssetRepresentation size]]]; 

    NSLog(@"Duration:%@", vvi.videoDuration); 
    NSLog(@"Size:%@", vvi.videoAssetSize); 

}; 

.... 

vvi只是我自己的自定義類。 這兩個NSLog將返回原始未修剪視頻的持續時間和大小。指向[vvi setRawSourceVideoFileURL:[info objectForKey:UIImagePickerControllerMediaURL]];的視頻確實會返回經過適當修剪的視頻。

非常感謝!

+0

代碼片段ü試圖實現這一目標,需要返回。 – 2012-04-12 05:52:48

+0

@ hpiOSCoder是的,我猜代碼會幫助... – 2012-04-13 16:22:15

回答

1

像這樣的東西應該照顧找到一個選定的圖像或視頻文件的大小從的UIImagePickerController

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 

     NSURL *videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL]; 

     //Error Container 
     NSError *attributesError; 
     NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[videoUrl path] error:&attributesError]; 
     NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize]; 
     long long fileSize = [fileSizeNumber longLongValue]; 
} 
+0

這已被問到其他地方,但這是最完整的答案! – elliotrock 2015-03-28 11:50:29

+0

我們可以爲這個PLZ有一個快速的3版本 – 2017-02-15 11:09:59

相關問題