get video fps using FFProbe
You can simply run this also, to get the video FPS, this will work on linux machines.
ffprobe -v quiet -show_streams -select_streams v:0 INPUT |grep "r_frame_rate"
This will print the video FPS:
ffprobe -v error -select_streams v -of default=noprint_wrappers=1:nokey=1 -show_entries stream=r_frame_rate file.mp4
Get the video FPS and print it to stdout: Saw the answer by @geo-freak and added it to get only the frame rate (remove the extra text).
ffprobe -v quiet -show_streams -select_streams v:0 input.mp4 |grep "r_frame_rate" | sed -e 's/r_frame_rate=//'
The answer by @o_ren seems more reasonable.
Python Function to do the same:
def get_video_frame_rate(filename):
result = subprocess.run(
[
"ffprobe",
"-v",
"error",
"-select_streams",
"v",
"-of",
"default=noprint_wrappers=1:nokey=1",
"-show_entries",
"stream=r_frame_rate",
filename,
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
result_string = result.stdout.decode('utf-8').split()[0].split('/')
fps = float(result_string[0])/float(result_string[1])
return fps
The accepted answer suggests using stream=r_frame_rate
. This is okay if you only need a slightly rounded result. (30/1 instead of ~29.7)
For a Precise & Unrounded FPS, Divide Total Frames by Duration:
ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -print_format csv="p=0" input.mp4 | read frames &&
ffprobe -i input.mp4 -show_entries format=duration -v quiet -of csv="p=0" | read duration &&
echo $(($frames/$duration))
>> 29.970094916135743
Duration of file:
ffprobe -i input.mp4 -show_entries format=duration -v quiet -of csv="p=0"
>> 15.367000
Total frame count of file:
ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -print_format csv input.mp4
>> 461