Effacer les filtres
Effacer les filtres

I just want the matlab code for converting a video into fewer frames .

1 vue (au cours des 30 derniers jours)
Disha
Disha le 19 Déc 2013
is that possible for someone to help me with the code for converting the video into few number of frames?

Réponses (1)

Walter Roberson
Walter Roberson le 19 Déc 2013
Combining examples from the VideoWriter and VideoReader documentation pages:
%this part is straight from the VideoReader documentation
xyloObj = VideoReader('xylophone.mp4');
nFrames = xyloObj.NumberOfFrames;
vidHeight = xyloObj.Height;
vidWidth = xyloObj.Width;
% Preallocate movie structure.
mov(1:nFrames) = ...
struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),...
'colormap', []);
% Read one frame at a time.
for k = 1 : nFrames
mov(k).cdata = read(xyloObj, k);
end
start making it smaller
%now a change to write in fewer frames:
frame_keep_fraction = 1/3; %for example
discard_frame = rand(1,nFrames) > frame_keep_fraction;
mov(discard_frame) = []; %throw away those frames because we want a smaller video
done making it smaller
%now we can write. Adapting now from the VideoWriter documentation
writerObj = VideoWriter('peaks.avi');
open(writerObj);
writeVideo(writerObj, mov); %we already have all the data so do not need to go frame by frame
close(writerObj);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by