Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
avi video compression

Subject: avi video compression

From: amira ali

Date: 27 Sep, 2011 23:36:28

Message: 1 of 2

hello
i want to compree avi video file instead of using 25 frame/sec i want to use only 4 frame/sec how to samples this frames randomely my code but it doesn't work:





vid='a.avi';

aviobj = avifile(vid,'fps',4,'compression','Cinepak');
vidObj = mmreader(vid);
vidFrames = read(readerobj);
numFrames = get(readerobj, 'numberOfFrames');
vid_name= get(readerobj, 'name');

for k = 1 : numFrames
fig=figure;
mov(k).cdata = vidFrames(:,:,:,k);
mov(k).colormap = [];

F = getframe(fig);
aviobj = addframe(aviobj,F);
end
aviobj = close(aviobj);

Subject: avi video compression

From: amira ali

Date: 28 Sep, 2011 01:00:27

Message: 2 of 2

"amira ali" wrote in message <j5tmls$ohe$1@newscl01ah.mathworks.com>...
> hello
> i want to compree avi video file instead of using 25 frame/sec i want to use only 4 frame/sec how to samples this frames randomely my code but it doesn't work:
>
>
>
>
>
> vid='a.avi';
>
> aviobj = avifile(vid,'fps',4,'compression','Cinepak');
> vidObj = mmreader(vid);
> vidFrames = read(readerobj);
> numFrames = get(readerobj, 'numberOfFrames');
> vid_name= get(readerobj, 'name');
>
> for k = 1 : numFrames
> fig=figure;
> mov(k).cdata = vidFrames(:,:,:,k);
> mov(k).colormap = [];
>
> F = getframe(fig);
> aviobj = addframe(aviobj,F);
> end
> aviobj = close(aviobj);
 i found the solution



fpath='C:\Program Files\MATLAB\R2011a\work\video_images\images\test\';
imglist=dir(fullfile(fpath,'*.jpeg'));
%imglist= dir([fpath '*.jpg']); % edit path/filename to match your images' location

% default-parameters:
fps= 10; % frames per second
fname='C:\Program Files\MATLAB\R2011a\work\video_images\images\test\h'; % path/name of movie output file
codec= 'hfyu'; % video codec (FOURCC), I use HuffYUV ('hfyu') because it is lossless

% create movie:
for k= 1:length(imglist);
img= imread([fpath imglist(k).name]); % get current frame
m(k)= im2frame(img);
if rem(k, 100) == 0
disp([num2str(k) ' frames processed...'])
% drawnow
end
end

% create avi:
movie2avi(m, fname, 'compression', 'Cinepak', 'fps', fps,'quality',10);
%movie2avi(m, fname, 'fps', fps);
disp('Playing movie file...');
%implay([fpath 'h.avi']);

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us