# How to calculate the PSNR of video sequence?

35 views (last 30 days)
Mohd Shaliyar on 11 Oct 2022
Hi there,
I want to calculate the PSNR value between two videos. One video is original and another one is watermarked video. The watermarked video has some watermarked frame. I have calculated PSNR of each frame one at a time of both of the videos, and calsulate the average of it, but unfortunately I get the "Inf" value of PSNR.
Again, I have also tried to calculate the PSNR of exactly two videos. As a result, I got the PSNR of 40 dB. In fact, the result must be 99.99
Any help must be appreciated.
The code I have written to calculate the PSNR of two idential videos
clc;
output_folder = 'D:\Matlab book and files\SLT\Akiyo_frames_journal';
EnumFrames=0;
Extframe = cell(1,300) ;
frame = cell(1,300) ;
numFrames1 = 0;
numFrames2 = 0;
while hasFrame(vidObj1)
numFrames1 = numFrames1 + 1;
frame{numFrames1} = F ;
numFrames1
while hasFrame(vidObj2)
numFrames2 = numFrames2 + 1;
Extframe{numFrames2}=F2;
end
numFrames2
for i= 1:300
Extframe{i}= getframe;
frame{i}= getframe;
fprintf ("The PSNR of frame %d = %.2f \n", i , psnr(frame2im(Extframe{i}),frame2im(frame{i})))
end
OUTPUT
The PSNR of frame 1 = Inf
The PSNR of frame 2 = Inf
The PSNR of frame 3 = Inf
The PSNR of frame 4 = Inf
The PSNR of frame 5 = Inf
The PSNR of frame 6 = Inf
The PSNR of frame 7 = Inf
The PSNR of frame 8 = Inf
The PSNR of frame 9 = Inf
The PSNR of frame 10 = Inf
............................................
.............................................
............................................
The PSNR of frame 300 = Inf