views:

179

answers:

5

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.

A: 

Read the header and look for codec details?
Mediainfo is an opensource video file info analyser

Sorry don't know any ipad specific stuff

Martin Beckett
A: 

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.

Joshua Weinberg
A: 

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.

Jasconius
Yes but that is slow. Can be over a few seconds per file just to prep them.
Marcus S. Zarra
Under what circumstances then are videos ending up on the phone? From a server? Can't you do this processing on the server where libs are more available?
Jasconius
+5  A: 

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.

sarnold
`file(1)` is not on iOS by default but I am going to explore compiling and adding it with the application.
Marcus S. Zarra
A: 

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.

bluesmoon