Opened 4 years ago

Last modified 21 months ago

#3345 new defect

Bias in planar YUV to YUV bit depth conversion

Reported by: abc123 Owned by:
Priority: normal Component: swscale
Version: git-master Keywords: bounty
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Summary of the bug: Unscaled YUV to YUV conversion (swscale_unscaled.c:planarCopyWrapper) produces output with a bias of -0.375 compared to the ideal real number result. We compare the ffmpeg output to the equation round(x / 4.0) which maps limited-range ITU-R 709 10-bit (64-940 Y, 64-960 UV) to 8-bit (16-235 Y, 16-240 UV).

How to reproduce:

% ffmpeg -pix_fmt yuv420p10le -s 1280x720 -i testGrad_01.yuv -pix_fmt yuv420p -f rawvideo testGrad_02.yuv
ffmpeg version N-59852-g785dc14 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jan 14 2014 22:07:30 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfi
g --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopenco
re-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-li
bvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 62.100 / 52. 62.100
  libavcodec     55. 48.101 / 55. 48.101
  libavformat    55. 23.103 / 55. 23.103
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  1.100 /  4.  1.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
[rawvideo @ 0000000000338080] Estimating duration from bitrate, this may be inaccurate
Input #0, rawvideo, from 'testGrad_01.yuv':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 552960 kb/s
    Stream #0:0: Video: rawvideo (Y3[11][10] / 0xA0B3359), yuv420p10le, 1280x720, 552960 kb/s, 25 tbr, 25 tbn, 25 tbc
File 'testGrad_02.yuv' already exists. Overwrite ? [y/N] y
Output #0, rawvideo, to 'testGrad_02.yuv':
    encoder         : Lavf55.23.103
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1280x720, q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> rawvideo)
Press [q] to stop, [?] for help
frame=    1 fps=0.0 q=0.0 Lsize=    1350kB time=00:00:00.04 bitrate=276480.0kbits/s
video:1350kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.000000%

Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.

An example gradient (1280x720, 10-bit, 4:2:0) is attached to this ticket. We can pay a bounty for a fix to this problem.

Attachments (1) (9.4 KB) - added by abc123 4 years ago.

Download all attachments as: .zip

Change History (7)

Changed 4 years ago by abc123

comment:1 Changed 4 years ago by kierank

I think this is expected behaviour because we specifically don't want to round but instead dither.

comment:2 Changed 4 years ago by abc123

Dithering is perfectly fine (in fact, expected) but it should not change the average level of the image. If you test the example frame with the command-line I posted, you will see a very obvious change in global color.

comment:3 Changed 4 years ago by IsaacDian

Sorry to ask, but why did this issue seem to be ignored? Does it need more samples? FWIW, Libav swscale doesn't have this issue.

comment:4 Changed 4 years ago by kierank

Libav swscale doesn't have dither and does a plain shift which is why it doesn't have the issue.

comment:5 Changed 3 years ago by holden

  • Keywords bounty added

comment:6 Changed 21 months ago by richardpl

How much is bounty?

Note: See TracTickets for help on using tickets.