error while writing a video
2 views (last 30 days)
Show older comments
I have a seven second video,i converted to frames and used imwrite to save all files in a folder and then i tried to convert frames to video,finally wen using videowriter my video was only 3 sec,plz tell why i get like this
[Merged from duplicate]
i have a code in which the frames per second changes and also the duration of video
clc
clear all
vidObj = VideoReader('foreman.avi');
Frames=vidObj;
numFrames = vidObj.NumberOfFrames;
pickind='bmp';
f1=fullfile('E:','rr1ames');
if (exist(f1) == 0)
mkdir (f1);
end
for k = 1:numFrames
a=read( Frames,k);
strtemp=strcat('E:\rr1ames\',int2str(k),'.',pickind);
imwrite(a,strtemp);
end
path ='E:\rr1ames\' ;
files = dir( [path '*.bmp'] );
pickind='bmp';
pickind='bmp';
writerObj = VideoWriter('rnewd2.avi');
open(writerObj)
for k = 1:numFrames
image = ((imread(fullfile(path,files(k).name))));
writeVideo(writerObj,image);
end
close(writerObj);
vidObj = VideoReader('rnewd2.avi');
the result i get for foreman is
Video Parameters: 14.99 frames per second, RGB24 176x144.
Duration-10.01
for rnewd2.avi is
Video Parameters: 30 frames per second, RGB24 176x144.
Duration-5
plz help
0 Comments
Answers (2)
Jan
on 11 Apr 2013
Edited: Jan
on 11 Apr 2013
Without seeing the code, it is impossible to guess, what you are doing exactly. Perhaps there is a bug, which ignores the last 4 seconds, or the first 4 seconds, or some frames in certain intervals, or the frame rate has been set incorrectly. There could be a bunch of problems, which can be found by using the debugger easily, but guessing them is a hard work.
kash, you have asked hundreds of questions now. You have been instructed many times to read your questions again and estimate, if they contain enough information to be answered efficiently or if an answer is possible at all. I cannot see any reason to ignore such recommendations.
3 Comments
Jan
on 12 Apr 2013
- Omit the clear all. It prevents the debugging by removing all breakpoints, and this is a really bad idea.
- exist(f1) is dangerous, because it checks for files, folders, variables java classes etc. Use exist(f1, 'file') instead.
Image Analyst
on 12 Apr 2013
I know it says "clear removes debugging breakpoints in MATLAB files." in the help but it's not entirely true, as a simple test will show. Make a script with clear or clear all at the top, set a breakpoint further down, and run it. It will stop at the breakpoint. If you do clear all from the command line, it will remove breakpoints in the script, but not if the clear is in the script itself. Just wanted to clarify.
Walter Roberson
on 12 Apr 2013
Where do you configure your frame-rate for your VideoWriter object?
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!