I want to get a single frame from yuv formate video file

2 ビュー (過去 30 日間)
Sahar Akhtar
Sahar Akhtar 2022 年 5 月 19 日
回答済み: Naga 2024 年 11 月 26 日
clear;
vlc='balloons_c_1_1024x768-.yuv';
vld='balloons_d_1_1024x768.yuv';
vrc='balloons_c_5_1024x768.yuv';
vrd='balloons_d_5_1024x768.yuv';
function[y,u,v]=Test2(vid,width,height,nframe)
%r(:,nframe)=y(:,:,nframe)+1.140*v(:,:,nframe);
%g(:,nframe)=y(:,:,nframe)-0.395*u(:,:,nframe)-0.581*v(:,:,nframe);
%b(:,nframe)=y(:,:,nframe)+2.032*u(:,:,nframe);
fid=fopen(vid,'r');
stream=fread(fid,'*uchar');
frame_length=1.5*width*height;
y=uint8(zeros(height,width,nframe));
u=uint8(zeros(height/2,width/2,nframe));
v=uint8(zeros(height/2,width/2,nframe));
for iframe=1:nframe
frame=stream((iframe-1)*frame_length+1:iframe*frame_length);
yImage = reshape(frame(1:width*height), width, height)';
uImage = reshape(frame(width*height+1:1.25*width*height), width/2, height/2)';
vImage = reshape(frame(1.25*width*height+1:1.5*width*height), width/2, height/2)';
y(:,:,nframe)=yImage;
u(:,:,nframe)=uImage;
v(:,:,nframe)=vImage;
end
%....................................................
height=768;
width=1024;
nframe=500;
[Y,U,V]=Test2(vlc,width,height,nframe);
imshow(Y(:,:,125));

回答 (1 件)

Naga
Naga 2024 年 11 月 26 日
Hi Sahar,
The code incorrectly assigns the Y, U, and V components to the same index nframe, causing all frames to overwrite each other. This results in only the last frame being stored, losing all previous frames.
Assign the components to iframe instead of nframe to ensure each frame is stored uniquely:
% Correct frame indexing
y(:,:,iframe) = currentYComponent;
u(:,:,iframe) = currentUComponent;
v(:,:,iframe) = currentVComponent;

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by