如何从YUV 420视频中提取框架?假设我想将它们存储为静止图像。如何?

有帮助吗?

解决方案

这是来自 Mathworks文件交换 那应该做你想做的事情:

功能 loadFileYuv 从上面的提交中,将加载YUV文件并返回一系列电影帧。每个电影框架都是一个具有以下字段的结构:

  • cdata: :一个矩阵 uint8 值。尺寸是逐宽的尺寸。
  • colormap: :n-by-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

其他提示

对不起

ffmpeg -i input.yuv -r 1 -f image2 images%05d.png

-r 1表示费率=每个帧

您可以在下面使用此代码:

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访问每个帧:)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top