Shalcker
8th July 2003, 14:15
More then a month ago in a thread named "Understanding a Quantization Matrix" was interesting discussion which sadly rather quickly faded...
But people mentioned there that to create good custom matrix we should look at values entering quantization, and that previewing results for a given quantizer can be helpful too... I've been thinking about that for a while and it looked like rather simple thing to do, at least for keyframes.
Therefore I created AviSynth filter for that purpose.
It can:
- output various data about processed frame into specified text file
and
- process frame in a way close to actual MPEG4 processing (at least i hope so), with frequency data quantized according to specified quantizer and quantization matrix, allowing you to note all artifacts quantization may introduce to picture.
Here it is, available for download, sources included - DCTCheck v0.4.1 (http://web.etel.ru/~shalcker/DCTCheck_v041.zip)
Only accepts YV12 and mod 16 width and height frames.
Posting this to AviSynth board seems pointless since only place where you can use custom quantization matrices is XviD...
Usage is explained in detail within DCTCheck.txt in archive.
----
Few quick examples:
DCTCheck(clip, Quant=2, idct=2, Matrix="c:\custom_matrix.mtx")
should result in output frame close to actual keyframe with quantizer 2 and custom matrix from custom_matrix.mtx (unless custom matrix is specified quantization matrix defaults to all-8). You can use output of the filter to check difference with original frame by using Subtract or ConvertToYUY2() and Compare.
DCTCheck(clip, "FYCKTtMmXxNnEe", Quant=10, Output="c:\temp\dctcheck.txt")
should result in frame passed unchanged and some data about DCT values before and after quantization written into file dctcheck.txt
DCTCheck(clip, "FYCKTtIAa", Quant=2.5, idct=2, Matrix="c:\custom_matrix.mtx", Output="c:\temp\dct_blocks.txt")
should result in big dct_blocks.txt with tables for all DCT blocks in frame (beware - all blocks for each frame processed, several megabytes of text data per frame) as well as "original" pixel blocks (before quantization) and "output" pixel blocks (close to keyframe at quantizer 2 since idct=2).
---
DCTCheck is slow and written in pure C++ without a single bit of mmx code, and uses only fdct_int32 and idct_int32 from XviD sources.
Delta-frame modes are extremely dumb (no motion compensation) and is only there to provide you with possible examples of data for Inter/Deltaframe.
Frame Quantizer accepts float values, so you can easily scale your matrix as much as you want. Quantizer value is not limited to 31.
----
You should note that DCT process is not loseless by itself, and will introduce rounding errors because precision of DCT result is limited to integer values (and higher precision is required to make this process close to loseless). Different DCT methods may introduce a bit different errors as it was discussed in several threads lately.
In my tests with AviSynth performing DCT and then iDCT without any quantization (idct=1 for DCTCheck) results in 56-64dB PSNR.
There were a lot more tests but i think this post is long enough as it is.
----
Any suggestions are welcome.
But people mentioned there that to create good custom matrix we should look at values entering quantization, and that previewing results for a given quantizer can be helpful too... I've been thinking about that for a while and it looked like rather simple thing to do, at least for keyframes.
Therefore I created AviSynth filter for that purpose.
It can:
- output various data about processed frame into specified text file
and
- process frame in a way close to actual MPEG4 processing (at least i hope so), with frequency data quantized according to specified quantizer and quantization matrix, allowing you to note all artifacts quantization may introduce to picture.
Here it is, available for download, sources included - DCTCheck v0.4.1 (http://web.etel.ru/~shalcker/DCTCheck_v041.zip)
Only accepts YV12 and mod 16 width and height frames.
Posting this to AviSynth board seems pointless since only place where you can use custom quantization matrices is XviD...
Usage is explained in detail within DCTCheck.txt in archive.
----
Few quick examples:
DCTCheck(clip, Quant=2, idct=2, Matrix="c:\custom_matrix.mtx")
should result in output frame close to actual keyframe with quantizer 2 and custom matrix from custom_matrix.mtx (unless custom matrix is specified quantization matrix defaults to all-8). You can use output of the filter to check difference with original frame by using Subtract or ConvertToYUY2() and Compare.
DCTCheck(clip, "FYCKTtMmXxNnEe", Quant=10, Output="c:\temp\dctcheck.txt")
should result in frame passed unchanged and some data about DCT values before and after quantization written into file dctcheck.txt
DCTCheck(clip, "FYCKTtIAa", Quant=2.5, idct=2, Matrix="c:\custom_matrix.mtx", Output="c:\temp\dct_blocks.txt")
should result in big dct_blocks.txt with tables for all DCT blocks in frame (beware - all blocks for each frame processed, several megabytes of text data per frame) as well as "original" pixel blocks (before quantization) and "output" pixel blocks (close to keyframe at quantizer 2 since idct=2).
---
DCTCheck is slow and written in pure C++ without a single bit of mmx code, and uses only fdct_int32 and idct_int32 from XviD sources.
Delta-frame modes are extremely dumb (no motion compensation) and is only there to provide you with possible examples of data for Inter/Deltaframe.
Frame Quantizer accepts float values, so you can easily scale your matrix as much as you want. Quantizer value is not limited to 31.
----
You should note that DCT process is not loseless by itself, and will introduce rounding errors because precision of DCT result is limited to integer values (and higher precision is required to make this process close to loseless). Different DCT methods may introduce a bit different errors as it was discussed in several threads lately.
In my tests with AviSynth performing DCT and then iDCT without any quantization (idct=1 for DCTCheck) results in 56-64dB PSNR.
There were a lot more tests but i think this post is long enough as it is.
----
Any suggestions are welcome.