Log in

View Full Version : Nifty script for comparing encodings


SleepEXE
9th February 2002, 03:23
I thought I'd share this little AVISynth script for comparing encodings:


LoadPlugin("k:\winnt\system\MPEG2DEC.DLL")

clip1=MPEG2Source("i:\cuckoo.d2v").Crop(24,76,672,326).BilinearResize(544,304).Subtitle("Original")
clip2=AVISource("i:\cuckoo_noluma.avi").Subtitle("No luma mask")
clip3=AVISource("k:\cuckoo_luma.avi").Subtitle("Luma mask")
clip4=Blankclip(clip1)

vertclip1=StackVertical(clip1,clip2)
vertclip2=StackVertical(clip3,clip4)

StackHorizontal(vertclip1,vertclip2)


It's not going to put a fresh coat of paint on your house or even let the dog outside to pee, but it does make a nice 2x2 matrix of the sources of your choice which looks like this (http://orca.st.usm.edu/~jmneal/files/compare_avs.jpg). Maybe advanced AviSynth users use something like this on a regular basis, but I haven't seen it mentioned here so I figured it was worth sharing.

Just plug your source files into the clipX= lines and load it into Virtualdub. Then simply scan through and note differences between the various encodings. To the best of my knowledge, all clips must have the same dimensions and color formats, so just use crop, resize, and convertto... arguments where necessary. If your monitor is running a low resolution (or the clips are large), you may need to use a modest downsize on all clips to make them fit in your viewable area.

In my example, I've used the original DVD2AVI *.d2v for clip1 as a reference, and clips 2 & 3 are Xvid encodings with & without luma masking. Clip4 is a blank placeholder to satisfy the dimensional requirements. The subtitle argument can of course be omitted, but it makes it easy to identify them in VirtualDub as you're scanning through and looking at the differences. If you're a real stickler for the scientific process, get someone else to plug in the clips randomly so you're not influenced by preconceived notions about which one should be better.

Try this with a DivX 3.11, Divx 4.12, and XviD clip and do your own codec comparisons.

Best regards,
SleepEXE

DDogg
9th February 2002, 06:18
Nice post. I really appreciated you putting in the link as "a picture is worth a thousand words"

SleepEXE
9th February 2002, 22:23
Thanks, DDogg.

Something different to chew on...just an expansion of the previous script. A little more modular and will amplify differences between the source and each of the compressed versions:

LoadPlugin("k:\winnt\system\MPEG2DEC.DLL")

clip1 = MPEG2SOURCE("i:\cuckoo.d2v").CROP(24,76,672,326).BILINEARRESIZE(544,304)
clip2 = AVISOURCE("h:\cuckoo_xvid.avi")
clip3 = AVISOURCE("i:\cuckoo_div3.avi")
clip4 = AVISOURCE("k:\cuckoo_div4.avi")
# --- special purpose clips below, for comparison ---
clip5 = SUBTRACT(clip1, clip2).LEVELS(107,1,149,0,255)
clip6 = SUBTRACT(clip1, clip3).LEVELS(107,1,149,0,255)
clip7 = SUBTRACT(clip1, clip4).LEVELS(107,1,149,0,255)

desc_clip1 = "Source"
desc_clip2 = "Xvid"
desc_clip3 = "DivX 3.11"
desc_clip4 = "DivX 4.12"
desc_clip5 = "Difference Source - Xvid"
desc_clip6 = "Difference Source - DivX 3.11"
desc_clip7 = "Difference Source - DivX 4.12"

# The two lines below will usually call clips 1-2-3-4, but 1-5-6-7 may be inserted
# to see [amplified] mathematical difference between clips
# To put it another way, these are the four clips we want to display
vertclip1 = STACKVERTICAL(clip1.SUBTITLE(desc_clip1), clip5.SUBTITLE(desc_clip5))
vertclip2 = STACKVERTICAL(clip6.SUBTITLE(desc_clip6), clip7.SUBTITLE(desc_clip7))

STACKHORIZONTAL(vertclip1,vertclip2)

I admit, using this script is a little harder so I'll try to explain in more detail than the # comments in the script.

To use it:

1. Plug your source (usually a DVD2AVI project) into the clip1= field and use whatever crop and resize values are needed to size it appropriately.
2. Plug your compressed AVI's into clip2=, clip3=, and clip4=. I used XviD, DivX 3.11, and DivX 4.12 clips, respectively. (If you have fewer than 3 compressed clips to compare, use BLANKCLIP(clip1) as placeholders)
3. Use the desc_clipX= fields to give your clips descriptive names which identify them.
4. Load the script into VirtualDub and become enlightened.

Clips 5-7 compare the three compressed versions against the source and amplify the difference so it's easier to see (with SUBTRACT and LEVELS commands). If our compressed versions could perfectly replicate the source, we would see a solid grey block. Instead, we see something like this (http://orca.st.usm.edu/~jmneal/files/compare_avs2.jpg). If you want, you can tweak the first and third arguments to LEVELS (making them equidistant from the value 128) to accentuate or attenuate the difference.

I'm not yet finished with all of the necessary compressed clips, so my example screengrab is fabricated to illustrate the point. But when they're all ready, I'm hoping this script will give me a more objective means to compare them...at least to see which best reproduces the source material.

Best regards,
SleepEXE

diji1
14th February 2002, 05:25
Hi SleepEXE :),

Thanks a 'elluva lot for this very useful script!! :D

trbarry
15th February 2002, 20:02
SleepEXE -

Yeah, this is kinda cool.

Now what we could really use is one more filter that could display the mean squared error bewteen the original and each result.

Know if any such beast exist?

- Tom

SleepEXE
16th February 2002, 01:54
Now what we could really use is one more filter that could display the mean squared error bewteen the original and each result.

Know if any such beast exist?

Haha! You're asking me?...<pans around the room> You sure you don't want to code it this weekend as a brain teaser? ;)

The only project I'm aware of that does something along these lines is FrameAnalyzer which was discussed on Xvid's forums (http://www.videocoding.de/forum/viewtopic.php?topic=145&forum=3). I'm not sure if it is still under development, but the writer appeared to have completed a working PSNR algorithm. The to-do list included some automatic image scaling and other usability features.

Best regards,
SleepEXE