How to find frames per second of any video file?
This will tell you the framerate if it's not variable framerate:
ffmpeg -i filename
Sample output with filename obscured:
Input #0, matroska,webm, from 'somerandom.mkv': Duration: 01:16:10.90, start: 0.000000, bitrate: N/A Stream #0.0: Video: h264 (High), yuv420p, 720x344 [PAR 1:1 DAR 90:43], 25 fps, 25 tbr, 1k tbn, 50 tbc (default) Stream #0.1: Audio: aac, 48000 Hz, stereo, s16 (default)
ffmpeg -i filename 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p"
Someone edited with one that didn't quite work the way I wanted. It's referenced here
Additional edit...If you want the tbr value this sed line works
sed -n "s/.*, \(.*\) tbr.*/\1/p"
ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate infile
Result:
2997/100
Here is a python function based on Steven Penny's answer using ffprobe that gives exact frame rate
ffprobe 'Upstream Color 2013 1080p x264.mkv' -v 0 -select_streams v -print_format flat -show_entries stream=r_frame_rate
import sys
import os
import subprocess
def get_frame_rate(filename):
if not os.path.exists(filename):
sys.stderr.write("ERROR: filename %r was not found!" % (filename,))
return -1
out = subprocess.check_output(["ffprobe",filename,"-v","0","-select_streams","v","-print_format","flat","-show_entries","stream=r_frame_rate"])
rate = out.split('=')[1].strip()[1:-1].split('/')
if len(rate)==1:
return float(rate[0])
if len(rate)==2:
return float(rate[0])/float(rate[1])
return -1