开发者

how to convert avi file to yuv 420 (software/matlab/source code/c/c++ anything)

Guys I want to convert an avi file into yuv 420 vid开发者_StackOverflow社区eo clip. Is there any method to do that? thx!


You can read an AVI file into MATLAB using the built-in mmreader class. Once you have the AVI frames read into a structure array of movie frames, you can save them as a YUV file using the saveFileYuv function found in this submission from the MathWorks File Exchange:

  • Convert YUV CIF 4:2:0 video file to image files by Da Yu

Your code might look something like this:

%# 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);


I don't recommend using Matlab. What you want to do can easily be done using mplayer/mencoder... Why use Matlab for that ?

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

You may add -vf swapuv to swap the U and V components if the colrs aren't correct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜