2

When I used ffprobe against an animated gif, I get, among other things, this:

> ffprobe.exe  foo.gif
. . . 
Stream #0:0: Video: gif, bgra, 500x372, 6.67 fps, 6.67 tbr, 100 tbn, 100 tbc

Great; this tells me the frame rate is 6.67 frames per second. But I'm going to be using this in a program and want it in a parsed format. ffprobe does json, but when I use it:

> ffprobe.exe -show_streams -of json foo.gif

The json shows:

"r_frame_rate": "20/3",
"avg_frame_rate": "20/3",

But I want the decimal form 6.67 instead of 20/3. Is there a way to have FFProbe produce its JSON output in decimal? I can't seem to find it in the docs.

My platform is Windows; FFProbe is version N-68482-g92a596f.

I did look into using ImageMagick, but the GIF file in question is corrupted (I'm working on a simple repair program); IM's "identify" command halts on it, while FFMpeg & FFProbe handle it just fine.

Addition: this is kind of academic now; I just used (in Python):

framerate_as_decimal = "%4.2f" % (float(fractions.Fraction(framerate_as_fraction)))

But I'm still kind of curious if there's an answer.

codingatty
  • 2,026
  • 1
  • 23
  • 32

2 Answers2

1

I know this is a bit old question but today I have tried to do the same and found two options:

  1. You can use the subprocess module in python and mediainfo: fps = float(subprocess.check_output('mediainfo --Inform="Video;%FrameRate%" input.mp4, shell=True)) here the returned value is a string, that's why I am converting it to float. Unfortunately I wasn't able to execute the same thing without the shell=True but perhaps I am missing something.
  2. Using ffprobe: ffprobe -v error -select_streams v:0 -show_entries stream=avg_frame_rate -of default=noprint_wrappers=1:nokey=1 input.mp4 here the problem is that the output is 50/1 or in your case 20/3 so you need to split the output by "/" and then to convert and divide the two elements of the list. Something like:

fps = subprocess.check_output(['ffprobe', '-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=avg_frame_rate', '-of', 'default=noprint_wrappers=1:nokey=1', 'input.mp4']) fps_lst = fps.split('/') fps_real = float(fps_lst[0]) / int(fps_lst[1])

So the normal commands for getting the frame rate are: ffprobe -v error -select_streams v:0 -show_entries stream=r_frame_rate -of default=noprint_wrappers=1:nokey=1 input.mp4 and mediainfo --Inform="Video;%FrameRate%" input.mp4

Georgi Stoyanov
  • 594
  • 1
  • 9
  • 26
0

In Python, you can just use:

frame_rate_str = "15/3"
frame_rate = eval(frame_rate_str)
  • There is usually a better way to do stuff as opposed to `eval()`. For example, `int('61')` is much faster and secure than `eval('61')` – Eric Jin Jun 07 '20 at 13:03