简体   繁体   English

如何使用Matlab从yuv 420视频剪辑中提取帧并将其存储为不同的图像?

[英]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. cdatauint8值的矩阵。 The dimensions are height-by-width-by-3. 尺寸为高×宽×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.

相关问题 如何使用Matlab从视频中以特定间隔提取帧 - How to extract frames at particular intervals from video using matlab 如何使用MATLAB从视频中提取所有帧,以及如何通过任何标准方法提取关键帧? - How to extract all the frames from a video using MATLAB and do key frame extraction by any standard method? 如何从Matlab mlarray提取图像并显示它们 - How can I extract images from a Matlab mlarray and display them 如何在Matlab下获取给定YUV视频剪辑的高度和宽度? 是否有任何reader()函数或get()函数? 还要别的吗? - How do I obtain the height and width of a given YUV video clip under Matlab? Is there any reader() function or get() function? Anything else? 如何读取多个图像并将它们存储在 MATLAB 中? - How to read multiple images and store them on MATLAB? 如何使用Matlab并行分析视频帧? - How to analyse video frames in parallel using Matlab? 如何从MATLAB中的视频中选择特定的帧? - how to select specific frames from a video in MATLAB? 如何使用Matlab从给定的yuv文件中提取Y,U和V分量? 每个组件用于进一步的像素级操纵 - How to extract Y,U, and V components from a given yuv file using Matlab? Each component is used for further pixels level manipulation Matlab中的YUV视频处理 - YUV video processing in Matlab 使用Matlab mmreader提取帧 - Extract frames using Matlab mmreader
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM