Log in

View Full Version : Struggle with low-contrast video compression


MaxLt
10th April 2024, 19:36
I ran into an odd issue with videos I need to compress.

The video is of gymnasts performing, and the issue is particularly with floor routines. It's a 4K 60 FPS HLG HDR video with an unimportant mostly flat background (beige carpet) but a very important human quickly moving in random directions. The videos are for coaching and judging, so they are different from the broadcast style - no motion blur (shutter 1/200 or faster), and more zoomed out to show the position on the carpet better. There is low noise and no grain.

In compression, the priority is entirely on the gymnast, and it's important to be able to see fine details, like toe and hand positions and even facial expressions (judges want them to smile, no matter how gruelling the stuff they do is).

Compressing it straight with default x265 settings and CRF 19 (for example) crushes the video into ridiculously low 7-9mbit with much of the details being just blurred, especially high-motion parts. My guess is that much of the frame being flat carpet, the low contrast between carpet and gymnast, and the gymnast being a small part of the frame fool the compression algo into treating it as a low-complexity scene.

Lowering CRF helps very little with this problem (it seems most of the extra bits go not to gymnast but elsewhere) and also makes zoomed-in scenes shoot through the roof (>150Mbit, and I'm trying to keep it under 100mbit). I tried no-sao, and it helped a bit but also added some (small) artifacts around quick-moving limbs and on faces.

I guess I need to "tell" hevc to pay more attention and give more bits to that small, low-contrast, quick-moving object on a very flat and static background.

Any ideas? :confused:

benwaggoner
10th April 2024, 23:47
I ran into an odd issue with videos I need to compress.

The video is of gymnasts performing, and the issue is particularly with floor routines. It's a 4K 60 FPS HLG HDR video with an unimportant mostly flat background (beige carpet) but a very important human quickly moving in random directions. The videos are for coaching and judging, so they are different from the broadcast style - no motion blur (shutter 1/200 or faster), and more zoomed out to show the position on the carpet better. There is low noise and no grain.

In compression, the priority is entirely on the gymnast, and it's important to be able to see fine details, like toe and hand positions and even facial expressions (judges want them to smile, no matter how gruelling the stuff they do is).

Compressing it straight with default x265 settings and CRF 19 (for example) crushes the video into ridiculously low 7-9mbit with much of the details being just blurred, especially high-motion parts. My guess is that much of the frame being flat carpet, the low contrast between carpet and gymnast, and the gymnast being a small part of the frame fool the compression algo into treating it as a low-complexity scene.

Lowering CRF helps very little with this problem (it seems most of the extra bits go not to gymnast but elsewhere) and also makes zoomed-in scenes shoot through the roof (>150Mbit, and I'm trying to keep it under 100mbit). I tried no-sao, and it helped a bit but also added some (small) artifacts around quick-moving limbs and on faces.

I guess I need to "tell" hevc to pay more attention and give more bits to that small, low-contrast, quick-moving object on a very flat and static background.

Any ideas? :confused:
Can you share your command line? Maybe a screen shot of a typical frame?

To raise detail in some areas without raising bitrate a lot, you'll want to play with --aq-mode and --aq-strength.

If there is some noise in the source, some --nr-inter can help save bits by reducing that.

In general, going to --preset slower from the detail will give you lower bitrates at the same quality. Your very high peak bitrates suggests you're not setting --profile and --level, or --vbv-maxrate and --vbv-bufsize.

If this was a big problem with a budget behind it, I'd come up with a ML-based gymnast detector to define regions of visual saliency, and then differently compress those regions less than the rest of the frame. Or at least blur them a bit to make them easier to compress.

Emulgator
12th April 2024, 16:53
Limiting QPmax should help as well. It may be helpful to upload a sample.
I would like to tickle any encoder a bit to spend bits in dark and guessed-flat areas because such scenario comes around more often.

rwill
12th April 2024, 20:18
Have you tried --no-cutree and --tune psnr yet ?

MaxLt
12th April 2024, 21:12
The command line I got the best results from so far is

f:\ffmpeg\bin\ffmpeg -hwaccel cuda -i %%a -c:v libx265 -preset slower -crf 19 -color_primaries bt2020 -colorspace bt2020nc -x265-params "deblock=-2,-2:high-tier=1:aq-mode=2:frame-threads=0:no-sao=1:psy-rdoq=2.00:subme=7:merange=64

Going from "slow" to "slower" did improve things noticeably.

I have difficulty with attaching a screenshot. I'll try to figure it out later.