I want to get a single frame from yuv formate video file
2 ビュー (過去 30 日間)
古いコメントを表示
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));
0 件のコメント
回答 (1 件)
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;
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!