alexheretic / ab-av1

AV1 re-encoding using ffmpeg, svt-av1 & vmaf.
MIT License
473 stars 29 forks source link

How to force all crf ? #224

Closed pokemaster974 closed 1 month ago

pokemaster974 commented 1 month ago

Hi, I'm not sure I'm using correctly your tool (if it's the case, I'm sorry for opening this "issue"). Using this command ab-av1.exe crf-search --preset 7 --min-crf 16 --max-crf 37 --crf-increment 0.5 --min-vmaf 98 --max-encoded-percent 40 -i test.mkv

I got this result

- crf 26.5 VMAF 97.76 (5%)
- crf 21 VMAF 98.16 (7%)
  00:05:52 ####################################################################################### (sampling crf 23, eta 0s)
Encode with: ab-av1 encode -i test.mkv --crf 23 --preset 7
crf 23 VMAF 98.03 predicted video stream size 481.57 MiB (6%) taking 47 minutes

But I would like to know. Is it possible to test all crf from 16 to 37 and list of results (VMAF & predicted sizes) to have a full view ? I guess it choose crf 23 because it's just abode the VMAF 98 arg I enter into my cmd, but if I remove this it choose a crf which seems to high for my use.

- crf 26.5 VMAF 97.76 (5%) (cache)
- crf 31.5 VMAF 97.05 (3%)
  00:05:48 ####################################################################################### (sampling crf 37, eta 0s)
crf 37 VMAF 96.31 predicted video stream size 171.09 MiB (2%) taking 46 minutes

So without --min-vmaf it chooses crf 37 but I guess I probably want something like CRF 27-30 but I'm not sure to can choose with only this results (crf 37 seems too low for me, I would like something as 30-60% of reduction only.

alexheretic commented 1 month ago

The goal of crf-search is to find the highest crf value that encodes with the --min-vmaf specified quality minimum. It tries to do this as quickly as possible, ie with the fewest crfs tested as possible and sampling the video instead of encoding and analysing the entire thing for each crf. So indeed it does not test every crf by design because we want it to get the answer faster than that.

In your first result it started in the middle of your min/max crf and then found a crf for vmaf 98.03 after 2 extra steps which is pretty good. In your second example you are using the default --min-vmaf=95 by not specifying it. It ended at crf 37 as you had set that as you --max-crf. E.g. in this case the highest allowed crf, 37, satisfied the quality setting, vmaf 95.

Is it possible to test all crf from 16 to 37 and list of results (VMAF & predicted sizes) to have a full view ?

Yes, you can use sample-encode command instead for specific crf values you'd like to test. E.g. script it with something like:

for crf in 16 17 18; do
  echo "==> crf=$crf"
  ab-av1 sample-encode -i test.mkv --preset 7 --crf $crf
done

Other notes:

pokemaster974 commented 1 month ago

The goal of crf-search is to find the highest crf value that encodes with the --min-vmaf specified quality minimum. It tries to do this as quickly as possible, ie with the fewest crfs tested as possible and sampling the video instead of encoding and analysing the entire thing for each crf. So indeed it does not test every crf by design because we want it to get the answer faster than that.

In your first result it started in the middle of your min/max crf and then found a crf for vmaf 98.03 after 2 extra steps which is pretty good. In your second example you are using the default --min-vmaf=95 by not specifying it. It ended at crf 37 as you had set that as you --max-crf. E.g. in this case the highest allowed crf, 37, satisfied the quality setting, vmaf 95.

Is it possible to test all crf from 16 to 37 and list of results (VMAF & predicted sizes) to have a full view ?

Yes, you can use sample-encode command instead for specific crf values you'd like to test. E.g. script it with something like:

for crf in 16 17 18; do
  echo "==> crf=$crf"
  ab-av1 sample-encode -i test.mkv --preset 7 --crf $crf
done

Other notes:

* `--crf-increment 0.5` won't work well for the default encoder svt-av1, as it only supports integer increments. The fractional crfs just get rounded somehow to an integer. Fractional crfs _do_ work for some other encoders though (like libx265), which is why this arg exists.

* It seems a bit odd to require _"30-60% of reduction only"_ the point of this tool is to get the best compression for a given quality target. You can increase the vmaf value closer to max 100, but high size reduction should only be a good thing.

Thank for your reply. I understand better the goal of the tool. Using a script with sample-encode will keep some results encoded files ? (I was thinking it first but as I saw that there is no output in the sample script I guess no ?)

About your first note, I will remove crf-increment to keep 1 (default). About your last note, it's just that I've done some encodes with CRF 37 and I find it was far too high as bitrate was only 1500-200 for 4K and differences vs source were notable. It can be settings's issues also but I try to keep a bitrate about 3000-5000. Maybe it's just that this tool is not for my needs. I will try VMAF to see results I can obtain with VMAF 98 for example.

You can close it if you consider solved. Regards.

alexheretic commented 1 month ago

Yep, you can also try with higher min-vmaf. I have noticed that the vmaf 4k model (which is used for 4k videos) seems to get higher scores compared to the 1k model for more noticeable visual loss, the default min of 95 seemed reasonable for 1080p. But i haven't looked into this too deeply.

Using a script with sample-encode will keep some results encoded files ?

The example bash just outputs to stdout/stderr, it's just an example.

Glad i could help 🙂