2

を使用してビデオを選択した後UIImagePickerController、ビデオのファイル サイズをその [defaultRepresentation size].
ただし、ピッカーのトリミング オプションを有効にする[defaultRepresentation size]と、元のトリミングされていないビデオと同じファイル サイズが返されます。

トリミングされたビデオのファイルサイズを取得する方法はありますか?

とても有難い...

はい、コードを含める必要がありました。私が悪い。

私が達成しようとしているのは、ユーザーに既存のビデオを選択してトリミングしてから、トリミングしたバージョンをアップロードさせることです。アップロード中にプログレス バーに入力するために、トリミングされたバージョンのファイル サイズが必要です。トリミングされたバージョンの期間もお願いします。

呼び出し方法は次のとおりです。

-(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私自身のカスタムクラスです。2 つの NSLog は、元のトリミングされていないビデオの長さとサイズを返します。で指定されたビデオ[vvi setRawSourceVideoFileURL:[info objectForKey:UIImagePickerControllerMediaURL]];は、適切にトリミングされたビデオを返します。

ありがとうございます!

4

1 に答える 1