Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asking ffmpeg to extract frames at the original frame rate [closed]

Tags:

ffmpeg

On the FFmpeg documentation (here, and here) I read that, by default, FFmpeg chooses to extract frames at 25 frames per second (otherwise you can specify a framerate with the -r option)

My problem is that I have a folder with dozens of videos, each of them recorded at different frame rates, so my question is:

Is there a way to ask FFmpeg to extract frames from a video at the "native" frame rate (i.e. the original frame rate at which the video was recorded)?

In case it matters, I am working with MP4 files

like image 636
Amelio Vazquez-Reina Avatar asked Sep 28 '11 14:09

Amelio Vazquez-Reina


1 Answers

To get the original frame rate:

ffmpeg -i file.mp4 2>&1 | grep -o '[0-9]\{1,3\}\sfps'

Example Output:

25 fps

You can futher pipe it to sed ... | sed 's/\sfps//' to keep only the 25, and store it into a variable, so you can use that variable to convert the videos e.g. ffmpeg -r $originalFps.

grep -o will extract the match, instead of the whole line containing the match.

[0-9]\{1,3\} will match one to three digits

\sfps will match a white space followed by 'fps'

like image 53
Eric Fortis Avatar answered Jan 03 '23 13:01

Eric Fortis