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];
有帮助吗?

解决方案 2

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.

其他提示

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.

you can also use this for getting size of video :

AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:YOURURL];

CMTime duration = playerItem.duration;
float seconds = CMTimeGetSeconds(duration);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top