I am trying to determine the PSNR between K frames of two image sequences.
I get incorrect answers.
I found using the stats_file=-
option that psnr
is analyzing an extra frame (sometimes beyond the end of the video).
Is there any way to avoid this extraneous frame?
Here is an example:
ffmpeg -f lavfi -i testsrc=duration=10:size=160x120:rate=1 v1.%03d.png
ffmpeg -f lavfi -i testsrc=duration=10:size=160x120:rate=1 v2.%03d.png
cp v1.001.png v2.004.png # make the fourth frame differ
# We want the average PSNR over the first 3 frames; it should be infinity.
ffmpeg -i v1.%03d.png -i v2.%03d.png -frames:v 3 -lavfi "psnr=stats_file=-" -f null -
And its output:
n:1 mse_avg:0.00 mse_r:0.00 mse_g:0.00 mse_b:0.00 psnr_avg:inf psnr_r:inf psnr_g:inf psnr_b:inf
n:2 mse_avg:0.00 mse_r:0.00 mse_g:0.00 mse_b:0.00 psnr_avg:inf psnr_r:inf psnr_g:inf psnr_b:inf
n:3 mse_avg:0.00 mse_r:0.00 mse_g:0.00 mse_b:0.00 psnr_avg:inf psnr_r:inf psnr_g:inf psnr_b:inf
n:4 mse_avg:6936.69 mse_r:6839.88 mse_g:6839.78 mse_b:7130.40 psnr_avg:9.72 psnr_r:9.78 psnr_g:9.78 psnr_b:9.60
frame= 3 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.12 bitrate=N/A speed=41.3x
video:2kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_psnr_0 @ 0x55dfcbe1d280] PSNR r:15.800917 g:15.800984 b:15.620263 average:15.739882 min:9.719282 max:inf
Even though I specified to use just 3 frames, it has included the fourth frame and reported an incorrect result.
It is only thanks to stats_file
that we see the inclusion of the fourth frame.