Question

Guys I want to convert an avi file into yuv 420 video clip. Is there any method to do that? thx!

Was it helpful?

Solution

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:

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top