Thursday, March 29, 2012

Matlab and Movie making

I realize that this is completely against the spirit of my blog, yet I find myself sighing so loudly with relief at having finally been able to make the 'movie making in matlab' process work for me, that I just needed to put it down here (for future reference and for everyone having the same problem)...Believe me, I know how madly annoying it can be to run an 'addframe' command in loop 5000 times, relinquishing control over your screen for an hour, only to find at the end of this excruciating process that the avi is distorted!!!

In matlab...

filename = sprintf('images/Pic%04d.jpg', index);
imwrite(image_matrix, filename);

In the terminal...
ffmpeg -i Pic%04d.jpg -sameq -r 25 outmovie.mp4
or
ffmpeg -i Pic%04d.jpg -sameq -r 25 outmovie.avi
To slow down the movie,
ffmpeg -i Pic%04d.jpg -sameq -r 25 -vf "setpts=2.0*PTS" outmovie.mp4
To speed up the movie,
ffmpeg -i Pic%04d.jpg -sameq -r 25 -vf "setpts=0.5*PTS" outmovie.mp4

And wala!, I now have a perfect movie :D

No comments:

Post a Comment