Is there libvpx "Constant quality" parameter in Avidemux like in ffmpeg?

Started by iG0R, October 22, 2023, 06:16:19 PM

Previous topic - Next topic

iG0R

Hi.
Could you please tell me with which parameters of VP9(libvpx) "libvpx VP9 Encoder Configuration" in Avidemux can achieve the same quality, speed and output file size as ffmpeg with parameters "-i input.wmv -c:v libvpx-vp9 -crf 50 -b:v 0 output.webm", which should correspond to "Constant Quality", but I have not found such parameter in Avidemux, only "Constant quantizer".
As stated here https://trac.ffmpeg.org/wiki/Encode/VP9, Constant quality (Constant quantizer), as I understand it, Constant quality = Constant quantizer, so "Constant quality" in ffmpeg should correspond to "Constant quantizer" in Avidemux, but the latter has a maximum value that can be set to 31, which does not correspond to -crf 50 in ffmpeg.
Why such a question arouse. When encoding wmv video with a duration of 13 seconds and a size of 1 578 KB:
- with ffmeg, using the above parameters, it takes 1 minute 17 seconds with a resulting size of 448 KB.
- with Avidemux, using the same input file and the parameters Two pass - Average Bitrate (0 kb/s), Speed 4, Use as many threads as CPU cores checked, Deadline - Best quality, it takes 2 minutes 57 seconds (measured with a stopwatch, as I couldn't find where Avidemux shows the exact encoding time data, if there is, please let me know where to find it in Avidemux) and the resulting file is even larger than the original - 1 706 KB. Surprisingly, the visual quality of the video is indistinguishable from the file obtained using ffmpeg, which has a size of 448 KB.

eumagga0x2a

Quote from: iG0R on October 22, 2023, 06:16:19 PMAs stated here https://trac.ffmpeg.org/wiki/Encode/VP9, Constant quality (Constant quantizer), as I understand it, Constant quality = Constant quantizer, so "Constant quality" in ffmpeg should correspond to "Constant quantizer" in Avidemux, but the latter has a maximum value that can be set to 31, which does not correspond to -crf 50 in ffmpeg.

Wrong maximum value in the quantizer spinbox in VP9 encoder plugin configuration dialog fixed, thank you.

With constant quantizer set to 50, the resulting picture quality will be horrible. To my astonishment, setting rc_end_usage to VPX_CQ didn't make the encoder to ignore bitrate (rc_target_bitrate) completely (which Avidemux doesn't touch in the constant quantizer mode, so that it stays at the default value of 256), but to a very large extent, it does ignore it, so this doesn't need to be changed in the code IMHO.

The main factor affecting encoding speed is the value set in the "Speed" spinbox. The default setting in Avidemux may be detrimental to compression rate, use a different one if you care about it. I'll try to check what libavcodec wrapper for libvpx does internally, however.

iG0R

Quote from: eumagga0x2a on October 23, 2023, 09:46:48 AMWrong maximum value in the quantizer spinbox in VP9 encoder plugin configuration dialog fixed, thank you.

Thanks a lot!

Quote from: eumagga0x2a on October 23, 2023, 09:46:48 AMWith constant quantizer set to 50, the resulting picture quality will be horrible.

I cannot understand why everyone, including you, mentioning constant quantizer set to 50, claims that the resulting picture quality will be terrible. Here are the original, ffmpeg and avidemux encoded samples of the aforementioned video.

Original video
https://drive.google.com/file/d/1bHlHWA1ONjlXKgKMvGA5YV0FvlTQ3gFQ/view?usp=sharing

ffmpeg encoded
https://drive.google.com/file/d/1fcm6HxRdFzoosywFZ-W0aTh1WJ32YZkE/view?usp=sharing

Avidemux encoded
https://drive.google.com/file/d/1lvYktqI5Huar2h1hA6hPr4PtLnHymtVt/view?usp=sharing

iG0R

Also there is an issue with libvpx -> Configue -> Encoding mode -> Two-pass video size
The minimum value that can be set is 1 MB, but what if the user needs, for example, 448 KB?

eumagga0x2a

Quote from: iG0R on October 24, 2023, 06:06:20 AMThe minimum value that can be set is 1 MB, but what if the user needs, for example, 448 KB?

She will need to calculate the average bitrate herself instead of letting Avidemux do the math based on specified video size. GUI covers most typical use cases, and better accuracy than 1 MiB is very seldom needed and even more seldom achieved.

eumagga0x2a

Quote from: iG0R on October 24, 2023, 05:47:34 AMI cannot understand why everyone, including you, mentioning constant quantizer set to 50, claims that the resulting picture quality will be terrible.

Because I encoded a sample video in CQ mode using different quantizer values, from 63 through 50 to 30 before replying.

iG0R

Quote from: eumagga0x2a on October 24, 2023, 09:16:03 AMShe will need to calculate the average bitrate herself instead of letting Avidemux do the math based on specified video size. GUI covers most typical use cases, and better accuracy than 1 MiB is very seldom needed and even more seldom achieved.

Is there any way to make it possible to set this parameter in KB?

Quote from: eumagga0x2a on October 24, 2023, 09:18:49 AMBecause I encoded a sample video in CQ mode using different quantizer values, from 63 through 50 to 30 before replying.

Did you see the attached sample videos a few posts above - is the ffmpeg sample quality really terrible compared to avidemux one?

sark

@ iGOR

I'm just curious. What is your OS setup, and Avidemux version? WEBM doesn't work on my setup. Avidemux cannot open the demuxer. I don't have a huge need for VP9 & WEBM, so this has never really bothered me, but I would be interested to know how you are managing to implement it, for future reference.

Thanks

 

iG0R

@sark
Hi.
OS: Microsoft Windows [Version 10.0.19045.2673] 64bit
Avidemux: Avidemux 2.8.2 (230930_f0b8f33c69b-fflibs 6.0
https :// www. upload. ee/files/15765752/Avidemux282_30092023_x64_portable.zip.html
From here https://forum.ru-board.com/topic.cgi?forum=5&topic=26189&start=2620

sark

Quote from: iG0R on October 24, 2023, 03:18:34 PM@sark
Hi.
OS: Microsoft Windows [Version 10.0.19045.2673] 64bit
Avidemux: Avidemux 2.8.2 (230930_f0b8f33c69b-fflibs 6.0
https :// www. upload. ee/files/15765752/Avidemux282_30092023_x64_portable.zip.html
From here https://forum.ru-board.com/topic.cgi?forum=5&topic=26189&start=2620

Thanks for that. Will take a look when I get home.

Edit... Solved. My error...

It proved not to be a version issue (successfully encoding your original sample video proved this), but an audio issue. If I do not select Opus I get a muxer error. If I do select Opus, I get a warning that the audio has an unsupported frequency.
By removing the audio track I can encode to vp9 (webm).

I wasn't aware webm was limited to Opus audio. The muxer error gives no clue to this. Also, it appears webm is very fussy about the audio you present it with.

Finally. I can see little difference in quality between all three samples you uploaded. I tested with ffmpeg and it appears vp9 affects much less of a change in quality across its crf settings compared to x264.

Thanks again.


eumagga0x2a

@iG0R

Finally, I had time to look (albeit extremely cursorily) into libavcodec/libvpxenc.c code. FFmpeg defaults to "Speed" (cpu_used parameter) = 1, Avidemux to 4. This makes a lot of difference regarding output quality and compression.

The sample you provided is not a normal video content because it is mostly static. With a normal video, quantizer set to 50 produces output of very poor quality.

@sark

Quote from: sark on October 24, 2023, 06:15:48 PMI wasn't aware webm was limited to Opus audio.

It is not limited to Opus audio, it is limited to either Vorbis or Opus, so it is very limited ;D

sark


Quote from: eumagga0x2a on October 24, 2023, 10:11:42 PM
Quote from: sark on October 24, 2023, 06:15:48 PMI wasn't aware webm was limited to Opus audio.

It is not limited to Opus audio, it is limited to either Vorbis or Opus, so it is very limited ;D

It appears Vorbis is a more accommodating option, accepting, without issue, both the AC3 and AAC files I commonly generate.
I rarely upload content, but on the occassions I need to do this, I might now consider VP9 and Webm if file size is critical. All useful to know.

Thanks