Log in

View Full Version : PSNR using Compare()


Appu
27th January 2007, 10:20
I was trying to compare the PSNR between three codecs ( Vp7, XVID and H.264). One scripts is shown below

The original input source contain 165 frames.

xvid_clip = AviSource("D:\streams\YUV\seq_720x576_xvid1.avi")
xvid_clip1 = ConvertToYUY2(xvid_clip).trim(1,0)
org_clip = AviSource("D:\streams\YUV\seq_720x576_yuv.avi")
org_clip1 = ConvertToYUY2(org_clip)

Compare(xvid_clip1, org_clip1, "YUV", "a.log", true)

1) trim is really needed here?. With out trim PSNR seems to riduculously low. How do I ensure that I am comparing right frames? With trim the no frames which are used for PSNR comparison is reduced by one ( 164 ). Also I didn't use trim for same script used for the Vp7 codec comparison and the PSNR seems to be OK.

2) What is the use of the last argument ( show_graph ) of the compare function?


3) I assume xvid_clip1 is in display order. Correct?

Any help/suggestions for PSNR measurements are highly appreciated..

Manao
27th January 2007, 10:51
1) Use interleave(clip1, clip2) to visually check that clips are synchronized. Depending on the codec, the presence of bframes, the presence of packet bitstream or not, avisource may sometimes add some useless frames at the beginning of the compressed video.

2) put over the video a graph showing the PSNR of the last visualized frames.

3) yep

Appu
27th January 2007, 11:25
Just tried Interleave(clip1, clip2). The clips seems to be synchronized. Each frame repeated twice after the interleave. This says that trim is not needed in the script. Right?. But with out trim PSNR seems to quite low. Confused!

The first frame of the XVID stream when opened with Virtualdub is black initially. But if I play few frames and start from beginning the first frame seems to be OK!.

I couldn't get the video graph of the PSNR working yet. Any hints?

Alain2
27th January 2007, 11:31
Use Interleave(clip1.subtitle("1"), clip2.subtitle("2")) for instance to be sure that it's definitely the frame of clip 1 that comes first, and then the same from clip 2

Manao
27th January 2007, 12:00
Appu : never seek when you want to compare psnr or check synchronicity of videos. The behavior of avisource with bframes/packed bitstream is not well defined when you do so. The best you can do is :
- use interleave(clip1, clip2), open the avs in vdub, only use the right arrow key ( never the left, nor the seek bar ), and check that even and odd frames are the same ( i.e 10 and 11 must be the same, but 11 and 12 may be different - beware, vdub indexes frames from 0, not 1 ).
- close the avs file, replace the interleave by compare, reopen the avs file, hit the 'play' button, disable the video preview ( in order to go faster ), wait until the video is entirely played, then close the avs file. It's the only wait ot be sure the txt file created by compare will be correct.

As you can see, it's not very convenient. I prefer using vdub for checking synchronization, then avs2avi when a 'null' codec to parse the avs. You may also want to try tools that compute PSNR/SSIM/whatever without using avisynth, it's less cumbersome.

Appu
27th January 2007, 13:28
Appu : never seek when you want to compare psnr or check synchronicity of videos. The behavior of avisource with bframes/packed bitstream is not well defined when you do so. The best you can do is :

OK.. This answers why the XVID stream starts with different frame after seeking.

Infact the after encoding the XVID avi stream starts with a black frame, eventhough the original doesn't start with a black. Don't know why!.. Hence trim is needed for PSNR. After trim both clips are in sync (10 and 11 same but 11 and 12 are different). Thanks for the tip!.. Will try some other tools also.

Still I don't know how to make use the last option ( show_graph )of the compare.

Do you know how the PSNR is computed by the AviSynth?. I am looking for the exact equation.


Alain2:

The clips doesn't have any subtitles.

Manao
27th January 2007, 14:32
In Alain2's example, Subtitle() is used to print "1" on the first clip, and "2" on the second.

eventhough the original doesn't start with a black. Don't know why!A little search on XviD's forum will help. It has to do with how the vfw interface is designed ( vfw is the framework used to read/write avi file ), and with bframes ( which the vfw interface doesn't handle well ).
Do you know how the PSNR is computed by the AviSynth?. I am looking for the exact equation.It's 10 x log10( 255*255 / MSE ), where MSE is the mean square error, ie the sum of the square of the difference between encoded pixels and original pixels. Overall PSNR is the PSNR when you consider the MSE of the whole movie, average PSNR is the average of the PSNR of each frame, taken independently.
Still I don't know how to make use the last option ( show_graph )of the compareSynchronize two clips with trim, then use compare(show_graph=true), load the file into virtual dub, and play it. You'll see a graph of the psnr per frame drawn over the video.