I just want the matlab code for converting a video into fewer frames .
1 回表示 (過去 30 日間)
古いコメントを表示
is that possible for someone to help me with the code for converting the video into few number of frames?
0 件のコメント
回答 (1 件)
Walter Roberson
2013 年 12 月 19 日
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);
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!