7

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

Felix Schwarz
  • 2,938
  • 4
  • 28
  • 41

3 Answers3

11
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.

Nick Retallack
  • 18,986
  • 17
  • 92
  • 114
3

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:


EDIT:

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

Mr Fooz
  • 109,094
  • 6
  • 73
  • 101
  • so this means there is no library which can return that information? – Felix Schwarz Jul 31 '10 at 14:23
  • I looked at pyffmpeg but I couldn't figure out how to get the information I wanted out of it. Also it wont compile on my mac without extensive patching from the mailing lists, and even then it just gives me a Bus Error 10 when I try to open a file with it. – Nick Retallack Feb 04 '12 at 01:19
1

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