Skip to content

video2yuv #1

Description

@baidut

Author: @baidut
Brief: convert video file to .yuv

  1. 将摄像头采集到的数据存成YUV文件
    • 帧率:15fps
    • 尺寸:320x240
    • 色度格式:4:2:0
  2. 用yuvviewer观察正确性
inFile = 'test.mp4';
outFile = 'output.yuv';
vidObj = VideoReader(inFile);
fid = fopen(outFile,'wb');
hold on;
while hasFrame(vidObj)
    vidFrame = readFrame(vidObj);

  R = double(vidFrame(:,:,1));
    G = double(vidFrame(:,:,2));
    B = double(vidFrame(:,:,3));

  D = [.299  .587  .144;
    -.147 -.289  .436;
     .615 -.515 -.1];
  C = [0; 128; 128];

    Y = D(1,1) * R + D(1,2) * G + D(1,3) * B + C(1);
    U = D(2,1) * R + D(2,2) * G + D(2,3) * B + C(2);
    V = D(3,1) * R + D(3,2) * G + D(3,3) * B + C(3);

    Y4 = uint8(round(Y));
    U4 = uint8(round(U));
    V4 = uint8(round(V));

    U1 = U4(1:2:end,1:2:end);
    V1 = V4(1:2:end,1:2:end);

    fwrite(fid,Y4','uint8');
    fwrite(fid,U1','uint8');
    fwrite(fid,V1','uint8');
end
fclose(fid);

参考资料

  1. MathWorks-Image Format Conversion: RGB to YUV
  2. 用Matlab读写YUV文件(备忘)
  3. ilovematlab-求教Matlab图像RGB转YUV

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions