如何检查视频文件是否大于2MB?
假设我从 iPhone 库中获取了一个视频文件。我想检查视频文件不应大于 2MB。
我无法使用 videoMaximumDuration 方法。因为如果任何视频是高清质量的,即使是 1 分钟持续时间的视频也可能会很大。
有什么意见吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
urlvideo 包含所选视频文件的 URL
urlvideo contains the url of selected video file
如果您希望确保视频的文件大小,以下内容将会有所帮助。
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:
谢谢,
If you wish to ensure the file size of video than following will help.
http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/LowLevelFileMgmt/Articles/FileInfo.html#//apple_ref/doc/uid/TP40009068-SW1
http://developer.apple.com/library/mac/#documentation/cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html#//apple_ref/occ/instm/NSURL/resourceValuesForKeys:error:
and
http://developer.apple.com/library/mac/#documentation/cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html#//apple_ref/occ/instm/NSURL/getResourceValue:forKey:error:
Thanks,
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.