IntroductionI thought I'd share my process for making "timelapse" videos under Linux. Since a few different programs and there are many to pick from it it took a few tries for me to arrive at a stable workflow. The type of video I'm talking about is a sped up recording of making a painting in your favorite program, adding sound to it afterwards, like this one:
This tutorial covers all aspects of creating a Linux timelapse in detail, so depending on your computer literacy you can probably skip parts of it. The sections covered are:
- Recording the video - using screen recorders, both in GUIs and from the terminal.
- Speeding up the video using memcoder - this creates really smooth speedup.
- Compositing the video in Kdenlive - combining video clips, audio and text
- Uploading to Youtube
- Summary
Recording the videoThere are a bunch of different screen recorder options in Linux and I've tried them all with varying results. Some have various clever solutions to only record part of the screen that's changing, others have various tools for showing graphics around your mouse cursor. For highly sped-up videos, showing your mouse and keyboard input is not all that useful however. In the end what I went with is the small and effective
recordmydesktop.
In Debian-derived Linux distributions (like Ubuntu, Mint etc) you can get recordmydesktop from your package manager or with
sudo apt-get install recordmydesktop
Recordmydesktop itself is a terminal-only program, and I use it as such. There are however GUI frontends for it, with buttons to press, in the form of gtk-recordmydesktop (found e.g. in the Ubuntu repo). If you prefer experimenting with those, you can get them in the same way.
The GUI wayI use the terminal but the easiest way to get started is to use one of the GUI frontends to recordmydesktop. I used to cover two options here, gtk-recordmydesktop and recorditnow. But I found that recorditnow produced very bad, choppy results for me. It may be just me not knowing how to configure it but out of the box its results are not suitable for what we want to do. So I removed it.
gtk-recordmydesktopAfter starting gtk-recordmydesktop, the following window will pop up.
gtk_recordmydesktop-01.pngBy default it will record your entire screen, or both screens if you have two monitors like me. You can use the "select window" button to mark which parts of the (tiny, tiny) thumbnail should be recorded. Before continuing though, press the "Advanced button" and go to the "Performance" tab. Make sure "Encode on the fly" is checked, like this:
gtk_recordmydesktop-02.pngThis makes the video immediately available to you when you finish (otherwise the encoding will happen afterwards which can take more than an hour for long videos). It is CPU-heavy though. So if you have a weaker computer and find it stutters while recording, turn this back off.
Press "record" to start recording. There should be a stop button popping up in your toolbar, but I find this does not really happen in my KDE setup. So unfortunately I have to stop it by killing the program from the task manager. One way or another, a file "out.ogv" (and later out-1.ogv, out-2.ogv etc) will be popping up in your home directory. These are video files you can look at with any normal video player (like VLC or Mplayer). Move them to wherever you want them to be.
The Terminal wayThe terminal gives complete control over the recording and is really quite simple - the length of this section is just because I explain every option in detail. If you are using Linux (or any computer, really). knowing the terminal is a good skill to have and you could view this as a simple learning project.
First, set aside somewhere in your home folder for storing your stuff. I made a
Videos folder in my home directory. First open a terminal (usually from a start menu or app launcher). This can be named Terminal, Konsole, Gnome Terminal, Xterm or similar depending on your window manager.
Since every recording tends to be started in the same way, I made a simple bash script to start my recording. I use the VIM editor myself, but learning that is a bit outside of this tutorial. Installing something like gedit (sudo apt-get install gedit) is probably best - it's something like Notepad on Windows. Let's make a simple bash script:
gedit record_current_screen.sh &
The ending "&" means you can still use the terminal even though the gedit program is running: Just move your mouse back to the terminal and press return to get the terminal prompt back. In this script, add the following then save:
#! /bin/bash
echo "Starting recordmydesktop. Abort with Ctrl-C."
recordmydesktop --no-sound --on-the-fly-encoding --workdir /var/temp -o desktop_recording.ogv
echo "Stopped."
Ok, let's look at what this does.
- #! /bin/bash must be at the very first line! There can not be an empty line above it. This tells Linux that this is a script that should be run with the bash shell.
- echo lines (both of them) simply echo the text following them to you when the script runs. We put some in to help you remember how it works.
- The recordmydesktop line is the actual starting of the program. We give it options:
- --no-sound: Don't record any sound. This makes for a less CPU-demanding recording, and since we are speeding the recording up later, sound would not work anyway.
- --on-the-fly-recording: This is important. It encodes the video immediately instead of just storing the raw frames in a temporarly location and encoding it afterwards. The advantage of this is that when you stop the recording you will immediately have a new .ogv file to look at. The drawback is that it's heavier on your CPU. So if you find your computer is affected by the recording (it stutters when you draw), turn this off. However, if you do, the encoding may take an hour or more after you stop the recording, so you must leave the terminal open to let it do its thing!
- --workdir /var/temp: This allocates the temp folder for it to store temporary files in. It's probably not too important, but if your /var is on a very small hard drive you might want to move this elsewhere.
- -o desktop_recording.ogv: This tells it to output the resulting video to a file desktop_recording.ogv. If you record multiple times and there is already a file with that name, subsequent files will be named desktop_recording-1.ogv, desktop_recording-2.ogv etc.
Let's test it out. Go back to the terminal (if you started gedit with & at the end, press return to get the prompt back).
ls
(returned:) record_current_screen.sh
So we have a new script file created. Let's make it executable:
chmod u+x record_current_screen.sh
If you do "ls" again, you should, if your terminal shows color, find that the file is green. The "chmod" command (which stands for "change mode") is used to change the permissions of a file. "u+x" means that we give the user (you) the right to "execute" the file. That is, to run it like a program.
So let's run it:
./record_current_screen.sh
(returned:) Starting recordmydesktop. Abort with Ctrl-C.
(returned:) Initial recording window is set to ...
(returned:) ...
The first text we see returned in the terminal is just the first
echo of our script file. After that is a lot of recordmydesktop output. You should see a grey box appear around your screen. You are now recording your screen! Move your mouse and window a little then go back to the terminal and press Ctrl-C to stop the recording.
If you enter "ls" now, you will see a new
desktop_recording.ogv file. You can look at it with
VLC or
Kaffeine or
mplayer or whatever video player you have installed. Henceforth you can just run the script to record your screen whevever you like.
A note on dual monitorsIf you have two screens you will normally be recording across both of them If you want to change to only record one of them that you need to specify the starting point and the width/height of the square in which to record when you call recordmydesktop. For example, I have two monitors, each 1680 pixels wide and 1050 high. Here's how I call recordmydesktop for recording on the left monitor:
recordmydesktop --no-sound --on-the-fly-encoding -x 0 -y 0 --width 1680 --height 1050 --workdir /var/tmp -o desktop_recording.ogv
And on the right monitor:
recordmydesktop --no-sound --on-the-fly-encoding -x 1680 -y 0 --width 1680 --height 1050 --workdir /var/tmp -o desktop_recording.ogv
The options are
- -x and -y: These define the starting top left corner of the rectangle to record. -x 0 -y 0 means to start at the top left corner of the leftmost monitor. -x 1680 -y 0 means to start 1680 pixels to the right (that is, all the way across the leftmost monitor).
- --width and --height: These specify the width and height of the recording area. We put them equal to one monitor's size.
Recording the videoJust start the recording and do the artworkd you want to record as as timelapse. This bit is entirely up to you. If you want to take a break, just stop the recording and start it again later. You will end up with multiple video files, but this is okay, we'll put them all together later.
Speed up the videoIt's really quite dull to watch a painting being created in real time. Speeding it up makes it a lot easier to summarize the process and keep people from getting bored. In principle the video editor program should be able to speed up the video. However, I have found that my editor of choice (Kdenlive) is actually pretty flaky about that, and the quality is not always great. So I do the speedup in a separate tool,
mencoder, which stands for "mplayer encoder". Get it from your package manager or via
sudo apt-get install mencoder
We will assume your new video file is called "desktop_recording.ogv" (replace with your actual filename). Open a terminal if you don't already have one open.
(cd to place you have your newly recorded video file)
mencoder desktop_recording.ogv -ovc xvid -oac mp3lame -xvidencopts pass=1 -pfps 48 -o "desktop_recording.mp4" -speed 8
This will convert your ogv file to a
desktop_recording.mp4 file sped up 8 times (the speedup can be worth experimenting with). That long line is a lot to remember though, so let's make a script to run this easily, similarly to what we did in "The Terminal way" above. The
gedit program is, as mentioned above, a simple text editor you can use. Let's make a small script called
speedup_video.sh by entering
(The "&" means you can keep using the terminal even though gedit is running). In gedit, enter these two lines and save:
#!/bin/bash
mencoder "$1" -ovc xvid -oac mp3lame -xvidencopts pass=1 -ofps 48 -o "$1.mp4" -speed "$2"
Here's what it means:
- #! /bin/bash must be at the very first line! There can not be an empty line above it. This tells Linux that this is a script that should be run with the bash shell.
- "$1" and "$2" will be replaced by the arguments we use to execute this script later. Think of them as placeholders - when the script runs, they will have values that we give it, in this case $1 will be the name of the video file and $2 the speedup factor.
- -ofps 48 sets the resulting framerate to 48, which I find makes for a very nice and smooth video, especially when sped up.
- The other options specify encoding formats and processing that just works. Look into the memcoder docs if you want more details.
If you saved in gedit, doing "ls" should show you that the new file
speedup_video.sh has popped up. Now, make our new script executable:
chmod u+x speedup_video.sh
The "chmod" command (which stands for "change mode") is used to change the permissions of a file. "u+x" means that we give the user (you) the right to "execute" the file. That is, to run it like a program. Which we'll do next:
./speedup_video.sh desktop_recording.ogv 8
Note how we supply the name of the video file to speed up (desktop_recording.ogv), and then the speedup factor (8). In the script, these will replace the $1 and $2 when calling memcoder. From now on, you don't need to remember all those other memcoder options and can just run this on whatever video file you want.
Combining the video with musicFor actually editing the video together with sound, we need a video editor. There are a open-source ones around for Linux, varying in complexity and scope. I have probably went through most of them and found that the simplest and easiest one is
Kdenlive. It has relatively few bells and whistles - but we don't really need too fancy features for what we want to do. It allows for easy editing in a very intuitive way - and now that our video is pre-sped-up it will be even easier. One thing though - make sure to save your project often - Kdenlive can be a bit unstable at times. Get it via your package manager or via apt-get as usual:
sudo apt-get install kdenlive
When you open Kdenlive, this window faces you:
kdenlive01.pngFirst, save your (currently empty) project in the File menu. Kdenlive projects have the file ending
.kdenlive. Make sure to hit Ctrl-S often, just to be safe.
To add a new clip, go to the
Project menu and choose "Add Clip":
kdenlive02.pngPick your sped-up video file from the selector. You may get a pop-up asking if you want to adapt your vide profile to the clip. Accept doing so. Your clip will now appear as one of the available clips. If you stopped/resumed your recording you will have multiple files (all sped up as above). Load those as well.
Next, add another clip, but this time select the finished painting (like a jpg file). We will show this as the "final result" at the end of the video.
kdenlive03.pngNow just click-and-drag the video clip(s) onto the timeline below. If you have multiple videos, you can put them one after another. As seen above, I put the final image at the end. I also pulled at the edge of it to make it show longer. Note that I put the image clip on the "lower" timeline. The reason for this is because we want to put some text "on top of it" (those time lines work a little like layers). You can press Space to start playing the video in the small window to the upper right. Click in the time line to move the "timeline marker" around.
To add some text to the final image, click to place the timeline marker over the final image clip, Go to the Project menu again choose "Add Title clip". The following window will appear:
kdenlive04.pngMake sure to check the "Show background" so you see where to put text relative to the image (which is "below" it in the timeline stack). This bit works like a text editor, you write text, align it etc. Think of it as writing on a transparent sheet over the video. When you exit, you will have a new "Title Clip" available. Pull this to the timeline above your final image and extend the two to match:
kdenlive05.pngLet's add sound! If you aren't making your own music, you need to download this from somewhere. You can't use just any music either, you must use music with a license allowing you to use it for free (you could also license music for money of you really wanted to, of course). A good idea is to search google for "royalty free music". There are lots of musicians that release music that you can use. Remember that if you want to
monetize your video on Youtube (have it show ads), you must also check so the music license allows commercial use.
Once you have your music. you need to do the normal "Add Clip" from the Project menu to get your music MP3 files. Pull those onto one of the "Audio" tracks.
kdenlive06.pngMost musical pieces are only 3-4 minutes long so you probably need to add multiple music files one after another to last the length of your video.
A final touch is to add fade-ins/outs. You find them under the "Effects" tab in the center of the Kdenlive window.
kdenlive07.pngThere are separate fades for the video and for the audio. Just pull them onto the right clip to add the effect (they will be added to the beginning or end of the clip depending on if you are fading in or out). This is a very easy way to blend music and clips together (such as fading out the previous clip and fading in the final result at the end of the video). It's pretty intuitive so you should be able to figure it out. There are plenty of other effects, experiment - just remember to save your progress often.
kdenlive08.pngFinally we want to render the file into a final video, sound, text and all. Press the "Render" button in the Kdenlive toolbar and you'll get the pop-up above. You can set the output file to the final filename you want for your video. MP4 is a good format to go for. For putting on Youtube, I use default settings and choose MP4/MPEG-4/MP3 as seen above - it has worked well for me but you may experiment if you want.
Press "Render to File" and your video will be created. If your video is long, this may take a while.
In the end you'll have your very own video that you can play on your computer!
Uploading your video to YoutubeThis is the easy bit, although the process may be a bit slow if your video is big. First you need a Google account. You use that to log into Youtube. If you go to your own "channel" you will have an "Upload" button you can click. This will give you the option to upload a new video. I recommend you first set the video to "Private". This gives you time to add any extra stuff to the video before anyone else can see it.
Once you've chosen your video file (or drag&dropped it), you will need to wait for it to upload. While uploading you can't close the browser window. After that the Youtube progress bar will show that the video is "Processing". This can take a long while sometimes, and you
don't have to sit around to wait for it - when the processing is done the video will just pop up as one of your videos. If you set it to private you then have all the time in the world to set its name, description, choose monetization options and what have you. I often add Annotations (pop up notes) to give some more background on what I'm doing in a painting.
When you are done, just switch the video to being "Public" and you have your timelapse online ready for everyone to see!
SummaryThis may have been a long read, but most of this tutorial describes setting things up. When I create a video, my full work flow is this:
1) Start gimp/krita/mypaint/whatever and open terminal
2) run ./record_left_screen.sh
3) Paint the image, then Ctrl-C to stop recording
4) run ./speedup_video.sh desktop_recording.ogv 8
5) Open kdenlive and edit
6) Post to YouTube