0

I created Camera using UIImagePickerController, after take a video. I clicked on Use Video, I saved this video to Photo library. And now I want to get size of this video. I used AlAssetLibrary to save video to Photo library. How can get size of the video has just taken? Please help me. Thanks in advance.

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

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    NSURL *recordedVideoURL= [info objectForKey:UIImagePickerControllerMediaURL];
    if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:recordedVideoURL]) {
        [library writeVideoAtPathToSavedPhotosAlbum:recordedVideoURL
                                    completionBlock:^(NSURL *assetURL, NSError *error){}
         ];
    }

}

I tried below code to get size of video but not works:

 ALAssetRepresentation *rep = [alasset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);
NSError *error = nil;
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:&error];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
user3168540
  • 77
  • 2
  • 9

3 Answers3

1

1) Please see this question to get your video.

2) After getting your video convert it into NSData as refer this question.

3)Now use NSData's length function .

It will give to to get the length of your video file.

Community
  • 1
  • 1
Ankush
  • 2,405
  • 3
  • 22
  • 45
0

you can also use this for getting size of video :

AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:YOURURL];

CMTime duration = playerItem.duration;
float seconds = CMTimeGetSeconds(duration);
Shubham
  • 570
  • 3
  • 12
0

You can do it in three ways

1.Use NSData length

    ALAssetRepresentation *rep = [alasset defaultRepresentation];
    Byte *buffer = (Byte*)malloc(rep.size);
    NSError *error = nil;
    NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:&error];
    NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
    NSLog(@"Size of video %d",data.length); 

2.Make use of ALAssetRepresentationsize

3.Worst-Case Scenario: Use the videoPathURL that points to the saved video file, retrieve it again using ALAsset and caliculate the size.

Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102