Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
Thread Tools | Search this Thread | Display Modes |
17th January 2018, 11:05 | #1 | Link |
Registered User
Join Date: Jan 2018
Posts: 9
|
Color banding when downscaling from UHD HDR10 to FHD - bug in scaler?
I would like to downscale a video from 2160p to 1080p, and want to encode it in HEVC with HDR10, same as the source. I already found in the past days that this is not a trivial thing to do if you want to avoid video encoding tools that only use 8 bit internally. I only found and tried two working ways so far: Decode and downscale with either AviSynth+ or FFmpeg, and pipe it to x265 (10bit version).
Unfortunately I found color banding in the reencoded video, which looks much worse than encoding it with SDR. I tried to find out where the banding happens. I piped the FFmpeg output to y4m files and found the color banding already there, so x265 was innocent. I skipped the downscaling and the banding was gone, so I suspected the scaler did something. I confirmed that the scaler has matching input and output pixel formats (yuv420p10le), so that there should be no conversion. I checked different scaling algorithms (bicubic, bilinear, lanczos, neighbor), but all show the banding, even nearest neighbor! I checked different output video sizes and found that 2176x1224 and below shows banding, but 2240x1260 and above did not. This happens with both AviSynth+ and FFmpeg! I can extract video frames with banding and post them here, if it would be useful for someone to find an explanation. One of my test conversion lines: Code:
ffmpeg.exe -i input.mp4 -strict -1 -pix_fmt yuv420p10le -vf "scale=iw/2:-1:out_color_matrix=bt2020:out_h_chr_pos=0:out_v_chr_pos=0:flags=print_info" -map 0:v:0 -f yuv4mpegpipe - | x265.exe --preset slow --input - --y4m --output-depth 10 --profile main10 --level-idc 5.1 --crf 0 --vbv-bufsize 160000 --vbv-maxrate 160000 --range limited --colorprim bt2020 --transfer smpte2084 --colormatrix bt2020nc --master-display "G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)" --max-cll "1000,400" --output output.hevc Last edited by Woodstock; 17th January 2018 at 11:07. |
18th January 2018, 18:51 | #3 | Link |
Registered User
Join Date: Jan 2018
Posts: 9
|
Thank you for the suggestion. Dithering is of course a solution to fix color banding, but I am looking for a solution on how to avoid it. The decoding and encoding is not responsible for it, so there must be something unwanted happening in the scaling. I fear that the scaling happens in an 8 bit color space, which would explain where the banding comes from.
|
18th January 2018, 19:32 | #5 | Link | |
Registered User
Join Date: Jan 2010
Posts: 709
|
Quote:
HDR contents dynamic range is so wide that 10bit shades are about the same as 8bit SDR ones. So dithering is avoidable for 10bit SDR (IMHO not a good idea) but almost mandatory for 10bit HDR stuff. (also I don't know if ffmpeg-scaler will process in float or higher bitdepth, maybe converting to yuv420p12le first can help)
__________________
powered by Google Translator Last edited by Motenai Yoda; 18th January 2018 at 19:36. |
|
18th January 2018, 21:17 | #6 | Link | |
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,770
|
Quote:
|
|
18th January 2018, 23:45 | #7 | Link |
Registered Developer
Join Date: Mar 2010
Location: Hamburg/Germany
Posts: 10,346
|
Try adding "accurate_rnd" to the scale flags, it can in such cases improve the precision.
__________________
LAV Filters - open source ffmpeg based media splitter and decoders |
19th January 2018, 14:53 | #9 | Link | |
Registered User
Join Date: Jan 2018
Posts: 9
|
Quote:
Thanks, I tried (without dither). Unfortunately the same result as scale, banding for 2176x1224 and lower. |
|
19th January 2018, 18:18 | #11 | Link |
Registered User
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,407
|
Why would NN not cause banding?
__________________
madVR options explained |
19th January 2018, 18:47 | #14 | Link |
Registered Developer
Join Date: Mar 2010
Location: Hamburg/Germany
Posts: 10,346
|
Thats not quite true. If you have a smooth gradient and downscale it with NN (or realistically, any algorithm), you'll get banding because the resulting image is quite simply smaller, and the gradient has to be represented with less pixels - less pixels means perhaps not enough pixel to fully represent every step of the gradient, and missed steps cause banding.
__________________
LAV Filters - open source ffmpeg based media splitter and decoders |
19th January 2018, 20:42 | #15 | Link |
Registered User
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,407
|
And that is why you need dithering.
__________________
madVR options explained |
20th January 2018, 13:09 | #18 | Link | |
Registered User
Join Date: Jan 2018
Posts: 9
|
Quote:
0123456789 Then downscale it with nearest neighbor: 02468 See what I mean? If you have a smooth gradient and reduce the pixels, how can you have not enough pixels afterwards? I guess you meant the opposite. You can get banding if you upscale it: 0000111122223333444455556666777788889999 Because you have not enough shades for each pixel. Or if you upscale 02468 with nearest neighbor you get for example: 00002222444466668888 Also banding due to missing interpolation. If is also possible to get banding from scaling algorithms like bilinear or bicubic as they can smooth away an existing dithering. But I don't see how downscaling with nearest neighbor can cause banding. I am always happy to learn more though. Last edited by Woodstock; 20th January 2018 at 13:20. |
|
20th January 2018, 13:11 | #19 | Link |
Registered Developer
Join Date: Mar 2010
Location: Hamburg/Germany
Posts: 10,346
|
But this isn't quite smooth anymore, is it? Sure, its even steps, but still bigger steps then before. How many steps can you take out before you see visual banding?
__________________
LAV Filters - open source ffmpeg based media splitter and decoders |
20th January 2018, 15:16 | #20 | Link |
Registered User
Join Date: Jan 2018
Posts: 9
|
If each pixel has another shade it is perfect: the gradient can't be smoother than that on the specific display. Color banding by definition requires the same color on multiple pixels, so something like 00112233445566778899 would be the minimum to call it banding.
|
Thread Tools | Search this Thread |
Display Modes | |
|
|