필터 지우기
필터 지우기

Video compression code working - Please explain the code

조회 수: 24 (최근 30일)
naveen V
naveen V 2014년 5월 5일
댓글: Walter Roberson 2022년 11월 26일
ImFolder=uigetdir;
pngFile = dir(strcat(ImFolder,'\*.png'));
S = [pngFile(:).datenum];
[~,S] = sort(S);
pngFiles = pngFile(S);
VideoFile=strcat(ImFolder,'\Video');
writeObj = VideoWriter(VideoFile);
fps= 15;
writeObj.FrameRate = fps;
open(writeObj);
for t= 1:length(pngFiles)
Frame=imread(strcat(ImFolder,'\',pngFiles(t).name));
writeVideo(writeObj,im2frame(Frame));
end
close(writerObj);
Above is the code i have used to compress the video,
Execution Steps:
1) Initially i recorded a video of 10seconds(Resolution - 160*120) size of video 8mb
2) I extracted all the frames from the video and saved in a folder
3) In this step i used above code
After executing above code i selected the directory where all the frames had been stored
4) After execution i got a video file of size 550Kb and of the same length as the original video
So original video is reduced to 550kb from 8mb, code is working good for my project, please help me the analyze the above code, how actually the compression is done by the code.
Thank You
  댓글 수: 11
ei
ei 2022년 11월 26일
hi please i want to video compression code
Walter Roberson
Walter Roberson 2022년 11월 26일
For video compression,
writeObj = VideoWriter(VideoFile, 'MPEG-4');
now writeVideo the frames.

댓글을 달려면 로그인하십시오.

답변 (3개)

Walter Roberson
Walter Roberson 2014년 5월 5일
writerObj = VideoWriter(filename) constructs a VideoWriter object to write video data to an AVI file with Motion JPEG compression.
So it is going to use Motion JPEG in an AVI container.

kushagra parashar
kushagra parashar 2016년 7월 24일
??? Undefined function or method 'VideoWriter' for input arguments of type 'char'.
Error in ==> Untitled at 7 writeObj=VideoWriter(VideoFile);
i am getting this error...what should i do
  댓글 수: 1
Walter Roberson
Walter Roberson 2016년 7월 24일
VideoWriter was introduced in R2010b. Which MATLAB release are you using?

댓글을 달려면 로그인하십시오.


chandra sekhar uppu
chandra sekhar uppu 2017년 3월 27일
편집: Walter Roberson 2017년 3월 27일
my video after expansion its size increases from 3 mb to 56 mb and its length increases from 1 min to 2 min the video has slow down.. i have used code
vid=VideoReader('w.mp4');
no=vid.NumberOfFrames;
for i=1:1:no
frames=read(vid,i);
base=sprintf('Image%d.png',i);
ful=fullfile(pwd,base);
imwrite(frames,ful);
im(i)=image(frames);
end
after i got frames i saved in a folder and apply this codee.. but i got 2 min and size of 50 mb
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 3월 27일
Notice that the code posted in the Question has
fps= 15;
writeObj.FrameRate = fps;
You should adjust that 15 to the rate you need.
With regards to the size: if you are creating a .mp4 output file then you should consider
writeObj = VideoWriter(VideoFile, 'MPEG-4');
Sliver Gaming
Sliver Gaming 2021년 10월 4일
How do i code it :/

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by