0

I'm streaming H.264(libx264) videos using RTP. I would like to compare the different error resiliency methods in h.264. In some research papers, psnr was used to compare them. So I would like to know how to calculate the psnr of the h.264 video during streaming.

1 Answer 1

1

To calculate PSNR, you must compare two frames, so first step is to make sure you have a copy of the source video. Next, you must be able to match the frames 1:1. so if a frame is droped, you need to compare the source frame to the previous streamed frame. This may be difficult if the timestamps do not match (They may be modified by the RTP server). Next decode each frame into its YUV channels. the PSNR of the channels needs to be calculated independently. You can average the three PSNR values at the end, but this puts too much weight on the U,V channels. I recommend just using the Y channel, as it is most important. And since you are measuring packet loss, the values will be strongly correlated anyway.

Next calculate your mean squared error like so:

int64_t mse = 0;
for(int x = 0 ; x < frame.width  ; ++x ) {
for(int y = 0 ; y < frame.height ; ++y ) {
    mse += pow( source_frame[x][y] - streamed_frame[x][y], 2 );
}}
mse *= 1.0/(frame.width*frame.height);

And finally:

/* use 219 instead of 255 if you know your colorspace is BT.709 */
double psnr = 20 * log10( 255 ) - 10 * log10( mse );

You can average the per frame PSNRs together to get a full stream PSNR.

2
  • some frames doesn't carry noise or very negligible noise(mse is very small). So to calculate average psnr , do we need to include those frames's psnr also?
    – K07
    Commented Jan 7, 2014 at 11:38
  • I don't know your setup, but it depends on what you are trying to measure. One 'error resiliency method' may do better on individual frames by degrading the stream over all, or vice versa. Do you want to know the per frame error, or the error over time?
    – szatmary
    Commented Jan 7, 2014 at 18:54

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