How to get he total number of frames

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
41 messages Options
123
Reply | Threaded
Open this post in threaded view
|

How to get he total number of frames

Ulf Zibis-2
Hi,,

can one please tell me, how I can get the total number of frames of a video?

-Ulf

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

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.


Peter
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Ulf Zibis-2

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?

-Ulf

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Peter White
On Tue, Mar 09, 2021 at 09:46:43AM +0100, Ulf Zibis wrote:

>
> 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?

The frame count *is* exact. The way to get there is just not that
pretty. If anybody on this list knows a better one, step up, please.


Peter
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Michael Koch
In reply to this post by Ulf Zibis-2
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

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Nicolas George
In reply to this post by Peter White
Peter White (12021-03-09):
> If anybody on this list knows a better one, step up, please.

ffprobe, of course.

Regards,

--
  Nicolas George

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Ulf Zibis-2
In reply to this post by Peter White

Am 09.03.21 um 09:57 schrieb Peter White:

> On Tue, Mar 09, 2021 at 09:46:43AM +0100, Ulf Zibis wrote:
>> 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?
> The frame count *is* exact. The way to get there is just not that
> pretty. If anybody on this list knows a better one, step up, please.

I suspect that the last "progression" line shows the exact count, as it may only show the last reprted progression state before the operation is completed.

-Ulf

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Ulf Zibis-2

Am 09.03.21 um 10:43 schrieb Ulf Zibis:
>
> Am 09.03.21 um 09:57 schrieb Peter White:
>> The frame count *is* exact. The way to get there is just not that
>> pretty. If anybody on this list knows a better one, step up, please.
>
> I suspect that the last "progression" line shows the exact count, as it may only report the last progression state a few µs before the operation is completed.

Can one please clarify this?

-Ulf

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Jim Hollingsworth
In reply to this post by Nicolas George
Unsubscribe!!!!!!!







On Mar 9, 2021, at 4:41 AM, Nicolas George <[hidden email]> wrote:

Peter White (12021-03-09):
> If anybody on this list knows a better one, step up, please.

ffprobe, of course.

Regards,

--
 Nicolas George
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Rob Hallam-2
On Tue, 9 Mar 2021 at 10:26, Jim Hollingsworth <[hidden email]> wrote:
> Unsubscribe!!!!!!!

Before the inevitable flames: to unsubscribe, please read the
footer of the email you replied to and follow the instructions there.

For convenience:

> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".

Cheers,
Rob
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Peter White
In reply to this post by Ulf Zibis-2
On Tue, Mar 09, 2021 at 11:07:21AM +0100, Ulf Zibis wrote:

>
> Am 09.03.21 um 10:43 schrieb Ulf Zibis:
> >
> > Am 09.03.21 um 09:57 schrieb Peter White:
> > > The frame count *is* exact. The way to get there is just not that
> > > pretty. If anybody on this list knows a better one, step up, please.
> >
> > I suspect that the last "progression" line shows the exact count, as it may only report the last progression state a few µs before the operation is completed.
>
> Can one please clarify this?

I don't know if I understood your request correctly but here goes:

ffmpeg -i example.mkv -an -sn -c copy -f null -
...
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=31186 fps=0.0 q=-1.0 Lsize=N/A time=00:21:40.59 bitrate=N/A speed=2.67e+03x
video:162174kB audio:0kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: unknown

As you can see, in the second to last line in the first field is the
frame count. Since the copy codec gets used, I can see no reason why
this should not always show the exact total frame count of any video.

Also, note that I used a matroska file as an example, since it is one of
the mentioned special cases mentioned here:
https://stackoverflow.com/a/28376817

I had the same question you posted once and think I saw that one or a
similar answer. After some ado I came to the conclusion that the
aforementioned way is the most robust and universal one. But if I am
wrong, I would very much like to be corrected.


Peter
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Moritz Barsnick
In reply to this post by Ulf Zibis-2
On Tue, Mar 09, 2021 at 11:07:21 +0100, Ulf Zibis wrote:
> Am 09.03.21 um 10:43 schrieb Ulf Zibis:
> > I suspect that the last "progression" line shows the exact count,
> > as it may only report the last progression state a few µs before
> > the operation is completed.
>
> Can one please clarify this?

The progess line is printed periodically, and additionally after the
end of processing. Therefore the last visible line does not omit any
stats.

Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Peter White
In reply to this post by Nicolas George
On Tue, Mar 09, 2021 at 10:41:41AM +0100, Nicolas George wrote:
> Peter White (12021-03-09):
> > If anybody on this list knows a better one, step up, please.
>
> ffprobe, of course.

Unless it happens to be one of those special cases that don't have that
info in their metadata, like matroska:
https://stackoverflow.com/a/28376817

Other than being a little ugly, my way seems to yield the correct result
with any video. I like universal solutions, so I stuck with it, and
recommended it.


Peter
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Nicolas George
Peter White (12021-03-09):
> Unless it happens to be one of those special cases that don't have that
> info in their metadata, like matroska:

Did I suggest to limit to the output of -show_format or -show_streams?
If you want information about frames, guess what you should use?

> Other than being a little ugly, my way seems to yield the correct result
> with any video. I like universal solutions, so I stuck with it, and
> recommended it.

FFprobe yields the correct result, and in a cleaner way. Just use it
properly.

Regards,

--
  Nicolas George

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

FFmpeg-users mailing list
In reply to this post by Peter White
 I hit this once some time ago when creating an application which was intended to assign start timecodes to recorded video files and for which we needed a frame-accurate count. In that case the files were AVIs, which theoretically may have a header including a frame count, but in practice we found that this was often either missing, not set, or inaccurate in files we found in the wild, and there are further issues specifically with AVI over a certain length. Other file types have similar problems.
My conclusion was that the only reliable way to get a frame count is to have something like ffmpeg go over the file frame by frame. With the command lines suggested here (which are, if I remember correctly, close to what I used) then it tends to be reasonably fast and, as I say, I'm not sure there's much other option if you need a reasonable amount of reliability on arbitrary files.
If you're in a situation where all your files come from a known source and you are confident they will always have frame count headers that will always be accurate, great, but otherwise I'd recommend doing roughly what's been suggested here.
P
    On Tuesday, 9 March 2021, 10:54:09 GMT, Peter White <[hidden email]> wrote:  
Unless it happens to be one of those special cases that don't have that
info in their metadata, like matroska:


 
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Peter White
In reply to this post by Nicolas George
On Tue, Mar 09, 2021 at 12:13:53PM +0100, Nicolas George wrote:
> Peter White (12021-03-09):
> > Unless it happens to be one of those special cases that don't have that
> > info in their metadata, like matroska:
>
> Did I suggest to limit to the output of -show_format or -show_streams?

Sorry, I didn't mean to offend.

> > Other than being a little ugly, my way seems to yield the correct result
> > with any video. I like universal solutions, so I stuck with it, and
> > recommended it.
>
> FFprobe yields the correct result, and in a cleaner way. Just use it
> properly.

Is there a proper universal way to do this with ffprobe that does not
take ages to complete? Honest question.

Plus, the ffmpeg command is relatively easy, if one uses ffmpeg on a
regular basis. OTOH I seldomly use ffprobe, as do many of the other
users, I suspect, so ffmpeg comes more natural.


Peter
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Nicolas George
Peter White (12021-03-09):
> Sorry, I didn't mean to offend.

I was not offended, I was amused.

> Is there a proper universal way to do this with ffprobe that does not
> take ages to complete? Honest question.

Of course. As I already said, FFprobe can do the same thing as FFmpeg,
but its output is meant for parsing. Your solution will break as soon as
we change a tiny detail in the statistics line.

Show us your complete command line and console output if you have
trouble.

Regards,

--
  Nicolas George

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Peter White
On Tue, Mar 09, 2021 at 12:39:09PM +0100, Nicolas George wrote:

> Peter White (12021-03-09):
> > Sorry, I didn't mean to offend.
>
> I was not offended, I was amused.
>
> > Is there a proper universal way to do this with ffprobe that does not
> > take ages to complete? Honest question.
>
> Of course. As I already said, FFprobe can do the same thing as FFmpeg,
> but its output is meant for parsing.

Would you mind answering the OP's question with a command line example,
then?

> Your solution will break as soon as we change a tiny detail in the
> statistics line.

I am well aware of that, but nobody said anything about parsing. But if
there is an equivalent to my suggestion with ffprobe I would gladly use
that and henceforth recommend it.

> Show us your complete command line and console output if you have
> trouble.

ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 input.mkv

No need for output because it takes to long to complete: roughly one
minute for a 20 minute video as opposed to virtually no time with:

ffmpeg -i input.mkv -an -sn -c copy -f null -


Peter
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Nicolas George
Peter White (12021-03-09):
> Would you mind answering the OP's question with a command line example,
> then?

I help people who help themselves, thus avoiding Russel's paradox.

> I am well aware of that, but nobody said anything about parsing.

Oh? Please, explain to me how you extract the number of frames from the
statistics line without parsing it?

> ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 input.mkv

Do not use "-v error" if you want help.

>
> No need for output because it takes to long to complete: roughly one
> minute for a 20 minute video as opposed to virtually no time with:
>
> ffmpeg -i input.mkv -an -sn -c copy -f null -

-c copy tells ffmpeg to dispense with the decoder, which means it does
not count frames but packets. Have you tried telling ffprobe to count
packets?

Regards,

--
  Nicolas George

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to get he total number of frames

Jim Hollingsworth
In reply to this post by FFmpeg-users mailing list
UNSUBSCRIBE !!!!!

Best regards,

Jim Hollingsworth

On Mar 9, 2021, at 6:16 AM, Phil Rhodes via ffmpeg-user <[hidden email]> wrote:

 I hit this once some time ago when creating an application which was intended to assign start timecodes to recorded video files and for which we needed a frame-accurate count. In that case the files were AVIs, which theoretically may have a header including a frame count, but in practice we found that this was often either missing, not set, or inaccurate in files we found in the wild, and there are further issues specifically with AVI over a certain length. Other file types have similar problems.
My conclusion was that the only reliable way to get a frame count is to have something like ffmpeg go over the file frame by frame. With the command lines suggested here (which are, if I remember correctly, close to what I used) then it tends to be reasonably fast and, as I say, I'm not sure there's much other option if you need a reasonable amount of reliability on arbitrary files.
If you're in a situation where all your files come from a known source and you are confident they will always have frame count headers that will always be accurate, great, but otherwise I'd recommend doing roughly what's been suggested here.
P
   On Tuesday, 9 March 2021, 10:54:09 GMT, Peter White <[hidden email]> wrote:  
Unless it happens to be one of those special cases that don't have that
info in their metadata, like matroska:



_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
123