日本語

How to Inspect Per-Frame Information with FFmpeg’s showinfo Filter

​​FFmpeg​command line,ffprobe,video

When you pass video through FFmpeg's showinfo filter, it prints one line per frame with the frame number, the timestamp, whether the frame is a keyframe, its picture type (I, P, or B), and pixel checksums and mean brightness. You can use it to find where the keyframes are, see how the frame timestamps are ordered, and check how frames change after passing through a filter.

I made a short test video in my test environment and checked the showinfo output line by line.

Note

The test environment is Ubuntu 24.04.5 with FFmpeg 6.1.1 (Ubuntu package 6.1.1-3ubuntu5). The video was a 320×240, 30fps, 4-second (120 frames) H.264 MP4 made with the lavfi testsrc2 source. Keyframes were placed every second (-g 30), and up to two consecutive B-frames were allowed (-bf 2). The audio was AAC carrying a 440Hz sine wave. I did not test interlaced video, codecs other than H.264, or other FFmpeg versions.

Basic usage and how to read one line

showinfo passes frames through unchanged and only writes information to the log. Since no output file is needed, I discarded the result with -f null - (null description). I used -an to drop audio and -nostats to turn off the progress display (according to the -stats description, progress is shown by default).

To look at only the first three frames, I put trim before showinfo. end_frame=3 discards everything from frame number 3 onward.

bash
ffmpeg -nostats -i sample.mp4 -vf "trim=end_frame=3,showinfo" -an -f null -

Here is the output for the first frame. (@ 0x… is a memory address that changes on each run, so I left it out. I also cut the long hexadecimal User Data= value partway through.)

text
[Parsed_showinfo_1 @ 0x…] config in time_base: 1/15360, frame_rate: 30/1
[Parsed_showinfo_1 @ 0x…] config out time_base: 0/0, frame_rate: 0/0
[Parsed_showinfo_1 @ 0x…] n:   0 pts:      0 pts_time:0       duration:    512 duration_time:0.0333333 fmt:yuv420p cl:left sar:1/1 s:320x240 i:P iskey:1 type:I checksum:5E0816CE plane_checksum:[63CA1CF8 3B66E708 20A612BF] mean:[122 129 127] stdev:[56.8 77.9 81.6]
[Parsed_showinfo_1 @ 0x…]   side data - H.26[45] User Data Unregistered SEI message: UUID=dc45e9bd-e6d9-48b7-962c-d820d923eeef
[Parsed_showinfo_1 @ 0x…] User Data=78323634202d20636f7265203136342072333130…(以下略)
[Parsed_showinfo_1 @ 0x…] 
[Parsed_showinfo_1 @ 0x…] color_range:unknown color_space:unknown color_primaries:unknown color_trc:unknown

The second frame was n: 1 pts: 512 pts_time:0.0333333 … iskey:0 type:B checksum:2AE929D7 ….

A line that starts with n: holds the information for one frame. The table below lists the fields with their meanings from the official documentation, along with the values for the first frame.

Field Meaning (from the official documentation) Value for the first frame
n Sequential frame number, starting from 0 0
pts Presentation time, in units of the time base 0
pts_time Presentation time, in seconds 0
fmt Pixel format yuv420p
sar Sample aspect ratio 1/1
s Frame size 320×240
i Interlacing type (P means progressive) P
iskey 1 if the frame is a keyframe 1
type Picture type (I, P, B, or ? if unknown) I
checksum Adler-32 checksum of all planes 5E0816CE
plane_checksum Adler-32 checksum for each plane three values for Y, U, and V
mean Mean pixel value for each plane 122 for Y
stdev Standard deviation of pixel values for each plane 56.8 for Y

The unit of pts is shown in the first line, config in time_base: 1/15360. The pts: 512 on the second frame is 512 ÷ 15360 = 0.0333… seconds, which matches pts_time:0.0333333. duration and duration_time are also printed, though they are not in the official list. duration_time was 0.0333333 seconds, the length of one frame at 30fps.

The side data line shows extra information attached to the frame. In this video, it contained SEI (supplemental enhancement information) written by x264. When I converted the hexadecimal data to text with Python's bytes.fromhex(), it began with x264 - core 164 r3108 31e19f9 - H.264/MPEG-4 AVC codec - …, which is the encoder name and settings string.

With -frames:v, the output does not stop

You may want to look at only the first few frames by using -frames:v 3. However, with the following command, showinfo printed nine lines instead of three. I ran it three times, and each time it printed nine.

bash
ffmpeg -nostats -i sample.mp4 -vf showinfo -frames:v 3 -an -f null -

The -frames description says "stop writing to the stream after framecount frames," so it stops the writing side, not the filter chain. To get exactly the number of showinfo lines you want, put trim=end_frame=3 inside the filter chain as shown above. That produced three lines.

The showinfo lines are printed at the info log level. With -loglevel warning, none were printed (-loglevel description says info is the default). If you lower -loglevel to reduce other messages, the showinfo lines disappear too.

Save every frame to a CSV to see keyframes and the I/P/B order

Because showinfo lines are log output, they go to standard error (-loglevel description states that logs go to stderr by default). I redirected them to a file with 2> and used Python to pull out only the fields I needed and write them to a CSV.

bash
ffmpeg -nostats -i sample.mp4 -vf showinfo -an -f null - 2> showinfo.txt
python3 parse.py showinfo.txt > frames.csv
python
# Convert n, pts_time, iskey, type, checksum, and mean (Y) for each frame from showinfo output to CSV
import re, sys
pat = re.compile(r"\] n:\s*(\d+) .*?pts_time:(\S+) .*?iskey:(\d) type:(\S) (?:checksum:(\w+) .*?mean:\[(\d+))?")
print("n,pts_time,iskey,type,checksum,mean_y")
for line in open(sys.argv[1]):
    m = pat.search(line)
    if m: print(",".join(g or "" for g in m.groups()))

The resulting CSV had one header line and 120 rows, one per frame. Filtering for rows where iskey is 1 shows where the keyframes are.

text
n,pts_time,iskey,type,checksum,mean_y
0,0,1,I,5E0816CE,122
30,1,1,I,EA74D494,123
60,2,1,I,FA3AE399,123
90,3,1,I,CA97EDCC,123

As specified with -g 30, keyframes were at exactly 0, 1, 2, and 3 seconds. Counting the type values gave 4 I-frames, 46 P-frames, and 70 B-frames. The sequence started IBBPBBPBPBBP…. I also checked the order with ffprobe, using -show_entries frame=pict_type, and it matched for all 120 frames.

Point

iskey and type are different pieces of information. In the fade-in video used in the next section, frame 1 was iskey:0 type:I. Some I-frames are not treated as keyframes. To find keyframe positions, check iskey.

Use mean to track brightness changes and checksum to check for identical images

mean and checksum are values calculated from the frame contents. I used a video that fades in from black and then stops moving after 2 seconds (made with fade and tpad=stop_mode=clone, then encoded with H.264) to observe the changes.

The horizontal axis shows pts_time from 0 to 4 seconds, and the vertical axis shows the mean of Y. The value rises steadily from 16 at 0 seconds to 123 at 1 second, then stays nearly flat at 122 to 123. A pink dashed line is at 2.00 seconds, and the section after it, where the video is frozen, is shaded in light blue
Graph of showinfo mean (Y) for each frame

The first mean value (Y, brightness) went up by about 3 to 4 per frame, from 16 at 0 seconds to 123 at 1 second. The 60 frames after the video froze at 2 seconds were all 123.

On the other hand, the checksum values for those 60 frozen frames were not all the same. There were five different values. Equal values appeared in a row only in short runs of 2 or 3 frames. I also ran showinfo on the filter output before encoding, for the same section, and there was only one checksum. The source frames were copies of the same image, but after H.264 encoding and decoding, the 60 frames split into five different images. In this video, searching for runs of identical checksums did not find the whole frozen section.

The checksum is useful for checking whether pixels are exactly identical. I created two files: one by copying sample.mp4 into MKV with -c copy, and one re-encoded with -c:v libx264 -crf 23. I compared the per-frame checksums with the original.

File Frames whose checksum differs from the original
MKV made with -c copy 0 / 120
Re-encoded with libx264 120 / 120

With -c copy, the decoded images are the same as the original, so all 120 checksums matched. The re-encoded file had a different value in every frame.

Place showinfo before and after a filter to compare changes

You can place showinfo in as many places in the chain as you like. I put it before and after fps=10 (fps filter) to see how the 30fps frames were thinned out. For the second showinfo, I set checksum=0 to turn off checksum calculation.

bash
ffmpeg -nostats -i sample.mp4 -vf "trim=end_frame=7,showinfo,fps=10,showinfo=checksum=0" -an -f null -

The name at the start of each line tells you which showinfo printed it. Parsed_showinfo_1 is before fps, and Parsed_showinfo_3 is after it. (I extracted only the n and time fields.)

text
[Parsed_showinfo_1 @ 0x…] config in time_base: 1/15360, frame_rate: 30/1
[Parsed_showinfo_3 @ 0x…] config in time_base: 1/10, frame_rate: 10/1
[Parsed_showinfo_1 @ 0x…] n:   0 pts:      0 pts_time:0
[Parsed_showinfo_1 @ 0x…] n:   1 pts:    512 pts_time:0.0333333
[Parsed_showinfo_1 @ 0x…] n:   2 pts:   1024 pts_time:0.0666667
[Parsed_showinfo_3 @ 0x…] n:   0 pts:      0 pts_time:0
[Parsed_showinfo_1 @ 0x…] n:   3 pts:   1536 pts_time:0.1
[Parsed_showinfo_1 @ 0x…] n:   4 pts:   2048 pts_time:0.133333
[Parsed_showinfo_1 @ 0x…] n:   5 pts:   2560 pts_time:0.166667
[Parsed_showinfo_3 @ 0x…] n:   1 pts:      1 pts_time:0.1
[Parsed_showinfo_1 @ 0x…] n:   6 pts:   3072 pts_time:0.2

After fps, the time base changed to 1/10, and pts went up by 1 each time, starting from 0 and 1. n also restarts from 0. n is the order in which frames passed through that particular showinfo, not the frame's position in the original video.

With checksum=0, the checksum, plane_checksum, mean, and stdev fields after type:I disappeared entirely. If you only need timestamps and frame types, this makes the lines shorter.

The latest official documentation also lists a udu_sei_as_ascii option, which displays the contents of SEI as text. In FFmpeg 6.1.1 it returned an Option not found error, so I could not use it. (The options shown by ffmpeg -h filter=showinfo included only checksum.)

Check audio with ashowinfo

For audio frames, use ashowinfo. I limited the output to the first 2048 samples with atrim=end_sample=2048.

bash
ffmpeg -nostats -i sample.mp4 -af "atrim=end_sample=2048,ashowinfo" -vn -f null -
text
[Parsed_ashowinfo_1 @ 0x…] n:0 pts:0 pts_time:0 fmt:fltp channels:1 chlayout:mono rate:48000 nb_samples:1024 checksum:95A157E3 plane_checksums: [ 95A157E3 ]
[Parsed_ashowinfo_1 @ 0x…] n:1 pts:1024 pts_time:0.0213333 fmt:fltp channels:1 chlayout:mono rate:48000 nb_samples:1024 checksum:BAB691FA plane_checksums: [ BAB691FA ]

In this AAC audio, each frame contained 1024 samples. At 48000Hz, one frame lasts 1024 ÷ 48000 = 0.0213… seconds, which matches the second line's pts_time:0.0213333.

​Posted by 86