[英]How to extract frames from yuv 420 video clip and store them as different images, using matlab?
如何從yuv 420視頻中提取幀? 假設我想將它們存儲為靜止圖像。 怎么樣?
這是MathWorks File Exchange提交的內容,應該可以完成您想要的操作:
上面提交的函數loadFileYuv
將加載YUV文件並返回電影幀數組。 每個電影幀都是具有以下字段的結構:
cdata
: uint8
值的矩陣。 尺寸為高×寬×3。 colormap
:N×3的雙精度矩陣。 在真彩色系統上為空。 因此,您可以從數組中的每個影片幀提取cdata
字段,並將其保存/用作RGB圖像。
您的代碼可能看起來像這樣:
nFrames = 115; %# The number of frames
vidHeight = 352; %# The image height
vidWidth = 240; %# The image width
mov = loadFileYuv('myVideo.yuv',vidHeight,vidWidth,1:nFrames); %# Read the file
for k = 1:nFrames %# Loop over the movie frames
imwrite(mov(k).cdata,['myImage' int2str(k) '.bmp']); %# Save each frame to
%# a bitmap image file
end
您可以在下面使用此代碼:
vidObj1 = mmreader('testballroom_0.avi'); %# Create a video file object
nFrames = vidObj1.NumberOfFrames; %# Get the number of frames
vidHeight1 = vidObj1.Height; %# Get the image height
vidWidth1 = vidObj1.Width; %# Get the image width
%# Preallocate the structure array of movie frames:
mov1(1:nFrames) = struct('cdata',zeros(vidHeight1,vidWidth1,3,'uint8'),...
'colormap',[]); %# Note that colormap is empty!
您可以從矩陣mov1中訪問每個幀:)
抱歉,matlab幫不上忙,但是在命令行上可以用ffmpeg來做
ffmpeg -i input.yuv -r 1 -f image2 images%05d.png
-r 1表示速率=每幀
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.