views:

100

answers:

2

I am trying to extract the prevailing bitrate of a video file (e.g. .mkv file containing a movie) at a regular sampling interval of between 1-10 seconds under conditions of normal playback. Kind of like you may see in vlc, during playback of the file in the statistics window.

Can anyone suggest the best way to bootstrap the coding of such an analyser? Is there a library that provides an API to such information that people know of? Perhaps a Python wrapper for ffmpeg or equivalent tool that processes video files and can thereby extract such statistics.

What I am really aiming for is a CSV format file containing the seconds offset and the average or actual bitrate in KiB/s at that offset into the asset.

Update:

I built pyffmpeg and wrote the following spike:

import pyffmpeg

reader = pyffmpeg.FFMpegReader(False)
reader.open("/home/mark/Videos/BBB.m2ts", pyffmpeg.TS_VIDEO)
tracks=reader.get_tracks()

# Called for each frame
def obs(f):
  pass

tracks[0].set_observer(obs)
reader.run()

But observing frame information (f) in the callback does not appear to give me any hooks to calculate per second bitrates. In fact bitrate calculations within pyffmpeg are measured across the entire file (filesize / duration) and so the treatment within the library is very superficial. Clearly its focus is on extract i-frames and other frame/GOP specific work.

+1  A: 

Something like these:

http://code.google.com/p/pyffmpeg/

http://pymedia.org/

jknair
pyffmpeg does not give me what I need as its treatment of bitrates is superficial and I cannot extract per-frame (P/B/I) data sizes from which to infer per second data throughput AFAICT.
landstatic
Next stop pymedia...
landstatic
Building pymedia on latest Ubuntu was a pig... and pymedia does not handle m2ts or mkv containers but rather is intended to process elementary streams only.
landstatic
So whilst I am grateful for the leads, they have not led me to a solution unfortunately.
landstatic
I shall try ffmpeg to unpack and then pymedia to demux the video ES and measure bitrate and report back soon...
landstatic
A: 

You should be able to do this with gstreamer. http://pygstdocs.berlios.de/pygst-tutorial/seeking.html has an example of a simple media player. It calls

pos_int = self.player.query_position(gst.FORMAT_TIME, None)[0]

periodically. All you have to do is call query_position() a second time with gst.FORMAT_BYTES, do some simple math, and voila! Bitrate vs. time.

joeforker