Reputation: 683
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.
Upvotes: 36
Views: 38202
Reputation: 61
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)
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
Upvotes: 5
Reputation: 547
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
Upvotes: 2
Reputation: 357
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"
Upvotes: 5
Reputation: 812
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
Upvotes: 60
Reputation: 683
I found calculate fps in another method that is..
String query = "ffmpeg -i foo.avi 2>&1 | sed -n 's/.*, \\(.*\\) fp.*/\\1/p' > fps.txt";
String[] command = {"gnome-terminal", "-x", "/bin/sh", "-c", query};
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
Thread.sleep(2000);
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("fps.txt")));
output = br.readLine();
} catch (IOException ioe) {
ioe.printStackTrace();
}
Anyway thanks friends.
Upvotes: 0