Create timelapse on Linux

In preparation to create a timelapse of my modeling work, I had to figure out a way how to record it on Linux. It turns out that it is not that complicated and is comprised of the steps:

  1. The periodical screenshots
  2. Compile the images into a movie

The solution I found works for me on a Linux Mint Debian Edition (LMDE), but I see no reason, why it should not work for any other Linux distribution.

All this I figured out with the help of Kvisle’s Post on this issue.

First step first, this is done by a script. The script is started before the action that is to be timlapsed and canceled with Ctrl-C afterwards:

#!/bin/bash

# Takes a screenshot of my second monitor every 15 seconds
# Only have one monitor? Drop the -crop part ...

IMG_DIR=~/Pictures/timelapse

mkdir $IMG_DIR

SLEEP_SEC=15

if [ $# -eq 1 ] ; then
  SLEEP_SEC=$1;
fi

while [ 1 ]; do
# Uncomment the line below if you only want timelapse of your second monitor, and both monitors are 1680x1050 big.
# import -window root -crop 1680x1050+1680+0 $IMG_DIR/LD21-$(date +%y%m%d-%H%M%S).jpg

# Only use first screen with resolution 1920x1080 and crop away the lower menu bar of height 25
import -window root -crop 1920x1055 $IMG_DIR/LD21-$(date +%y%m%d-%H%M%S).jpg

#import -window root $IMG_DIR/LD21-$(date +%y%m%d-%H%M%S).jpg
sleep $SLEEP_SEC
done

The notable parts of this script:

The sleep time can be passed as argument. The default value is 15 seconds. The sleep time defines the time that passes between two screen shots.

The second point is the cropping used on the import command. As I have two monitors and the action that I want to show happens on the first, I specify the dimensions of the display as the crop argument. Additionally I cut away the menu and task bar at the bottom of the screen.

Due to the cropping for each screen shot we get four images, as the whole display for both monitors is cut up into rectangles, so we get the one that is specified in the crop part. The handling of the other parts is already the second step:

#!/bin/bash

IMG_DIR=/home/andi/Pictures/timelapse

cd $IMG_DIR

# As the crop option was used to create the images,
# there are three images that we are not interested in.
rm *-1.jpg *-2.jpg *-3.jpg

mencoder mf://*.jpg -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o timelapse.avi

The thing to do is to throw away all the images, that we are not interested in. The remaining we can push into the mencoder to create an avi output file. In my installation I had to install the mencoder first.

Schreibe einen Kommentar