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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With