views:

110

answers:

2

How do I extract the frames from a yuv 420 video? Let's say i want to store them as still images. How?

A: 

sorry can't help with matlab but on the command line you can do it with ffmpeg

ffmpeg -i input.yuv -r 1 -f image2 images%05d.png

-r 1 means rate = every frame

Martin Beckett
Thx for the help man. My project requirement says I have to stick to matlab. So probably i cannot use ffmpeg. thx anyway
appi
A: 

Here's a submission from the MathWorks File Exchange that should do what you want:

The function loadFileYuv from the above submission will load a YUV file and return an array of movie frames. Each movie frame is a structure with the following fields:

  • cdata: A matrix of uint8 values. The dimensions are height-by-width-by-3.
  • colormap: An N-by-3 matrix of doubles. It is empty on true color systems.

You can therefore extract the cdata field from each movie frame in the array and save/use it as an RGB image.

Your code might look something like this:

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
gnovice
So to do the conversion, first of all, i need to read out each frame in the yuv420 clip and store them in a series of matrix which consists of all the yuv components. Am i right? After that, i need to write those data into bmp or jpg according to their corresponding structure, correct? My job scope is to implement this source code. It would be highly appreciated if you could give me some tips regarding the actual implementation. Thanks!
appi
@yoursclark: If you download the submission I link to, you can look at the code to see how the YUV data is read into a structure array of movie frames. I already explained above how to get the RGB image matrices from the movie frames: you just have to access the `cdata` field of the structure array elements. You can then save each of these RGB images to a file using [IMWRITE](http://www.mathworks.com/access/helpdesk/help/techdoc/ref/imwrite.html).
gnovice
Thx gnovice. I'm working on it :D
appi
This works! Thanks gnovice!
appi