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

StackOverflow https://stackoverflow.com/questions/3615036

  •  26-09-2019
  •  | 
  •  

문제

Guys I want to convert an avi file into yuv 420 video 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:

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.

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