Screen capture and making movies
Sunday, March 22, 2009 at 5:45PM
Tux in Linux, Linux, Tips and Tricks, capture, images2mpg, jpg, mjpegtools, movie, mpeg123, screencap

Greetings fellow cybersquatters!

Came across an annoying problem today that had me stumped for a while. I wanted to do two specific things:

1. I wanted to capture a portion of the screen but, since I wanted to capture the same area repeatedly so that I could make a sequence of pictures, I needed to find a way to capture that did *not* involve me selecting a region of the screen for each picture over and over again because that would have been too time consuming.
2. Once I had a sequence of screen captures, I wanted to turn them into a movie.

Do I hear someone say "Linux to the rescue?". If so, I couldn't agree more!

Linux tip alert......

To capture a portion of the screen - in my case, a browser window - I decided to use good old *ImageMagick*. ImageMagick's *import* command can be used to capture an area of the screen AND it can also be given command-line parameters. For those of you who go slightly queasy at the mere mention of the words "command" and "line", stick around, this really is not a difficult tip to implement at all....

Since I wanted *import* to capture only a specific portion of the screen, I began with the following command:

import -window root -crop 100x200+100+200 example001.jpg

Hitting enter on that will cause import to take a picture of the root window and crop it down to 100 by 200 pixels at the co-ordinates 100 from the left of the screen and 200 from the top of the screen. The parameter "-window root" tells import to capture the entire screen. You could also tell import to capture a specific window, if you like.

My problem was, I didn't want to capture an entire window, just a part of a window. And I didn't want to capture the entire screen, just a part of the screen. That's what the second half of my command line accomplished. By using the parameters:


I was telling capture that AFTER taking a picture of the whole screen, it should move 100 pixels to the right, and 200 pixels down (+100+200) and then select an area 100 pixels by 200 pixels in size (100x200). The final argument to import is the filename you want to save to, in my case "example001.jpg".

The best way to get a feel for what I described above is to try it out yourself, just use my command line and mess around with the 4 size parameters (AxB+C+D) and see what effect it has on the output file "example001.jpg".

After tinkering with the size parameters myself, I finally succeeded in selecting an area that was exactly right for my purposes: It covered the area of interest, but not the window dressings, borders, scrollbars, banner ads, etc.

And after that it was just a matter of advancing to the next page in the browser, and then invoking the command line command above again, except this time with a filename +1 (i.e. example001.jpg, example002.jpg, etc). No selecting capture sizes, no dragging or clicking with the mouse, just arrow up to get the previous command, change the filename, and hit enter. One second later, your picture is saved!

Making movies

What the above paragraphs left me with was a series of sequentially numbered jpg files which I then needed to turn into a movie. This was easily accomplished by using the program "images2mpg". On my distro (Fedora 10), images2mpg is part of the "kipi-plugins" package. Before using it in the manner described below, I also had to install the "mpg123" and "mjpegtools" packages.

Once all that was in place, I moved into the directory that held my jpeg files and entered the following command (from a console, of course):

images2mpg -M /usr/bin -f SVCD -d 2 -S 420mpeg2 -o MyMovie.mpg -i *.jpg

What does all that MEAN? Okay, the "-M" flag shows images2mpg where the mjpegtools programs are located. I had to use this flag with the parameter "/usr/bin" because images2mpg wasn't apparently able to find the mjpegtools programs by itself. The "-f" flag tells images2mpg which format to encode to. In my case, SVCD was fine. If you want to know what other formats images2mpg supports, just enter "man images2mpg" from the command line. The "-d" flag stands for duration. I set my duration to two seconds, which means that each jpeg picture is displayed for two seconds in your movie, before the next picture is displayed. The "-S" parameter determines - wait for it - the "Chroma subsampling mode". I used 420mpeg2 which seems to be a reasonable default for an mpeg2 movie. "-o" is the name of the output file and "-i" is the name, or names, of your input file or files. In my case, I just used "*.jpg" since my jpeg files were sequentially numbered, thereby ensuring that they would be used in the correct order by images2mpg without any further tinkering.

And there you have it: Your very own movie, constructed from multiple jpeg images.

Tux lives.

Article originally appeared on dutchtechies (
See website for complete article licensing information.