1

This question and answer cover how to get the framecount and keyframe count from an AVI file, which is very useful. I've got a raw AVI file and want to count the number of keyframes (equivalent to non-dropped frames for raw AVI), but it takes a long time to process through a raw AVI file.

There is some way to get this information without fully processing the file, as VirtualDub provides both framecount and key framecount in the file information, as well as total keyframe size, almost instantly for a 25-second raw 1920x1080 AVI. But ffprobe requires count_frames to populate nb_read_frames, which takes some good processing time.

I can do some math with the file's size and the frame's width/height/format to get a fairly good estimate of the number of frames, but I'm worried the overhead of the container could be enough to throw the math off for very short clips. (For my 25 second clip, I get 1286.12 frames, when there are really 1286.)

Any thoughts on if there is a way to get this information programatically with ffprobe or ffmpeg without processing the whole file? Or with another API on windows?

aggieNick02
  • 2,557
  • 2
  • 23
  • 36
  • I should mention I'd also be interested if there's a nice way to grab the keyframe count while encoding the video to another format using ffmpeg. I do that as well, it's just frustrating to have to process the video an extra time to get the keyframe count. – aggieNick02 Jul 26 '18 at 21:09
  • How long does ffprobe take? – rogerdpack Jul 26 '18 at 21:11
  • It depends a lot on the disk your file is on. For a 1080p raw video, about half the duration of the video on a nice SATA SSD (850EVO), and 1/5th the duration on a high-end PCIe SSD. – aggieNick02 Jul 26 '18 at 21:20
  • Does virtualdub do some "pre processing" when you first open a file I wonder? – rogerdpack Jul 27 '18 at 00:15
  • When you mentioned 1286 frames for a 25-s clip, that sounds like you want total frame count. KF count will be less unless you're working with intra-coded streams. What video codecs are you working with? – Gyan Jul 27 '18 at 05:20
  • @rogerdpack It may do some processing, but it opens near-instantaneous even on very large raw videos, so it is nothing like what ffprobe. – aggieNick02 Jul 27 '18 at 18:14
  • @Gyan I'm dealing with a raw AVI file - video stream format rgb24. I can quickly get the nb_frames from ffprobe, which is the number of frames including dropped frames. With a raw video stream, every non-dropped/skipped frame is a keyframe, and that is what I'm after. – aggieNick02 Jul 27 '18 at 18:16
  • For AVIs, no of frames is stream duration x framerate. – Gyan Jul 27 '18 at 18:36
  • @Gyan, right, but I am trying to get the number of non-dropped frames. Some frames in the AVI may be "dropped" frames where no actual frame data is present. Somehow Virtualdub can provide this info instantly, but ffprobe appears to require processing the whole file. – aggieNick02 Jul 27 '18 at 18:43
  • Share the log of `ffmpeg -i in.avi` – Gyan Jul 27 '18 at 19:08
  • @Gyan - I'm guessing you mean to show ffmpeg -i for processing to another format. It is pretty verbose, but I've scanned the output - it lists the number of frames, but not the number of non-dropped/keyframes, so it doesn't help. – aggieNick02 Aug 01 '18 at 19:38
  • Maybe VirtualDub has some "parse through and don't even read the frames to decode them" optimization. Might be worth a feature request to FFmpeg. Cheers! – rogerdpack Aug 02 '18 at 21:59
  • possibly ask on superuser/av.stackexchange – rogerdpack Aug 08 '18 at 16:57

0 Answers0