登录论坛

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


poster
2019-12-10, 20:48
如何从yuv 420视频中提取帧?假设我想将它们存储为静止图像。怎么样?



回答:

这是MathWorks File Exchange (http://www.mathworks.com/matlabcentral/fileexchange/)提交的内容,应该可以完成您想要的操作:


通过Da Yu (http://www.mathworks.com/matlabcentral/fileexchange/authors/16240) 将YUV CIF 4:2:0视频文件转换为图像文件 (http://www.mathworks.com/matlabcentral/fileexchange/6318-convert-yuv-cif-420-video-file-to-image-files)
上面提交的函数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

更多&回答... (https://stackoverflow.com/questions/3614441)