문제

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

도움이 되었습니까?

해결책

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

다른 팁

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

You can use this code below:

vidObj1 = mmreader('testballroom_0.avi');  %# Create a video file object
nFrames = vidObj1.NumberOfFrames;   %# Get the number of frames
vidHeight1 = vidObj1.Height;         %# Get the image height
vidWidth1 = vidObj1.Width;           %# Get the image width

%# Preallocate the structure array of movie frames:

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

You can access each frame from the matrix mov1 :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top