Wednesday, 19 January 2011

Inline comments in LaTeX

I recently got some feedback on an article that I've submitted, and when I started including the reviewer's comments in the revised version, I started wondering if there is a way to make an "in-line" comment in LaTeX documents. I often use the percent sign, %, to comment out everything after a line, like this:

... and thus we see that these methods are equvivalent. % Or are they?

After some searching I found an interesting post on Eric Rasmussen's blog, and it seems that the easiest way to do this is to define a "macro" that doesn't do anything, in the document preamble:

\newcommand{\comment}[1]{}

and then I can make an inline comment using the \comment{} command, like this:

... these methods are equvalent. \comment{Or are they?} Luckily, it doesn't matter...

Thursday, 13 January 2011

Compressing Matlab AVI videos in Linux

Recently I've started making a few movies in Matlab. This is actually quite easy - for an example see this description from the Matlab documentation. Unfortunately, the movie2avi() function does not apply any compression when writing the movie to file (not in Linux, anyway), and this results in very large movies (on the order of 100 MB for a few seconds).

However, I found a solution. I originally posted it as a reply in the MATLAB Newsreader, but I thought I'd share it here as well:

You can transcode Matlabs AVI movies using FFmpeg (www.ffmpeg.org). If you don't have the package, you can install it using the terminal:

sudo apt-get install ffmpeg

If you have only one file, let's call it inputFile, you can transcode it using something like this:

ffmpeg -i inputFile.avi -sameq outputFile.avi

The "-sameq" option is used to preserve video quality. I tested this on a 80 MB file produced by Matlab, and got a 5 MB file without any visible loss in quality. If you want to do it within your matlab script, use the system() command:

system('ffmpeg -i file1.avi -sameq outputFile.avi')

If you have a problem with the Matlab AVI file growing too big, you can split it into several smaller files and compress them as you go, and finally combine them after your iteration has finished. A way of doing this is described here in the FFmpeg FAQ. Note that you will have to transcode your intermediate files to MPEG format. .