0
votes

This work is on the MPEG codec which is supposed to take a YUV file as raw video inout. Following is the code I'm using to convert the YUV file to RGB

fileName = 'bus.y4m';
width = 250;
height = 250;
nrFrame = 10;

fileId = fopen(fileName, 'r');
subSampleMat = [1, 1; 1, 1];
dummy = fgetl(fileId); % Skip file header

%progressbar
for f = 1:nrFrame
    %f

    % Skip frame header
    dummy = fgetl(fileId);
    fprintf('fileID = %i',fileId); 
    % read Y component
    buf = fread(fileId, width * height, 'uchar');
    imgYuv(:, :, 1) = reshape(buf, width, height).'; % reshape

    % read U component
    buf = fread(fileId, width / 2 * height / 2, 'uchar');
    buf = reshape(buf, width / 2, height / 2).';
    imgYuv(:, :, 2) = kron(buf, subSampleMat); % reshape and upsample

    % read V component
    buf = fread(fileId, width / 2 * height / 2, 'uchar');
    buf = reshape(buf, width / 2, height / 2).';
    imgYuv(:, :, 3) = kron(buf, subSampleMat); % reshape and upsample

    % convert YUV to RGB
    imgRgb = reshape(convertYuvToRgb(reshape(imgYuv, height * width, 3)), height, width, 3);
    mov(f) = im2frame(imgRgb);

    progressbar(f/nrFrame)
end
fclose(fileId);

I'm getting the following error

Undefined function 'clipValue' for input arguments of type 'double'.

Error in convertYuvToRgb (line 11)

rgb = uint8(clipValue(rgb, 0, 255));

Error in conv (line 32) imgRgb = reshape(convertYuvToRgb(reshape(imgYuv, height * width, 3)), height, width,3);

Error in run (line 64)

evalin('caller', [script ';']);

What might have gone wrong??

1

1 Answers

1
votes

The problem is: convertYuvToRgb.m depends upon clipValue.m.

I think you have some files missing...

  1. Go to https://www.mathworks.com/matlabcentral/fileexchange/6318-convert-yuv-cif-4-2-0-video-file-to-image-files/content/YUV2Image/convertYuvToRgb.m
  2. Download YUV2Image.zip.
  3. Extract YUV2Image.zip. Make sure you have all extracted files in the same folder.
  4. Download and extract progressbar.zip from https://www.mathworks.com/matlabcentral/fileexchange/6922-progressbar (copy progressbar.m to the same folder as YUV2Image).
  5. Place your source file in the the folder...

I couldn't find bus.y4m, so I tested it with bus_cif.y4m.

enter image description here