How do I extract the frames from a yuv 420 video? Let's say i want to store them as still images. How?
问问题
9504 次
3 回答
1
这是来自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
于 2010-09-01T02:05:15.760 回答
0
您可以在下面使用此代码:
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 访问每一帧 :)
于 2013-10-06T19:10:58.507 回答
0
抱歉,matlab 帮不上忙,但在命令行上,您可以使用 ffmpeg
ffmpeg -i input.yuv -r 1 -f image2 images%05d.png
-r 1 表示速率 = 每帧
于 2010-09-01T01:40:36.113 回答