[FFmpeg-user] How to get he total number of frames
Mark Filipak (ffmpeg)
markfilipak at bog.us
Tue Mar 9 21:43:21 EET 2021
On 2021-03-09 03:58, Michael Koch wrote:
> Am 09.03.2021 um 09:46 schrieb Ulf Zibis:
>>
>> Am 09.03.21 um 09:26 schrieb Peter White:
>>> On Tue, Mar 09, 2021 at 09:13:14AM +0100, Ulf Zibis wrote:
>>>> Hi,,
>>>>
>>>> can one please tell me, how I can get the total number of frames of a video?
>>> ffmpeg -i input -an -sn -c copy -f null -
>>>
>>> This basically copies all frames into the void but you get the total
>>> count this way in the stats line.
>>
>> Much thanks. This at least gives a ballpark figure. Is there a way to get the exact frame count?
>>
>
> These links might help:
> https://stackoverflow.com/questions/2017843/fetch-frame-count-with-ffmpeg
> https://superuser.com/questions/1512575/why-total-frame-count-is-different-in-ffmpeg-than-ffprobe
>
> Michael
Those links are really hard to follow and it's fruitless to try to find what's there that works vs.
what doesn't work.
From Ulf Zibis:
can one please tell me, how I can get the total number of frames of a video?
Was Ulf's question actually answered? I think not.
I'd like to know the answer.
Here's a cmd script that I have implemented in the Windows 'SentTo' context menu:
@ECHO OFF
ECHO Tip: Use "Save As" to save this list.>"%TEMP%\%~nx1 timestamps.txt"
ECHO.>>"%TEMP%\%~nx1 timestamps.txt"
ffprobe -hide_banner -sexagesimal -select_streams v -i %1 2>>"%TEMP%\%~nx1 timestamps.txt"
ffprobe -hide_banner -sexagesimal -select_streams v -show_frames -of flat -i %1 | FINDSTR /L
"key_frame=1 best_effort_timestamp">>"%TEMP%\%~nx1 timestamps.txt"
"%TEMP%\%~nx1 timestamps.txt"
DEL /Q "%TEMP%\%~nx1 timestamps.txt"
'~nx' strips enclosing quotes (if present) and extracts the file's name & extension (example:
video.mkv).
'%~nx1 timestamps.txt' saves the video.mkv list as 'video.mkv timestamps.txt'.
"%TEMP%\%~nx1 timestamps.txt" opens the list in my editor.
The last line of the list produced by the cmd script shows the frame number of the ending frame --
Add 1 to get the number of frames.
The list also shows this metadata:
"NUMBER_OF_FRAMES-eng: 95286",
but that number is bogus; the mkv actually has only 3596 frames.
Yes, the ffprobe command is slow. That's why I'd like to know a quick check of number of frames if
indeed such a method exists.
More information about the ffmpeg-user
mailing list