快速判断文件是否为有效视频
确定文件是否是可播放视频的最快方法是什么?我并不关心它是否损坏,而是关心它是否是可以在 iPad 上播放的哑剧类型。
我已经按照另一个问题的建议通过 NSURL
推送文件,但这可能需要 >每个文件 1 秒,太慢了。
我目前正在查看文件扩展名,但更希望有更确定的东西。
更新
我很想在应用程序内部使用 UTI,但我也没有找到任何公开的方法来从这个方向实现它。如果有人知道一种在 3.2 上获取文件的 UTI 的方法,那就行了。
What is the fastest way to determine if a file is playable video? I am not concerned with it being corrupt or not but just whether it is a mime-type that should be playable on the iPad.
I have played with pushing the file through a NSURL
as suggested by another question but that can take > 1 second per file which is too slow.
I am currently looking at the file extension but would much rather have something that is more certain.
update
I would love to use UTIs internally to the app but I have not found any exposed way to come at it from that direction either. If anyone knows of a way to get at the UTI of a file on 3.2 that would work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
file(1)
命令(以及关联的libmagic) 可以在标准 Unix 系统上完成这项工作;如果苹果没有将其纳入手机操作系统中,您可能可以自己让它在手机上运行。 (在我的 x86-64 Linux 系统上,该库为 109k。)
在我的计算机上,它在不到 7 秒的时间内将 146 个易于访问的视频分类为 18 种不同的格式。 (120 GB。)它出了一些问题:
在这些速度下,也许你可以容忍一点噪音并退回到较慢的机制;或者也许用它还不知道的格式填写规则。
The
file(1)
command (and associatedlibmagic
) can do this job on standard Unix systems; if Apple didn't include it into the phone OS, you can probably get it to run on the phone yourself. (On my x86-64 Linux system, the library is 109k.)On my computer, it classified 146 easily-accessible videos into 18 different formats in under seven seconds. (120 gigabytes.) It got some wrong:
At those speeds, perhaps you can tolerate a little noise and fall back to a slower mechanism; or perhaps fill out the rules with formats it doesn't yet know.
阅读标题并查找编解码器详细信息?
Mediainfo 是一个开源视频文件信息分析器
抱歉不知道任何 iPad 特定的东西
Read the header and look for codec details?
Mediainfo is an opensource video file info analyser
Sorry don't know any ipad specific stuff
我想说你需要做的是获取文件的 UTI,这在桌面上可以使用 LaunchServices 来完成。我不知道苹果是否公开了在 iOS 上执行此操作的 API。
I'd say what you need to do is get the UTI of the file, which on the desktop would be done using LaunchServices. I don't know if apple exposed an API to do so on iOS.
除了检查文件扩展名之外,您是否应该无法简单地播放该文件并且电影播放器对象将向委托发出信号表明该文件无法播放?或者在最坏的情况下,你可以尝试一个令人讨厌的 try/catch。
On top of checking the file extension, should you not be able to simply play the file and the movie player object will signal to the delegate that it could not be played? Or in the worst case you can try a nasty try/catch.
一般来说,文件的前几个字节会告诉您文件类型。这就是
libmagic
和file
命令的作用。如果您不想在 iOS 上构建 libmagic,您可以简单地查看它正在做什么,然后提取您关心的查找表的子集。In general, the first few bytes of the file will tell you the file type. That's what
libmagic
and thefile
command do. If you don't want to build libmagic on iOS, you could simply look at what it's doing, and pull in the subset of the lookup table that you care about.