Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get video fps using FFProbe

I am new in ffprobe my aim is get video fps and store into java program. my code store xml files but i want store directly like int fps=30;

ffprobe -v quiet -print_format xml -show_format -show_streams "/video/small/small.avi" > "/video/small/test.xml"

this is my code.

like image 947
RDY Avatar asked Jan 06 '15 06:01

RDY


People also ask

How can I get fps from a video?

To find out video resolution and frame rate of a video file, you can simply view its properties in modern Windows or any other OS. In Windows 7, the information is found out from the Properties > Details (tab) of a video. Video information like frame width and frame height is present there.

Is Ffprobe part of FFmpeg?

The FFmpeg library, ffprobe, can rightly be called the Swiss Army Knife of video information extraction or video inspection. As the FFmpeg documentation succinctly puts it, ffprobe gathers information from multimedia streams and prints it in human- and machine-readable fashion.


3 Answers

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
like image 123
o_ren Avatar answered Oct 16 '22 09:10

o_ren


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"
like image 30
geo-freak Avatar answered Oct 16 '22 10:10

geo-freak


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
like image 1
Ankur Bhatia Avatar answered Oct 16 '22 09:10

Ankur Bhatia