2

伙计们,我想将 avi 文件转换为 yuv 420 视频剪辑。有什么方法可以做到吗?谢谢!

4

2 回答 2

2

您可以使用内置mmreader将 AVI 文件读入 MATLAB 。将 AVI 帧读入电影帧的结构数组后,您可以使用MathWorks File ExchangesaveFileYuv提交中的函数将它们保存为 YUV 文件:

您的代码可能如下所示:

%# Get the video data:

vidObj = mmreader('myVideo.avi');  %# Create a video file object
nFrames = vidObj.NumberOfFrames;   %# Get the number of frames
vidHeight = vidObj.Height;         %# Get the image height
vidWidth = vidObj.Width;           %# Get the image width

%# Preallocate the structure array of movie frames:

mov(1:nFrames) = struct('cdata',zeros(vidHeight,vidWidth,3,'uint8'),...
                        'colormap',[]);  %# Note that colormap is empty!

%# Read each video frame into the structure array:

for k = 1:nFrames
  mov(k).cdata = read(vidObj,k);  %# Place frame k in the cdata field of mov(k)
end

%# Save the movie frame array as a YUV 4:2:0 file:

saveFileYuv(mov,'myVideo.yuv',1);
于 2010-09-01T04:37:17.837 回答
0

我不建议使用 Matlab。使用 mplayer/mencoder 可以轻松完成您想做的事情......为什么要使用 Matlab 呢?

mencoder.exe -of rawvideo clock.avi -o clock.yuv -nosound -ovc raw

如果颜色不正确,您可以添加 -vf swapuv 来交换 U 和 V 组件。

于 2011-05-09T13:22:08.070 回答