Dictionary

What Does NB Frames Mean?

NB Frames tells you how many frames a video or audio stream holds. FFmpeg does not report this number for every format, so the value can be unknown.

nb-frames

NB Frames means the number of frames in one stream of a video or audio file. The letters NB stand for "number". FFmpeg and its ffprobe program call this field nb_frames.

A file can hold several streams, and each stream has its own NB Frames value. A file with one video stream and one audio stream therefore has 2 separate counts. NB Streams is a different value: it counts the streams in the file, not the frames inside one stream.

What a frame is

In a video stream, a frame is one still image of the video. In an audio stream, the meaning depends on the format.

In AIFF, a sample frame holds one sample for each audio channel. In MP3, a frame is a larger block, and FFmpeg multiplies the frame count by the samples per frame to get the length. So you cannot directly compare an audio count from one format with a count from another format.

What the values look like

The value is a whole number when it is known. These values appear in FFmpeg's code, documentation, and test results:

  • 708: the count for a video stream in one of FFmpeg's test files.
  • 1: the count for a single still image in a HEIC file.
  • 0: the value that FFmpeg's programming interface uses when the number is not known.
  • N/A: the text that ffprobe's default output prints when the value is 0. Its JSON and XML output leave the field out.

A value of 0 or N/A, or a missing field, does not tell you that the stream is empty. The value only tells you that FFmpeg set no count in this field.

Where the value comes from

NB Frames normally comes from the file's own structure, so FFmpeg does not have to count the frames. The source depends on the format:

  • MP4 and MOV: FFmpeg adds up the sample counts in the time-to-sample table, which is the stts atom.
  • AVI: FFmpeg reads a 32-bit number from the stream header, which is the strh chunk.
  • AIFF: FFmpeg reads the numSampleFrames field from the Common Chunk.
  • WAV, MP3, FLAC, and MKV: FFmpeg's readers for these formats do not set the value, so ffprobe's default output prints N/A.

An MKV file can still hold a count under another name. The mkvmerge program writes a tag named NUMBER_OF_FRAMES for each track.

How to count the frames

NB Frames only repeats the number in the file structure. That number does not prove that all the frames are really in the file. One MOV test file in FFmpeg stores a count of 708, but ffprobe reads only 66 packets and 65 frames from that file.

To measure the count, run ffprobe with the -show_streams and -count_frames options. The ffprobe program then decodes the stream and reports the result in a separate field, nb_read_frames. This takes more time, because ffprobe must decode every frame.

Use this check for video streams. In an AIFF file, ffprobe counts decoded blocks that each hold many sample frames, so the two numbers differ even in a complete file.

The -count_packets option, also used with -show_streams, counts packets without decoding them and reports the result in nb_read_packets. A video packet typically holds one compressed frame, but an audio packet may hold several.

Why it matters

For a video stream, the frame count and the duration together give the average frame rate. FFmpeg's MP4 and MOV reader calculates the rate from a frame count and a duration. In the same test file, 708 frames over 23.613333 seconds gives about 29.98 frames per second.

The count also helps you check a video file. If a measured count is far below the stored count, part of the video data may be missing.