-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyuyv_to_yuv.m
43 lines (37 loc) · 1.19 KB
/
yuyv_to_yuv.m
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
36
37
38
39
40
41
42
43
function [ y, u, v ] = yuyv_to_yuv( filename, interleave )
%YUYV_TO_YUV Summary of this function goes here
% Detailed explanation goes here
% Read raw sensor data
fp = fopen(filename, 'rb');
A = fread(fp, '*uint8');
fclose(fp);
if interleave == 0
% Decode and reinterleave pixels into planes (more standard)
% Can be viewed with "ffplay -i <outfile> -s 1280x1024"
%result = reshape(A(1:2:end), 1280, []); % Brightness component
y = A(1:2:end); numel(y) % Debug watch: image(reshape(y, 1280, []))
u = A(2:4:end); numel(u)
v = A(4:4:end); numel(v)
% Write planes
fp = fopen(strcat(filename, '.yuv'), 'wb');
fwrite(fp, y, '*uint8');
fwrite(fp, u, '*uint8');
fwrite(fp, v, '*uint8');
fclose(fp);
elseif interleave == 1
stripes = reshape(A, 4, []); % YUYV columns
A = stripes([1,3,2,4], :); % Convert into YYUV
fp = fopen(strcat(filename, '.yuv'), 'wb');
fwrite(fp, reshape(A, 1, []), '*uint8');
fclose(fp);
elseif interleave == 2
% NV12 format
y = A(1:2:end);
uv = A(2:2:end);
% Write planes
fp = fopen(strcat(filename, '.yuv'), 'wb');
fwrite(fp, y, '*uint8');
fwrite(fp, uv, '*uint8');
fclose(fp);
end
end