-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveFileYuv.m
More file actions
36 lines (27 loc) · 914 Bytes
/
saveFileYuv.m
File metadata and controls
36 lines (27 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function saveFileYuv(mov, fileName, mode)
% save RGB movie [0, 255] to YUV 4:2:0 file
switch mode
case 1 % replace file
fileId = fopen(fileName, 'w');
case 2 % append to file
fileId = fopen(fileName, 'a');
otherwise
fileId = fopen(fileName, 'w');
end
dim = size(mov(1).cdata);
nrFrame = length(mov);
for f = 1 : 1 : nrFrame
imgRgb = frame2im(mov(f));
% convert YUV to RGB
imgYuv = reshape(convertRgbToYuv(reshape(imgRgb, dim(1) * dim(2), 3)), dim(1), dim(2), 3);
% write Y component
buf = reshape(imgYuv(:, :, 1).', [], 1); % reshape
count = fwrite(fileId, buf, 'uchar');
% write U component
buf = reshape(imgYuv(1 : 2 : end, 1 : 2 : end, 2).', [], 1); % downsample and reshape
count = fwrite(fileId, buf, 'uchar');
% write V component
buf = reshape(imgYuv(1 : 2 : end, 1 : 2 : end, 3).', [], 1); % downsample and reshape
count = fwrite(fileId, buf, 'uchar');
end
fclose(fileId);