繁体   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