Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Detect codecs used in a video container

I have a couple of video container files which contain audio and video in various codecs. Now I'd like to inspect the container from a Python script to know which codec is used for audio+video. This is on a linux box so I have all the tools available if necessary.

I thought that maybe gstreamer could help me here but I was unable to find an API which could help me here.

Any ideas? I'm also open for any suggestion, doesn't need to be gstreamer as long as it is free software :-) fs

like image 925
Felix Schwarz Avatar asked Jul 31 '10 12:07

Felix Schwarz


3 Answers

ffprobe -show_format -show_streams -loglevel quiet -print_format json YOUR_FILE

Just invoke this with subprocess.check_output and you'll get a beautiful JSON description of your media file. If you need it to grab the data from stdin, replace YOUR_FILE with pipe:0.

ffprobe comes with ffmpeg.

like image 77
Nick Retallack Avatar answered Sep 28 '22 03:09

Nick Retallack


Try downloading the ffmpeg source and look at the source for their command line programs. I've hacked up similar utilities in the past. I'm not posting my solution because ffmpeg likes to change their API, so my old code is unlikely to compile with the current version. You'll want to do enough work to create codec context, which you can inspect to get what you need.

Some other alternatives:

  • MediaInfo: http://mediainfo.sourceforge.net/en

  • GSpot (Windows only): http://www.headbands.com/gspot/


EDIT:

http://code.google.com/p/pyffmpeg/ might have what you want (I haven't used it myself).

like image 35
Mr Fooz Avatar answered Sep 28 '22 03:09

Mr Fooz


You can use decodebin2 in Gstreamer. Take a look at TAE for code examples.

like image 20
Andreas Tunek Avatar answered Sep 28 '22 04:09

Andreas Tunek