Guys I want to convert an avi file into yuv 420 video clip. Is there any method to do that? thx!
views:
210answers:
1
+1
A:
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);
gnovice
2010-09-01 04:37:17
hi gnovice. I followed your suggestion and call the two functions. I got some problem with the colormap. How do i specify each mov(k).colormap? thx
appi
2010-09-01 12:27:01
@yoursclark: I updated my answer with some sample code. You shouldn't have to specify anything for the `colormap` field (i.e. just make it the empty matrix `[]`) since the frames you will place in the `cdata` field will be RGB (e.g. [truecolor](http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f2-10709.html#f2-12468)) images.
gnovice
2010-09-01 15:12:28
Thank you very much gnovice. your explanation is very clear and helpful!thx!
appi
2010-09-02 05:13:34