How to extract and modify data rate and time scale from OpenDML (AVI) file I'm working on a Python script to bulk transcode video files. These files will have different framerates, and one of the goals is to get them all to the same framerate, by making some intelligent decisions on whether to slow down or speed up the playback or to decimate or duplicate frames. As I understand it, the framerate is stored as two 32-bit integers, for example 29.97 fps is actually stored as 30000/1001, and I need to work with these values. I'll also use these values to calculate how much to stretch and pitch shift the audio. The framerates of the source files are not necessarily standard ones, but they may be anything from slightly off from PAL or NTSC to completely screwed up, and using the values that are actually in the files makes it easier to make the calculations.

So, how can I extract them, and, in the case of slowing down or speeding up the video, write back modified values?
Preferably a commandline tool (needs to run on FreeBSD).
I'm also open to parsing the headers directly from the script, but unfortunately I don't know where to find them.

The specs I've found more or less list the various structs (as defined in C) for the various headers, and a more skilled programmer may be able to use this, but I need a simpler explanation. I don't need help with the actual scripting, I just need help understanding where the information is located.



OpenDML AVI File Format Extensions
AVI File Format
ffprobe can supply the frame rate as a rational value

ffprobe in.avi -show_entries stream=r_frame_rate,avg_frame_rate -select_streams v -v 0 -of compact=p=0:nk=1


The first rational value is from the stream header; the 2nd is the computed value which will differ for a variable frame rate stream