Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Not sure whether I have some fundamental misunderstanding about YUV files, but if you edit the function like I did below, you have the YUV components for every frame in a single variable called <code>imgYUV</code>. Note that you may run out of memory in the process, you maybe you don't want to load all the frames of the movie in one go.</p> <pre><code>function imgYUV = loadFileYuv(fileName, width, height, idxFrame) % load YUV data from YUV 4:2:0 file fileId = fopen(fileName, 'r'); subSampleMat = [1, 1; 1, 1]; nrFrame = length(idxFrame); %# preassign imgYUV. In case we can't keep everything in RAM, %# it is better that the function crashes here, rather than after %# having wasted time slowly filling up the memory. %# Since the images are likely to be of class 'uint8', %# you can save on a lot of memory by initializing %# imgYUV as zeros(width/2,height/2,3,nrFrame,'uint8'); imgYUV = zeros(width/2 height/2, 3, nrFrame); for f = 1 : 1 : nrFrame %# search fileId position sizeFrame = 1.5 * width * height; fseek(fileId, (idxFrame(f) - 1) * sizeFrame, 'bof'); %# read Y component buf = fread(fileId, width * height, 'uchar'); imgYuv(:, :, 1, f) = reshape(buf, width, height).'; %# read U component buf = fread(fileId, width / 2 * height / 2, 'uchar'); imgYuv(:, :, 2, f) = kron(reshape(buf, width / 2, height / 2).', subSampleMat); % reshape and upsample % read V component buf = fread(fileId, width / 2 * height / 2, 'uchar'); imgYuv(:, :, 3, f) = kron(reshape(buf, width / 2, height / 2).', subSampleMat); % reshape and upsample end fclose(fileId); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload