View Full Version : Calculate PSNR between two YUV files
miskeen
22nd November 2009, 20:31
Hi guys,
I need a piece of code that enanles me getting the psnr between two YUV files. Can you help me please?
I'm looking for a code that can be executed under linux to open the two yuv files and give the final psnr between the two yuv sequences.
Thank you in advance,
misk
LoRd_MuldeR
22nd November 2009, 20:38
That is extremely simple. You just calculate PSNR = 10 * log_10 (MAX˛ / MSE), where MAX usually is 255 and MSE is the Mean Squared Error.
Calculating the MSE is done with a simple (nested) loop across all pixels and then simply dividing the sum of squared errors through the number of total pixels.
Here "error" is defined as the absolute difference between pixel I(x,y) in the source frame and pixel K(x,y) in the distorted frame. Done :)
http://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio
J_Darnley
22nd November 2009, 21:15
How about tiny_psnr.c from ffmpeg?
miskeen
22nd November 2009, 23:36
Thank you guys for your help.
I've had a look at tiny_psnr.c and it looks interesting. But, how can I use it?
Should I compile only tiny_psnr or I should compile ffmpeg? Can tiny_psnr accept two YUV files as arguments?
Thank you!
LoRd_MuldeR
22nd November 2009, 23:37
I think that part answers your question:
00111 if(argc<3){
00112 printf("tiny_psnr <file1> <file2> [<elem size> [<shift> [<skip bytes>]]]\n");
00113 printf("for wav files use the following:\n");
00114 printf("./tiny_psnr file1.wav file2.wav 2 0 44 to skip the header.\n");
00115 return -1;
00116 }
Also that code has a main() function and doesn't include anything FFmpeg-specific. So it should compile on it's own ;)
miskeen
23rd November 2009, 00:19
tiny_psnr.c can not work alone.
I've downloaded ffmpeg but it's hard to understand. I've not understood how can I call the psnr calculation.
Any help please.
LoRd_MuldeR
23rd November 2009, 00:29
tiny_psnr.c can not work alone.
It does for sure! As said before, it doesn't include anything FFmpeg-specific. Only some standard C header files. And it does have a main() function.
So all you need to do is:
$ gcc -o tiny_psnr.exe tiny_psnr.c
I compiled a Win32 binary for you:
http://www.mediafire.com/file/idmwzi4jb3y/tiny_psnr.exe
miskeen
23rd November 2009, 02:04
YES! YES! YES! It works.
I've tried it under linux and it works. Thank you so much.
Thank you for the win32 compiled version.
BR,
misk
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.