快速判断文件是否为有效视频

发布于 2024-09-07 18:29:33 字数 269 浏览 6 评论 0原文

确定文件是否是可播放视频的最快方法是什么?我并不关心它是否损坏,而是关心它是否是可以在 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 技术交流群。

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

发布评论

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

评论(5

初吻给了烟 2024-09-14 18:29:33

file(1) 命令(以及关联的 libmagic) 可以在标准 Unix 系统上完成这项工作;如果苹果没有将其纳入手机操作系统中,您可能可以自己让它在手机上运行。 (在我的 x86-64 Linux 系统上,该库为 109k。)

在我的计算机上,它在不到 7 秒的时间内将 146 个易于访问的视频分类为 18 种不同的格式。 (120 GB。)它出了一些问题:

$ sort -u /tmp/out
data
ISO Media, MPEG v4 system, version 1
Matroska data
Microsoft ASF
MPEG transport stream data
RIFF (little-endian) data, AVI, 384 x 240, 25.00 fps, video: DivX 5, audio: MPEG-1 Layer 3 (mono, 44100 Hz)
RIFF (little-endian) data, AVI, 384 x 288, 25.00 fps, video: DivX 3 Low-Motion, audio: DivX (stereo, 44100 Hz)
RIFF (little-endian) data, AVI, 512 x 272, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 512 x 288, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 44100 Hz)
RIFF (little-endian) data, AVI, 512 x 288, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 512 x 328, 25.00 fps, video: DivX 5, audio: MPEG-1 Layer 3 (stereo, 32000 Hz)
RIFF (little-endian) data, AVI, 512 x 328, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 32000 Hz)
RIFF (little-endian) data, AVI, 572 x 304, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 576 x 320, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 608 x 336, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 624 x 352, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 640 x 352, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
TeX font metric data (\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377

在这些速度下,也许你可以容忍一点噪音并退回到较慢的机制;或者也许用它还不知道的格式填写规则。

The file(1) command (and associated libmagic) 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:

$ sort -u /tmp/out
data
ISO Media, MPEG v4 system, version 1
Matroska data
Microsoft ASF
MPEG transport stream data
RIFF (little-endian) data, AVI, 384 x 240, 25.00 fps, video: DivX 5, audio: MPEG-1 Layer 3 (mono, 44100 Hz)
RIFF (little-endian) data, AVI, 384 x 288, 25.00 fps, video: DivX 3 Low-Motion, audio: DivX (stereo, 44100 Hz)
RIFF (little-endian) data, AVI, 512 x 272, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 512 x 288, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 44100 Hz)
RIFF (little-endian) data, AVI, 512 x 288, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 512 x 328, 25.00 fps, video: DivX 5, audio: MPEG-1 Layer 3 (stereo, 32000 Hz)
RIFF (little-endian) data, AVI, 512 x 328, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 32000 Hz)
RIFF (little-endian) data, AVI, 572 x 304, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 576 x 320, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 608 x 336, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 624 x 352, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
RIFF (little-endian) data, AVI, 640 x 352, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)
TeX font metric data (\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377

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.

維他命╮ 2024-09-14 18:29:33

阅读标题并查找编解码器详细信息?
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

寄离 2024-09-14 18:29:33

我想说你需要做的是获取文件的 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.

淡淡の花香 2024-09-14 18:29:33

除了检查文件扩展名之外,您是否应该无法简单地播放该文件并且电影播放器​​对象将向委托发出信号表明该文件无法播放?或者在最坏的情况下,你可以尝试一个令人讨厌的 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.

玻璃人 2024-09-14 18:29:33

一般来说,文件的前几个字节会告诉您文件类型。这就是 libmagicfile 命令的作用。如果您不想在 iOS 上构建 libmagic,您可以简单地查看它正在做什么,然后提取您关心的查找表的子集。

In general, the first few bytes of the file will tell you the file type. That's what libmagic and the file 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.

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