can't play video file
Show older comments
I can't get the final video to play. It has a size of 1x1 when it should be 401x401.
I'm using R2014a
dir = '/Users/douglasbrenner/Documents/Rosen/AOSLO_MA_AVIs/';
base_name = 'media';
nimages = 11;
size = 31; %size of subimage around alignment point must be odd.
size_from_center = (size - 1)/2;
for i = 3:3%nimages
avi = [dir,base_name,int2str(i),'.avi'];
disp('Converting')
disp(avi)
a = VideoReader(avi)
v = VideoWriter('aligned.avi','Uncompressed AVI');
open(v);
n_frames = a.NumberOfFrames
figure(1);
frame = read(a,1);
imshow(frame);
[Xc(1),Yc(1)] = getpts(1);
subframe = frame(int16(Yc(1)) - size_from_center:int16(Yc(1))+size_from_center,int16(Xc(1))-size_from_center:int16(Xc(1))+size_from_center);
center = centroid(subframe,size);
yc1 = Yc(1);
xc1 = Xc(1);
Xc(1) = center(2) - size_from_center;
Yc(1) = center(1) - size_from_center;
J = imtranslate(frame,[Xc(1),Yc(1)],'cubic');
writeVideo(v,uint8(J(a.Height)))
for j = 2:5%n_frames
j
frame = read(a,j);
subframe = frame(int16(yc1) - size_from_center:int16(yc1)+size_from_center,int16(xc1)-size_from_center:int16(xc1)+size_from_center);
center = centroid(subframe,size);
Xc(j) = center(2) - size_from_center;
Yc(j) = center(1) - size_from_center;
J = imtranslate(frame,[Xc(j),Yc(j)],'cubic');
writeVideo(v,uint8(J(a.Height)))
end
%
Mx = mean(Xc)
Sx = std(Xc)
My = mean(Yc)
Sy = std(Yc)
end
close(v);
avi = 'aligned.avi';
a = VideoReader(avi);
implay(a);
thanks
Accepted Answer
More Answers (3)
Walter Roberson
on 4 Aug 2016
0 votes
You create your VideoWriter within the for i loop but you do not close it until after the for i loop. That would mess up your output.
2 Comments
Walter Roberson
on 4 Aug 2016
In your line
writeVideo(v,uint8(J(a.Height)))
a.Height is going to be a single scalar, so you are accessing your frame data at a single location, converting the resulting scalar to a uint8 and writing out that scalar.
Douglas
on 4 Aug 2016
Douglas
on 4 Aug 2016
0 votes
3 Comments
Walter Roberson
on 4 Aug 2016
a.Height and a.Width are scalars. J(a.Height, a.Width) is going to give you a scalar output.
Possibly you want
writeVideo(v,uint8( J(1:a.Height, 1:a.Width)))
A question: is your input RGB or is it indexed or is it grayscale ? Your code treats it as grayscale.
Douglas
on 4 Aug 2016
Walter Roberson
on 4 Aug 2016
Did you change both writeVideo calls? You could get that error if you missed changing the first one.
Douglas
on 6 Aug 2016
0 votes
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!