user396243
user396243

Reputation:

How can I identify a video format in Python3?

I'd like to be able to open a given file, and see that "This is a MP4 file", or "This is a webm" file, or even "This does not appear to be a valid video"

I saw the FFmpeg wrapper, at https://code.google.com/p/pyffmpeg/, but I didn't see any sort of get_codec function inside of it.

Thoughts?

Upvotes: 2

Views: 4048

Answers (3)

jlhasson
jlhasson

Reputation: 2286

You can use the python equivalent to the unix file utility via python-magic: Is there a python-equivalent of the unix "file" utility?

Upvotes: 0

Scott Griffiths
Scott Griffiths

Reputation: 21925

Take a look at Hachoir. It 'extracts metadata from multimedia files'.

Here's their example of metadata extraction from an AVI file:

$ hachoir-metadata pacte_des_gnous.avi
Common:
- Duration: 4 min 25 sec
- Comment: Has audio/video index (248.9 KB)
- MIME type: video/x-msvideo
- Endian: Little endian
Video stream:
- Image width: 600
- Image height: 480
- Bits/pixel: 24
- Compression: DivX v4 (fourcc:"divx")
- Frame rate: 30.0
Audio stream:
- Channel: stereo
- Sample rate: 22.1 KHz
- Compression: MPEG Layer 3

Upvotes: 4

Geoffrey
Geoffrey

Reputation: 11353

My python is a bit rusty, but a quick look over the module turns these up.

To get the Codec ID:

Track.CodecCtx.codec_id

To get the Codec itself (AVCodec):

Track.Codec

AVCodec contains the codec name.

Upvotes: 3

Related Questions