Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

video2yuv #1

Open
baidut opened this issue Feb 12, 2016 · 0 comments
Open

video2yuv #1

baidut opened this issue Feb 12, 2016 · 0 comments

Comments

@baidut
Copy link
Member

baidut commented Feb 12, 2016

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant