[英]How to extract frames from yuv 420 video clip and store them as different images, using matlab?
How do I extract the frames from a yuv 420 video? 如何从yuv 420视频中提取帧? Let's say i want to store them as still images.
假设我想将它们存储为静止图像。 How?
怎么样?
Here's a submission from the MathWorks File Exchange that should do what you want: 这是MathWorks File Exchange提交的内容,应该可以完成您想要的操作:
The function loadFileYuv
from the above submission will load a YUV file and return an array of movie frames. 上面提交的函数
loadFileYuv
将加载YUV文件并返回电影帧数组。 Each movie frame is a structure with the following fields: 每个电影帧都是具有以下字段的结构:
cdata
: A matrix of uint8
values. cdata
: uint8
值的矩阵。 The dimensions are height-by-width-by-3. colormap
: An N-by-3 matrix of doubles. colormap
:N×3的双精度矩阵。 It is empty on true color systems. You can therefore extract the cdata
field from each movie frame in the array and save/use it as an RGB image. 因此,您可以从数组中的每个影片帧提取
cdata
字段,并将其保存/用作RGB图像。
Your code might look something like this: 您的代码可能看起来像这样:
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
You can use this code below: 您可以在下面使用此代码:
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!
You can access each frame from the matrix mov1 :) 您可以从矩阵mov1中访问每个帧:)
sorry can't help with matlab but on the command line you can do it with ffmpeg 抱歉,matlab帮不上忙,但是在命令行上可以用ffmpeg来做
ffmpeg -i input.yuv -r 1 -f image2 images%05d.png
-r 1 means rate = every frame -r 1表示速率=每帧
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.