Currently,i'm focus on how to use psnr&ssim metrics to evaluate the video encode quality of libx264 and hw h264 encoders.

And i find that libx264 encoder has the option to log stuff psnr&ssim values.

When i use the following command,i can get the psnr when encode finish.

eg:ffmpeg -y -video_size 1920*1080 -pix_fmt yuv420p -r 25 -i ./Tennis_1920x1080_24.yuv -c:v libx264 -preset faster -tune psnr -vb 1000k -g 90 -s 1920*1080 -an libx264_out_1000k.h264 -psnr

[libx264 @ 0x4840c20] PSNR Mean Y:32.345 U:39.530 V:39.383 Avg:33.687 Global:33.326 kb/s:943.62

But sometimes the hardware encoder do not have the encode log,which should user the 3rd part tools to calculate the psnr quality.And i also find that when i use the ffmpeg psnr filter to caculate the psnr value,and i could not able the get the same score as the above result shows,even the encode frame is aligned.

ffmpeg -video_size 1920*1080 -pix_fmt yuv420p -r 25 -i ./Tennis_1920x1080_24.yuv -r 25 -i libx264_out_1000k.h264 -lavfi psnr=stats_file=libx264_out_1000k.h264.log -f null - 2>&1 | tee libx264_out_1000k.h264.ffmpeg_psnr.txt

[Parsed_psnr_0 @ 0x33b41e0] PSNR y:32.067442 u:39.500521 v:39.372329 average:33.447532 min:31.125177 max:37.774371

My question is that if we use the libx264 psnr value from its log ouput,and use the ffmpeg psnr filter to calculate the hw encode result,the different test tools will cause the different result.

During the video quality test,we should align the test tools.

So could anyone share some advise to me?And where can i get the psnr&ssim tools which could get the same test result as the libx264 log output?

Thanks in advance.

  • PSNR is asymmetric and the reference has to be the 2nd input to the filter, but your order is reversed. Change -lavfi psnr= to -lavfi [1][0]psnr=. – Gyan Jun 3 '19 at 5:38
  • @Gyan Would it really make a difference? MSE doesn't care on which side the reference is. The output between both runs differs only by 0.12 dB … not a lot. Could it be a rounding issue? – slhck Jun 3 '19 at 6:56
  • Depending on the first input, lavfi may negotiate a different pixel format conversion, which can introduce a difference. – Gyan Jun 3 '19 at 7:18
  • @Gyan It doesn't make a difference.The test results are the same.Thanks. – simon_sun Jun 3 '19 at 7:24
  • @slhck The Y component differ between the above two results could cause bad effect to BD-rate.The U and V component have slightly effect. – simon_sun Jun 3 '19 at 7:30

x264 calculate psnr of each frame and finally calculate the average psnr (psnr1 + psnr2 + ... psnrN) / frame_num, ffmpeg calculate mse of each frame and sum mse of all frames, then calculate the whole psnr for the sequence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.