Log in

View Full Version : Tool to test & edit AVC CQMs


Manao
30th October 2005, 00:47
Hi everyone,

I made an avisynth filter that allows to encode frames directly with x264. It takes custom matrices as input.

Here is the link : http://manao4.free.fr/AVCMatrices-1.0.zip

Here is the short documentation :AVCMatrices(clip c, string "luma4x4" , string "chroma4x4" , string "luma8x8",
string "pluma4x4", string "pchroma4x4", string "pluma8x8",
int "quant", int "deblocking", bool "size", bool "psnr")

The 6 strings correspond to the custom matrices ( 3 intra first, then 3 inter ). If
omitted, a string is defaulted to an all-16 matrix. If no 8x8 matrices are given,
8x8dct gets disabled in x264. If no inter matrices are given, only intra will be done.

The encoding is done at a constant quantizer ( default 26 ), with a ipratio of 1.4
if there's an inter matrix ( else, ipratio = 1.0, to make all I quantizers equal to the
chosen quantizer ).

Deblocking is disabled by default, specifying a value to "deblocking" will enable it
and set its strength.

Finally, "size" shows each frame size, while "psnr" show each frame psnr ( luma, chroma, both ).Have fun ( and report bugs :( )

Manao
31st October 2005, 20:22
*Bump*

Nobody seemed to have noticed that filter. Did anybody try it ? Did it work ?

Because it allows easy on the fly CQM comparison ( or other settings, such as deblocking ) : source = mpeg2source("foo")

enc1 = source.avcmatrices(deblocking = -4)
enc2 = source.avcmatrices(deblocking = 0)

return interleave(enc1, enc2)It allows to check the visual difference between two deblocking strength.

PSNR and filesize information are there to help you take into account the change in compressibility that different settings imply, and so on.

Sharktooth
31st October 2005, 20:41
i'll try it in the weekend.

Revgen
1st November 2005, 00:31
@Manao

I'd like to use your filter but I have some questions.

1) Does the avcmatrices filter use the vfw version of x264 or the cli version? If it uses cli, should it be located in the directory of the cli executible?

2) In your instructions you say that the second string should be the "Intra Chroma 4X4". This is confusing because some matrices like Sharktooths EQM marix are separated into INTRA4X4_CHROMAU and INTRA4X4_CHROMAV. Should I just combine the two values together with INTRA4X4_CHROMAU entered first and INTRA4X4_CHROMAV entered second?

Here's Sharktooths CQM for a better example:

INTRA4X4_LUMA =
6, 9,13,19,
9,14,20,27,
13,20,28,35,
19,27,35,42

INTRA4X4_CHROMAU =
6,10,15,20,
10,16,21,27,
15,21,28,33,
20,27,33,42

INTRA4X4_CHROMAV =
6,10,15,20,
10,16,21,27,
15,21,28,33,
20,27,33,42

INTER4X4_LUMA =
8,11,15,20,
11,16,21,27,
15,21,28,35,
20,27,35,42

INTER4X4_CHROMAU =
8,11,16,21,
11,17,22,27,
16,22,28,35,
21,27,35,42

INTER4X4_CHROMAV =
8,11,16,21,
11,17,22,27,
16,22,28,35,
21,27,35,42

INTRA8X8_LUMA =
6, 7, 8,10,12,14,16,18,
7, 9,11,13,15,16,18,20,
8,11,14,16,17,19,21,22,
10,13,16,18,20,22,24,26,
12,15,17,20,23,25,28,30,
14,16,19,22,25,29,34,38,
16,18,21,24,28,34,46,52,
18,20,22,26,30,38,52,72

INTER8X8_LUMA =
8, 9,10,12,14,16,19,21,
9,11,13,15,17,19,21,23,
10,13,16,18,20,22,23,25,
12,15,18,21,23,24,26,32,
14,17,20,23,25,27,33,40,
16,19,22,24,27,34,41,52,
19,21,23,26,33,41,53,64,
21,23,25,32,40,52,64,80


Thanks.

Manao
1st November 2005, 07:46
The filter doesn't allow to use matrices stored in files at the moment ( you have to type the matrices in avisynth ). There's only one chroma matrix because, as you can see, both chroma matrices for U and V are always the same ( which is normal, since both chroma channels should be processed alike ).

The filter is a standalone ( it links statically with libx264.lib ) so you don't have to install x264.

I'll add the possibility to give cqm files in a few hours.

Revgen
1st November 2005, 18:43
@manao

I tried comparing two different deblocking strengths as you illustrated above. It works fine.

However when I tried to compare Sharktooths EQM matrix to Flat 16 Vdub would crash on startup.

Here's my script

source=mpeg2source("E:\3s-Goofs and Saddles\goofs.d2v",idct=6)

enc1=source.avcmatrices(luma4x4="16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16",chroma4x4="16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16",luma8x8="16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16",pluma4x4="16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16",pchroma4x4="16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16",pluma8x8="16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16",quant=26,deblocking=0,size=true,psnr=true)
enc2=source.avcmatrices(luma4x4="6,9,13,19,9,14,20,27,13,20,28,35,19,27,35,42",chroma4x4="6,10,15,20,10,16,21,27,15,21,28,33,20,27,33,42",luma8x8="6,7,8,10,12,14,16,18,7,9,11,13,15,16,18,20,8,11,14,16,17,19,21,22,10,13,16,18,20,22,24,26,12,15,17,20,23,25,28,30,14,16,19,22,25,29,34,38,16,18,21,24,28,34,46,52,18,20,22,26,30,38,52,72",pluma4x4="8,11,15,20,11,16,21,27,15,21,28,35,20,27,35,42",pchroma4x4="8,11,16,21,11,17,22,27,16,22,28,35,21,27,35,22",pluma8x8="8,9,10,12,14,16,19,21,9,11,13,15,17,19,21,23,10,13,16,18,20,22,23,25,12,15,18,21,23,24,26,32,14,17,20,23,25,27,33,40,16,19,22,24,27,34,41,52,19,21,23,26,33,41,53,64,21,23,25,32,40,52,64,80",quant=26,deblocking=0,size=true,psnr=true)

return interleave(enc1,enc2)

Is there something I'm doing wrong?

EDIT

I guess I'l just wait for the new version.

Manao
1st November 2005, 18:57
Yes, there's something wrong, but it's my fault, I didn't document the filter properly : coefficients have to be separated by spaces, not comma.

Anyway, here's a new version, which can load CQM matrices : http://manao4.free.fr/AVCMatrices-1.1.zip

Oh, and to finish the undocumented 'features', if you want to do a test without CQM, but with PFrames, you'll have to give at least one flat P-matrix, else the filter will encode with only IFrames.

Revgen
1st November 2005, 19:35
Just tried the newer version. It works fine. :)
I was able to compare Sharktooths with Flat 16 and see the differences.


Also, would it be difficult to include SSIM?
Although the PSNR is good to know, It would also be good to know the SSIM differences.

Thanks.

Manao
1st November 2005, 19:53
Well, I added PSNR because there was nothing to code to add it ( x264 computes PSNR if asked ). SSIM would need me to code it. However, you can compute it with the SSIM.dll filter ( alas, that needs you not to output the size & psnr )

Anyway, if I output PSNR, it's only informative, to know whether things can be compared visually or not : if PSNR / size between two CQMs differ a lot, it means that the matrices don't scale in the same way. Hence, you have to change the quantizer in order size / PSNR to match as closely as possible. Else, comparing the matrices would be quite useless. That's the only reason to output PSNR.

SSIM could serve the same purpose, but wouldn't really bring more information than PSNR already brings : SSIM is as ill suited as PSNR to check CQM quality, and PSNR at least has the advantage of being easy to compute.

Revgen
1st November 2005, 19:59
Okay thats fine. I'll just use the .dll instead.

Thanks again. :)

DaWolfman
5th November 2005, 09:49
Well done, Manao. Just a few things-

1. Perhaps my Avisynth scripting skills are lousy, but is there a way to use am input file AND specify quantizer, deblocking, etc. without specifying the individual matrices?

2. Can you include the kb/s as well? I rarely use quantizer as a means of judging my output. It wouldn't matter if I specified it in the .avs file or if it was in the HUD, so long as I had an idea of what it was...

3. Does it support High profile?

Thanks for the kickass filter Manao! Keep up the good work!

Manao
5th November 2005, 10:01
1. Perhaps my Avisynth scripting skills are lousy, but is there a way to use am input file AND specify quantizer, deblocking, etc. without specifying the individual matrices?result = source.AVCMatrices(file = "my_file.cqm", quant = 20, deblocking = 0)That should work.Can you include the kb/s as well? I rarely use quantizer as a means of judging my output. It wouldn't matter if I specified it in the .avs file or if it was in the HUD, so long as I had an idea of what it was...Yes, it can be done, wait a minute. But what HUD means ?Does it support High profile?You're using cqm, so it does support high profile :) If you meant 8x8, it's enabled as soon as you give a cqm file or a 8x8 cqm matrix.

akupenguin
5th November 2005, 10:10
HUD = "heads up display". Called OSD in ffdshow.

Manao
5th November 2005, 13:29
OK, here's the new version : http://manao4.free.fr/AVCMatrices-v1.2.zip

Changes : * added a "br" parameter ( in kbps ). If given, the encoding is done in ABR at this bitrate
* added an "intra" bool parameter to force intra encoding ( if not, given, P's are enabled )
* changed parameter names ( to make them shorter ) : quant -> q, deblocking -> dbk, and matrix names have changed ( look at the documentation )
* print local quantizer, and local bitrates ( one frame / one second / ten seconds ).
* fixed internal mistakes

Thanks for the definition of HUD :)

McCauley
31st March 2008, 15:10
Hi Manao,

first i want to say thank you this PlugIn!

Is there a way to use a user defined x264.exe for testing the matrices?
If yes, how do i tell the PlugIn to use a custom .exe?
In regard of the AQ patched exes, that would be very useful to see how custom matrices behave with those.


Regards and thanks in advance
McCauley

Manao
31st March 2008, 18:41
You can't use x264.exe, you need x264 library. So if you want an update of the core encoder, you need either to fetch the plugin's source code, x264's source code, and build it yourself (don't bother if you've never done any programming).

If there's a real need, I can update the plugin this week end, perhaps earlier.

McCauley
31st March 2008, 21:59
If there's a real need, I can update the plugin this week end, perhaps earlier.

That would be really splendid! But you can take your time.

If i understood the documentation correctly i'm only able too specifiy the deblocking strength, could you add the threshold too, or would that be too much fiddling?

Regards
McCauley


PS: Thanks for your work on your Masktools too, they are really becoming the backbone of Avisynth filtering capabilities!

Sharktooth
1st April 2008, 02:30
Manao, if you do that, can you please add SSIM?
Recent x264 versions can calculate it too.

Manao
1st April 2008, 20:38
*bump*

http://manao4.free.fr/AVCMatrices-v1.3.7z

I updated x264 to the latest revision, and I allow setting aq (method & strength). SSIM is printed when psnr is asked for.

Sharktooth
1st April 2008, 20:42
tnx :)

McCauley
2nd April 2008, 02:04
Whoah, that was fast.
Thanks.:)

Regards
McCauley

gooberon
7th April 2008, 00:02
Hi Manao,
Great work! Just have an issue.
When I run my source through the filter the output is compressed horizontally and some of the frame is cut off top and bottom, getting about 1/4 of the top part of the frame.

:thanks:

Manao
7th April 2008, 06:11
Can you post a screenshot ? are you sure your input is YV12 ?

gooberon
8th April 2008, 01:50
Doh!
Works now. Outstanding, I love this plugin!

many :thanks:

Sagekilla
3rd August 2008, 20:28
I've updated AVCMatrices so it can pass off more parameters to x264. Here's the latest build with Subme, CRF, References, Bframes (borked) enabled. B-Frames are a bit funny because I haven't included a workaround to re-arrange them according to how they're supposed to be displayed and the OSD doesn't properly print out Type: B when they show up. So, use them if you wish but be aware of the issues.

Here's AVCMatrices 1.31, please let me know if any issues arise: http://www.mediafire.com/download.php?5kyngh073oh

Sagekilla
4th August 2008, 01:12
Only known issues I've encountered is that B-Frames will cause AvsP to throw an exception, but if you close that exception you should be able to continue forward without issues. This is only the case when you have bframes=1. If you have multiple B-frames, AvsP is going to go insane. I haven't created a workaround for B's yet because I only have a minor understanding of the code that goes into this filter.

If anyone has an idea of how to fix this so B-Frames can be used, and displayed, properly, help would be great! :)