Search code examples
pythonpython-3.xmp4webm

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?


Solution

  • 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