Page 1 of 1

Determine if file is audio or video

Posted: 15 Mar 2024 23:17
by chundermike
Hi,

I'm trying to determine when reading a media file if it's audio only (i.e. mp3) or has video (i,e. mp4). If possible, I don't want to rely in the file extension. I've noticed a structure called libvlc_track_type_t (which has audio and video representations) but can't see any library function which uses it. Is it possible to determine if a file is audio only or is video using this structure or is there another way?

Thanks,
Mike

Re: Determine if file is audio or video

Posted: 20 Mar 2024 05:18
by mfkl
Sure I guess. These are tracks though, but if there is no video track, I guess you could assume it is an audio file.

Re: Determine if file is audio or video

Posted: 14 Jun 2024 06:36
by Gronky
A quick and dirty (but far from foolproof) method would be to look at the first few bytes of the file - if it contains the string "ID3" you could be reasonably sure it's an MP3, or if it has the string "RIFF" you could be reasonably sure it's a wave audio file.