如何检查视频文件是否大于2MB?

发布于 2024-11-07 11:07:48 字数 140 浏览 0 评论 0 原文

假设我从 iPhone 库中获取了一个视频文件。我想检查视频文件不应大于 2MB。

我无法使用 videoMaximumDuration 方法。因为如果任何视频是高清质量的,即使是 1 分钟持续时间的视频也可能会很大。

有什么意见吗?

Suppose I have taken a video file from iphone library. I want to put a check that Video file shouldn't be greater than 2MB.

I cant use videoMaximumDuration method. Because if any video is hd quality even 1 min duration video could be huge in size.

Any views ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夕嗳→ 2024-11-14 11:07:48

urlvideo 包含所选视频文件的 URL

            NSString *strurl=[urlvideo path];
            NSFileManager *fileManager = [NSFileManager defaultManager];
            NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:strurl error:nil];

        if(fileAttributes != nil)
            {
                NSString *fileSize = [fileAttributes objectForKey:NSFileSize];
                //NSLog(@"File size: %@ kb", fileSize);             
                if ([fileSize intValue] > 2000000) {                    
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"File size greater than 2MB.Please select another video file." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [alert show];
                    [alert release];
                }               
                else {
NSLog(@"video size less than 2 mb");
    }

urlvideo contains the url of selected video file

            NSString *strurl=[urlvideo path];
            NSFileManager *fileManager = [NSFileManager defaultManager];
            NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:strurl error:nil];

        if(fileAttributes != nil)
            {
                NSString *fileSize = [fileAttributes objectForKey:NSFileSize];
                //NSLog(@"File size: %@ kb", fileSize);             
                if ([fileSize intValue] > 2000000) {                    
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"File size greater than 2MB.Please select another video file." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [alert show];
                    [alert release];
                }               
                else {
NSLog(@"video size less than 2 mb");
    }
往日情怀 2024-11-14 11:07:48

如果您希望确保视频的文件大小,以下内容将会有所帮助。

http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/LowLevelFileMgmt/Articles/FileInfo.html#//apple_ref/doc/uid/TP40009068-SW1

<一href="http://developer.apple.com/library/mac/#documentation/cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html#//apple_ref/occ/instm/NSURL/resourceValuesForKeys:error" rel="nofollow">http://developer.apple.com/library/mac/#documentation/cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html#//apple_ref/occ/instm/NSURL/resourceValuesForKeys :错误:

http://developer.apple.com/library/mac/#documentation/cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html#//apple_ref/occ/instm/NSURL/getResourceValue :forKey:error

谢谢,

提笔落墨 2024-11-14 11:07:48

NSURL 解决方案不起作用,因为用户 iPod 或照片库中视频的 url 不是文件 url,而是 MediaPlayer 或 ALAssetLibrary 处理的特殊方案。 (我对 ALAssetLibrary 这样做并不乐观,但我知道 MediaPlayer 会这样做,并且可以想象照片库也会这样做,所以你不能在它背后弄乱东西)。

我能想到的最好的解决方案是使用 URL 创建一个 AVURLAsset,然后迭代曲目并将estimatedDataRate 乘以曲目持续时间(以秒为单位)。这将为您提供每个轨道的粗略大小估计。

NSURL solutions won't work because the url to a video from the user's iPod or Photo library will not be a file url, but a special scheme that the MediaPlayer or ALAssetLibrary handles. (I'm not positive on the ALAssetLibrary doing this, but I know the MediaPlayer does it and would imagine the photo library does it too so you can't muck with stuff behind its back).

The best solution I can think of is to create an AVURLAsset with the URL, and then iterate through the tracks and multiply the estimatedDataRate by the track duration in seconds. That should give you a rough size estimate for each track.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文