MATLAB: How to flip a movie file with VideoWriter

flipmoviemovie2avivideovideowriter

I had flipped my movie file up to down by using movie2avi, with the following code. However, after upgraded to MATLAB R2015a, the code couldn't work, and MATLAB's help recommends me to use VideoWriter. How can I use VideoWriter to flip my movie file?
Thanks in advance.
% edit_movie
close all
cd C:\
Vobj = VideoReader( '1R2f1.avi' );
matrix_V = read( Vobj );
[ H, W, B, F ] = size( matrix_V );
matrix_V_rev = [];
for i = 1:F
matrix_image = matrix_V( :, :, :, i );
matrix_image_rev = flipud( matrix_image );
M( i ) = im2frame( matrix_image_rev );
end
movie2avi( M, '1R2f1_rev.avi' );

Best Answer

Remove the movie2avi call and use
v = VideoWriter('1R2f1_rev.avi');
open(v);
writeVideo(s, M);
close(v);