2013-04-28 52 views
0

是否可以確定用戶使用UIImagePickerController選擇的視頻是否被修剪?UIImagePickerController - 確定視頻是否被修剪或編輯

我的應用程序允許用戶向對方發送短視頻。如果他們在應用程序中錄製視頻,我會將其副本保存回其畫廊,以便他們可以在下次輕鬆發送視頻。我希望對裁剪後的視頻執行相同操作,但不會裁剪未剪裁的視頻,因爲這隻會導致重複。

我使用這個代碼:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
imagePicker.delegate = self; 
[imagePicker setVideoQuality:UIImagePickerControllerQualityType640x480]; 
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie]; 
[imagePicker setVideoMaximumDuration:6]; 
imagePicker.allowsEditing = YES; 

[self presentModalViewController:imagePicker animated:YES]; 

我使用NSURL已經嘗試返回確定視頻修剪或沒有,但遺憾的是,即使未修剪視頻回來是這樣的:「 trim.DBOnmL.MOV「並查看了文檔,我找不到任何有用的屬性。

- 編輯

我已經實現imagePickerController:didFinishPickingMediaWithInfo:,我只是不想看到任何屬性返回讓我知道,如果它被編輯。

謝謝!

回答

0

您應該實施imagePickerController:didFinishPickingMediaWithInfo:委託方法。 info字典包含一些有關用戶是否編輯圖像/視頻的有用信息。

+0

對不起,我應該說我已經有了,但沒有看到任何返回的屬性,讓我知道如果視頻被修剪/編輯。我已更新我的問題 – 2013-04-28 15:37:38

3

我找到了解決方案。

imagePickerController:didFinishPickingMediaWithInfo:返回一個url到原始視頻資產和修剪(即使未修剪)的視頻資產。

您可以簡單地獲取原始視頻和修剪過的視頻(即使未修剪)的持續時間,並將它們進行比較,如果不同,則會對其進行修剪。

這麼一來,你的兩個網址:

NSURL *originalVideoAssetUrl = [info objectForKey:UIImagePickerControllerReferenceURL]; 
    NSURL *videoAssetUrl = [info objectForKey:UIImagePickerControllerMediaURL]; 

..這讓你的資產的持續時間

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:assetUrl 
               options:[NSDictionary dictionaryWithObjectsAndKeys: 
                  [NSNumber numberWithBool:YES], 
                  AVURLAssetPreferPreciseDurationAndTimingKey, 
                  nil]]; 

    NSTimeInterval durationInSeconds = 0.0; 
    if (asset) 
     durationInSeconds = CMTimeGetSeconds(asset.duration); 
0

你可以加載2個視頻剪輯成NSData的進行比較,並使用'長度'來比較大小。剪輯的視頻會更少。

+0

這不行。所選視頻通常會有不同的大小,因爲即使用戶沒有對其進行編輯,它也會被壓縮。 – murat 2013-04-28 16:31:10

+0

感謝您的建議,但我找到了一個適用於我的解決方案。我已經把它寫成了一個答案 – 2013-04-28 16:38:03