How to calculate the PSNR of video sequence?
9 views (last 30 days)
Show older comments
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.
Thanks in advance.
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';
vidObj1 = VideoReader('akiyo_cif_x264.mp4');
vidObj2 = VideoReader('akiyo_cif_x264_Copy.mp4');
EnumFrames=0;
Extframe = cell(1,300) ;
frame = cell(1,300) ;
numFrames1 = 0;
numFrames2 = 0;
while hasFrame(vidObj1)
F1 = readFrame(vidObj1);
numFrames1 = numFrames1 + 1;
frame{numFrames1} = F ;
numFrames1
while hasFrame(vidObj2)
F2 = readFrame(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
0 Comments
Answers (1)
Suraj Kumar
on 8 Jan 2025
Hi Mohd,
The issue you're encountering with infinite PSNR values typically arises when the frames being compared are identical. In such cases, the Mean Squared Error (MSE) is zero, which leads to an infinite PSNR value.
Here are a few suggestions that you can implement in your code:
1.Ensure the frames are being read correctly from both videos. In the provided code, there seems to be an issue with the nested while loop, which might prevent frames from 'vidObj2' from being read properly.
2. Store frames correctly in the frame and 'Extframe arrays'. It looks like you might be overwriting or not correctly storing frames due to incorrect indexing or missing 'readFrame' calls.
3. The loop to read frames from 'vidObj2' should not be nested inside the loop for 'vidObj1'. They can be in separate loops.
To learn more about the 'getframe' function in MATLAB, please refer to the following documentation:
Hope this works for you!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!