Opened 16 months ago

Closed 16 months ago

Last modified 16 months ago

#6355 closed defect (invalid)

Unexpected values for psnr_avg

Reported by: aitkenap Owned by:
Priority: normal Component: avfilter
Version: 3.0.7 Keywords: psnr
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
I am getting unexpected results when calculating PSNR averaged over y/u/v channels.

Here is an example command and output:

%$ ffmpeg -i file1.mp4 -i file2.mp4  -lavfi  [0][1]psnr=- -f null -
ffmpeg version 3.0 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (GCC) 20150212 (Red Hat 4.9.2-6)
  configuration: --prefix=/home/magicpony/conda/envs/devenv --pkg-config-flags=--static --extra-cflags=-I/home/magicpony/conda/envs/devenv/include --extra-ldflags=-L/home/magicpony/conda/envs/devenv/lib --bindir=/home/magicpony/conda/envs/devenv/bin --enable-shared --enable-gpl --enable-libx264 --enable-nonfree --disable-outdev=sdl
  libavutil      55. 17.103 / 55. 17.103
  libavcodec     57. 24.102 / 57. 24.102
  libavformat    57. 25.100 / 57. 25.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 31.100 /  6. 31.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
  Duration: 00:00:01.08, start: 0.000000, bitrate: 58 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 72x40, 47 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'file2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
  Duration: 00:00:01.08, start: 0.000000, bitrate: 29 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 72x40, 18 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
    Stream #0:0: Video: wrapped_avframe, yuv420p, 72x40, q=2-31, 200 kb/s, 60 fps, 60 tbn, 60 tbc (default)
    Metadata:
      encoder         : Lavc57.24.102 wrapped_avframe
Stream mapping:
  Stream #0:0 (h264) -> psnr:main
  Stream #1:0 (h264) -> psnr:reference
  psnr -> Stream #0:0 (wrapped_avframe)
Press [q] to stop, [?] for help
n:1 mse_avg:38.32 mse_y:48.93 mse_u:17.59 mse_v:16.61 psnr_avg:32.26 psnr_y:31.24 psnr_u:35.68 psnr_v:35.93
n:2 mse_avg:38.96 mse_y:49.93 mse_u:17.37 mse_v:16.69 psnr_avg:32.19 psnr_y:31.15 psnr_u:35.73 psnr_v:35.91
n:3 mse_avg:39.60 mse_y:50.70 mse_u:18.25 mse_v:16.57 psnr_avg:32.12 psnr_y:31.08 psnr_u:35.52 psnr_v:35.94
n:4 mse_avg:42.54 mse_y:54.43 mse_u:21.36 mse_v:16.20 psnr_avg:31.81 psnr_y:30.77 psnr_u:34.83 psnr_v:36.04
n:5 mse_avg:42.39 mse_y:53.49 mse_u:23.95 mse_v:16.43 psnr_avg:31.82 psnr_y:30.85 psnr_u:34.34 psnr_v:35.97
n:6 mse_avg:41.52 mse_y:52.04 mse_u:23.47 mse_v:17.51 psnr_avg:31.91 psnr_y:30.97 psnr_u:34.43 psnr_v:35.70
n:7 mse_avg:41.34 mse_y:51.78 mse_u:23.24 mse_v:17.68 psnr_avg:31.93 psnr_y:30.99 psnr_u:34.47 psnr_v:35.66
n:8 mse_avg:41.47 mse_y:51.05 mse_u:22.21 mse_v:22.44 psnr_avg:31.92 psnr_y:31.05 psnr_u:34.67 psnr_v:34.62
n:9 mse_avg:41.57 mse_y:52.33 mse_u:20.64 mse_v:19.44 psnr_avg:31.91 psnr_y:30.94 psnr_u:34.98 psnr_v:35.24
n:10 mse_avg:41.85 mse_y:52.68 mse_u:20.77 mse_v:19.57 psnr_avg:31.88 psnr_y:30.91 psnr_u:34.96 psnr_v:35.22
n:11 mse_avg:46.06 mse_y:57.39 mse_u:22.14 mse_v:24.69 psnr_avg:31.46 psnr_y:30.54 psnr_u:34.68 psnr_v:34.21
n:12 mse_avg:46.54 mse_y:58.07 mse_u:21.37 mse_v:25.60 psnr_avg:31.42 psnr_y:30.49 psnr_u:34.83 psnr_v:34.05
n:13 mse_avg:45.89 mse_y:57.19 mse_u:20.76 mse_v:25.83 psnr_avg:31.48 psnr_y:30.56 psnr_u:34.96 psnr_v:34.01
n:14 mse_avg:46.45 mse_y:58.36 mse_u:20.89 mse_v:24.35 psnr_avg:31.43 psnr_y:30.47 psnr_u:34.93 psnr_v:34.27
n:15 mse_avg:48.32 mse_y:61.12 mse_u:21.01 mse_v:24.44 psnr_avg:31.26 psnr_y:30.27 psnr_u:34.91 psnr_v:34.25
n:16 mse_avg:56.38 mse_y:72.63 mse_u:22.19 mse_v:25.56 psnr_avg:30.59 psnr_y:29.52 psnr_u:34.67 psnr_v:34.06
n:17 mse_avg:49.70 mse_y:62.66 mse_u:22.74 mse_v:24.85 psnr_avg:31.13 psnr_y:30.16 psnr_u:34.56 psnr_v:34.18
n:18 mse_avg:50.21 mse_y:63.30 mse_u:23.00 mse_v:25.05 psnr_avg:31.09 psnr_y:30.12 psnr_u:34.51 psnr_v:34.14
n:19 mse_avg:49.64 mse_y:62.56 mse_u:22.62 mse_v:24.98 psnr_avg:31.14 psnr_y:30.17 psnr_u:34.59 psnr_v:34.15
n:20 mse_avg:63.29 mse_y:84.05 mse_u:18.86 mse_v:24.66 psnr_avg:30.08 psnr_y:28.89 psnr_u:35.38 psnr_v:34.21
n:21 mse_avg:64.54 mse_y:86.10 mse_u:18.43 mse_v:24.42 psnr_avg:30.00 psnr_y:28.78 psnr_u:35.48 psnr_v:34.25
n:22 mse_avg:51.93 mse_y:67.39 mse_u:18.00 mse_v:24.04 psnr_avg:30.94 psnr_y:29.84 psnr_u:35.58 psnr_v:34.32
n:23 mse_avg:49.89 mse_y:64.10 mse_u:18.12 mse_v:24.86 psnr_avg:31.12 psnr_y:30.06 psnr_u:35.55 psnr_v:34.18
n:24 mse_avg:50.07 mse_y:64.33 mse_u:18.06 mse_v:25.02 psnr_avg:31.10 psnr_y:30.05 psnr_u:35.56 psnr_v:34.15
n:25 mse_avg:46.23 mse_y:57.80 mse_u:20.46 mse_v:25.74 psnr_avg:31.45 psnr_y:30.51 psnr_u:35.02 psnr_v:34.02
n:26 mse_avg:46.36 mse_y:57.88 mse_u:20.58 mse_v:26.06 psnr_avg:31.44 psnr_y:30.51 psnr_u:35.00 psnr_v:33.97
n:27 mse_avg:44.16 mse_y:54.84 mse_u:20.09 mse_v:25.53 psnr_avg:31.65 psnr_y:30.74 psnr_u:35.10 psnr_v:34.06
n:28 mse_avg:45.24 mse_y:56.58 mse_u:19.87 mse_v:25.22 psnr_avg:31.54 psnr_y:30.60 psnr_u:35.15 psnr_v:34.11
n:29 mse_avg:44.93 mse_y:56.11 mse_u:19.82 mse_v:25.28 psnr_avg:31.57 psnr_y:30.64 psnr_u:35.16 psnr_v:34.10
n:30 mse_avg:43.50 mse_y:54.04 mse_u:19.80 mse_v:25.04 psnr_avg:31.71 psnr_y:30.80 psnr_u:35.16 psnr_v:34.14
n:31 mse_avg:46.52 mse_y:58.66 mse_u:19.71 mse_v:24.77 psnr_avg:31.42 psnr_y:30.45 psnr_u:35.18 psnr_v:34.19
n:32 mse_avg:45.07 mse_y:56.47 mse_u:19.74 mse_v:24.82 psnr_avg:31.56 psnr_y:30.61 psnr_u:35.18 psnr_v:34.18
n:33 mse_avg:46.37 mse_y:58.40 mse_u:19.74 mse_v:24.89 psnr_avg:31.43 psnr_y:30.47 psnr_u:35.18 psnr_v:34.17
n:34 mse_avg:47.50 mse_y:60.11 mse_u:19.80 mse_v:24.76 psnr_avg:31.33 psnr_y:30.34 psnr_u:35.17 psnr_v:34.19
n:35 mse_avg:48.00 mse_y:60.38 mse_u:19.57 mse_v:26.89 psnr_avg:31.28 psnr_y:30.32 psnr_u:35.22 psnr_v:33.84
n:36 mse_avg:47.84 mse_y:60.30 mse_u:19.42 mse_v:26.41 psnr_avg:31.30 psnr_y:30.33 psnr_u:35.25 psnr_v:33.91
n:37 mse_avg:48.59 mse_y:61.27 mse_u:20.07 mse_v:26.41 psnr_avg:31.23 psnr_y:30.26 psnr_u:35.10 psnr_v:33.91
n:38 mse_avg:45.37 mse_y:56.44 mse_u:20.23 mse_v:26.28 psnr_avg:31.53 psnr_y:30.62 psnr_u:35.07 psnr_v:33.93
n:39 mse_avg:45.88 mse_y:57.21 mse_u:20.52 mse_v:25.92 psnr_avg:31.48 psnr_y:30.56 psnr_u:35.01 psnr_v:33.99
n:40 mse_avg:46.42 mse_y:57.79 mse_u:20.59 mse_v:26.78 psnr_avg:31.43 psnr_y:30.51 psnr_u:34.99 psnr_v:33.85
n:41 mse_avg:47.47 mse_y:59.26 mse_u:20.78 mse_v:26.97 psnr_avg:31.33 psnr_y:30.40 psnr_u:34.95 psnr_v:33.82
n:42 mse_avg:47.39 mse_y:59.66 mse_u:20.56 mse_v:25.13 psnr_avg:31.34 psnr_y:30.37 psnr_u:35.00 psnr_v:34.13
n:43 mse_avg:46.33 mse_y:58.17 mse_u:20.25 mse_v:25.04 psnr_avg:31.44 psnr_y:30.48 psnr_u:35.07 psnr_v:34.15
n:44 mse_avg:47.26 mse_y:59.92 mse_u:19.28 mse_v:24.61 psnr_avg:31.35 psnr_y:30.35 psnr_u:35.28 psnr_v:34.22
n:45 mse_avg:48.36 mse_y:61.61 mse_u:19.21 mse_v:24.52 psnr_avg:31.25 psnr_y:30.23 psnr_u:35.30 psnr_v:34.23
n:46 mse_avg:46.64 mse_y:59.00 mse_u:19.27 mse_v:24.55 psnr_avg:31.41 psnr_y:30.42 psnr_u:35.28 psnr_v:34.23
n:47 mse_avg:48.19 mse_y:61.28 mse_u:19.64 mse_v:24.41 psnr_avg:31.27 psnr_y:30.26 psnr_u:35.20 psnr_v:34.25
n:48 mse_avg:47.85 mse_y:60.78 mse_u:19.69 mse_v:24.29 psnr_avg:31.30 psnr_y:30.29 psnr_u:35.19 psnr_v:34.28
n:49 mse_avg:49.75 mse_y:63.24 mse_u:20.13 mse_v:25.41 psnr_avg:31.13 psnr_y:30.12 psnr_u:35.09 psnr_v:34.08
n:50 mse_avg:47.73 mse_y:60.78 mse_u:19.82 mse_v:23.45 psnr_avg:31.31 psnr_y:30.29 psnr_u:35.16 psnr_v:34.43
n:51 mse_avg:48.13 mse_y:61.52 mse_u:19.66 mse_v:23.05 psnr_avg:31.27 psnr_y:30.24 psnr_u:35.20 psnr_v:34.50
n:52 mse_avg:49.32 mse_y:63.32 mse_u:19.69 mse_v:22.94 psnr_avg:31.17 psnr_y:30.12 psnr_u:35.19 psnr_v:34.52
n:53 mse_avg:48.80 mse_y:62.54 mse_u:19.55 mse_v:23.12 psnr_avg:31.21 psnr_y:30.17 psnr_u:35.22 psnr_v:34.49
n:54 mse_avg:49.02 mse_y:62.86 mse_u:19.47 mse_v:23.20 psnr_avg:31.19 psnr_y:30.15 psnr_u:35.24 psnr_v:34.48
n:55 mse_avg:50.93 mse_y:65.70 mse_u:19.58 mse_v:23.20 psnr_avg:31.03 psnr_y:29.96 psnr_u:35.21 psnr_v:34.48
n:56 mse_avg:51.58 mse_y:66.72 mse_u:19.55 mse_v:23.04 psnr_avg:30.97 psnr_y:29.89 psnr_u:35.22 psnr_v:34.51
n:57 mse_avg:51.76 mse_y:66.72 mse_u:19.58 mse_v:24.08 psnr_avg:30.96 psnr_y:29.89 psnr_u:35.21 psnr_v:34.31
n:58 mse_avg:49.88 mse_y:64.00 mse_u:19.39 mse_v:23.91 psnr_avg:31.12 psnr_y:30.07 psnr_u:35.25 psnr_v:34.35
n:59 mse_avg:50.61 mse_y:65.24 mse_u:19.12 mse_v:23.58 psnr_avg:31.05 psnr_y:29.99 psnr_u:35.32 psnr_v:34.41
n:60 mse_avg:52.26 mse_y:67.67 mse_u:19.11 mse_v:23.76 psnr_avg:30.92 psnr_y:29.83 psnr_u:35.32 psnr_v:34.37
n:61 mse_avg:54.16 mse_y:70.39 mse_u:19.00 mse_v:24.42 psnr_avg:30.76 psnr_y:29.66 psnr_u:35.34 psnr_v:34.25
n:62 mse_avg:54.16 mse_y:70.39 mse_u:19.00 mse_v:24.42 psnr_avg:30.76 psnr_y:29.66 psnr_u:35.34 psnr_v:34.25
n:63 mse_avg:54.16 mse_y:70.39 mse_u:19.00 mse_v:24.42 psnr_avg:30.76 psnr_y:29.66 psnr_u:35.34 psnr_v:34.25
n:64 mse_avg:55.99 mse_y:73.26 mse_u:18.67 mse_v:24.21 psnr_avg:30.62 psnr_y:29.48 psnr_u:35.42 psnr_v:34.29
n:65 mse_avg:56.02 mse_y:73.30 mse_u:18.73 mse_v:24.20 psnr_avg:30.61 psnr_y:29.48 psnr_u:35.40 psnr_v:34.29
frame=   65 fps=0.0 q=-0.0 Lsize=N/A time=00:00:01.08 bitrate=N/A speed=22.2x
video:30kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_psnr_0 @ 0x1233900] PSNR y:30.273564 u:35.104567 v:34.378487 average:31.283939 min:29.998335 max:32.262509

Taking the first frame as an example, I would expect psnr_avg to be:

10 * log10(average_max^2 / mse_avg) = 10 * log10 * (255^2 / 38.32) = 32.30

However, this is reported as 32.26 by ffmpeg. If I instead use average_max = 254 in the above calculation, I get 32.26.

I believe 255 is the correct value for average_max, but it looks like it may be calculated incorrectly for some pixel formats due to rounding errors - it is calculated here. For yuv420p pixel format, I would expect the values of planeweight to be [4/6, 1/6, 1/6] and max to be [255, 255, 255]. I would therefore expect average_max to be given by:

average_max = (4/6 * 255) + (1/6 * 255) + (1/6 * 255) = 170.0 + 42.5 + 42.5 = 255.0

However, since average_max is of type int (defined here), this looks as though it would actually become:

average_max = (4/6 * 255) + (1/6 * 255) + (1/6 * 255) = 170 + 42 + 42 = 254

I believe this would explain the discrepancy and changing the type of average_max to double should fix it.

Change History (3)

comment:1 Changed 16 months ago by aitkenap

  • Resolution set to fixed
  • Status changed from new to closed

comment:3 Changed 16 months ago by cehoyos

  • Resolution changed from fixed to invalid
Note: See TracTickets for help on using tickets.