簡體   English   中英

如何使用Matlab從yuv 420視頻剪輯中提取幀並將其存儲為不同的圖像?

[英]How to extract frames from yuv 420 video clip and store them as different images, using matlab?

如何從yuv 420視頻中提取幀? 假設我想將它們存儲為靜止圖像。 怎么樣?

這是MathWorks File Exchange提交的內容,應該可以完成您想要的操作:

上面提交的函數loadFileYuv將加載YUV文件並返回電影幀數組。 每個電影幀都是具有以下字段的結構:

  • cdatauint8值的矩陣。 尺寸為高×寬×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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM