ab-av1 icon indicating copy to clipboard operation
ab-av1 copied to clipboard

optimize for quality for a given max size

Open tcurdt opened this issue 1 year ago • 4 comments

I need to re-compress some videos. I am trying to find the setting for

  • a similar (not much worse) video quality
  • a similar (not much bigger) file size
$ ab-av1 crf-search -e h264_videotoolbox --samples 1 -i "Test.avi"    
- crf 32 VMAF 42.43 (17%)
- crf 21 VMAF 42.43 (17%)
- crf 10 VMAF 42.43 (17%)
  00:00:47 ################################################### (sampling crf 10, eta 0s)
Error: Failed to find a suitable crf

$ ab-av1 crf-search -e h264 --samples 1 -i "Test.avi" 
- crf 32 VMAF 53.82 (19%)
- crf 21 VMAF 87.65 (77%)
- crf 10 VMAF 98.10 (260%)
- crf 13 VMAF 97.07 (186%)
- crf 15 VMAF 95.92 (149%)
- crf 16 VMAF 95.11 (134%)
- crf 17 VMAF 94.06 (120%)
  00:01:52 ################################################## (sampling crf 17, eta 0s)
Error: Failed to find a suitable crf

I used "--samples 1" just for a first quick test.

Does this crf 10 VMAF 98.10 (260%) mean video quality is at 98% of the original but size has increased to 260%? So for my use case crf would need to be between 21 and 17. Why isn't it further searching in that range?

In this issue you wrote

The default --min-vmaf is 95, the default --max-encoded-percent is 80. So in your case the search has found that crf 24 doesn't satisfy either and so gives up the search. With preset 8 there is no crf value that can deliver that quality & compression. You can, of course, override these defaults and/or try lower presets. However, in this case I imagine the input video is just already fairly compressed and so difficult to re-encode.

I am a litte unsure on how to set --max-encoded-percent and --min-vmaf for this use case.

It seems like I am looking for

--max-encoded-percent 110
--min-vmaf 90

But trying with that

$ ab-av1 crf-search -e h264 --max-encoded-percent 110 --min-vmaf 90 --samples 1 -i "Test.avi"
- crf 32 VMAF 53.82 (19%) (cache)
- crf 21 VMAF 87.65 (77%) (cache)
- crf 10 VMAF 98.10 (260%) (cache)
- crf 19 VMAF 91.29 (97%)
- crf 20 VMAF 89.59 (87%) (cache)
  00:00:15 ############################################################################# (sampling crf 20, eta 0s)
Encode with: ab-av1 encode -e h264 -i Test.avi --crf 19

crf 19 VMAF 91.29 predicted video stream size 662.36 MiB (97%) taking 4 minutes
$ ab-av1 crf-search -e h264 --max-encoded-percent 110 --min-vmaf 92 --samples 1 -i "Test.avi"
- crf 32 VMAF 53.82 (19%) (cache)
- crf 21 VMAF 87.65 (77%) (cache)
- crf 10 VMAF 98.10 (260%) (cache)
- crf 16 VMAF 95.11 (134%) (cache)
  00:00:15 ######################################################################### (sampling crf 18, eta 0s)
Encode with: ab-av1 encode -e h264 -i Test.avi --crf 18

crf 18 VMAF 92.80 predicted video stream size 739.64 MiB (108%) taking 4 minutes

It looks like ab-av1 is focusing to optimize for size while I'd rather like to optimize for quality. Is there a way to switch that priority?

Side questions:

  • Why is it that re-compression with a more effient codec results in bigger files when not re-compression from the source?
  • Why is it that h264_videotoolbox is ignoring the crf values?

tcurdt avatar Apr 07 '23 07:04 tcurdt