matlab代码为:
% 计算视频帧间差异度序列d,其中x是qcif yuv420视频的名称
function d = qcif_video_dif(x)
width = 176;
height = 144;
n = width * height;
m = n * 3 / 2;
fid = fopen(x, 'r');
[a, count] = fread(fid, [m, 400], 'uchar');
a = uint8(a); % 节省空间
% 分步存储,节省空间(设视频不超过2400帧)
for i = 1 : 5
[b, count] = fread(fid, [m,400], 'uchar');
b = uint8(b);
a = [a,b];
clear b;
end
fclose(fid);
numfrm = numel(a) / m; % 帧数
for i = 1 : numfrm
y{i} = a(1 : n, i : i);
u{i} = a(n + 1 : n * 5 / 4, i : i);
v{i} = a(n * 5 / 4 + 1 : n * 3 / 2, i : i );
end
for i = 2 : numfrm
d(i) = 4/6 * dif(y{i-1} ,y{i}) + 1/6 * dif(u{i-1}, u{i} ) + 1/6 * dif(v{i-1}, v{i});
end
d(1) = d(2);