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.
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.
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.
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
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"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With