Tuesday, April 14, 2015

Time-lapse Photography with Linux

INTRODUCTION:

Before I really start, I want to point out that there are simple mobile apps out there that will help you do time-lapse videos with your mobile phone and encode it all on the fly! So if you just want to do time-lapse videos as simple as possible, for fun and you don't intend to sell your work, then stick to those apps, they are OK. Otherwise if you are curious or really want to learn how to do it and sell them then read on...

Some patience will be required, depending on the amount of quality you are trying to achieve. I do time-lapses in a more semi-pro level which I sell in stock media sites such as pond5.com or for direct clients who need to re-edit the encoded video to have it assembled with other video formats and the final encoded video must have certain quality specs. Also, I am able to edit the individual shots this way such as levels, exposures, colors and some effects at some point of the process.



This guide is just a "basic" work-through of how I do it or the steps I have developed to do it, just use it as a basic starter guide, you are free to use the software that you have available and don't really have to stick to what I use or what I do, depending also in your OS, just make sure that you have about the same control of the steps that I have and that I show in this guide so your time-lapses end up having a great profitable quality. 

Let's start...

I have been asked quite many times on how to create a time-lapse video like the ones I do, so that's why I decided to throw in this guide for those who really want to do it in a more "pro" level and probably even sell them. Unfortunately for some of you, I am a Linux user (probably more like fortunately for me) so this guide will be aimed more for Linux users because of the software I use but the steps can be quite similar if you use another OS environment and depending on what software you have available. Also, there really isn't a right or wrong way of doing it, except for the final video encoding format. Here I just explain how I do it myself, with time and as you go along you will probably find out and learn other things that will suit your needs. It's quite simple but a lot of patience is required in the whole process, mostly during the shooting and photo preparation stages, because if we wanted to encode a final video for example with a playing duration of 30 seconds with shots taken every 3 seconds and a frame rate of 29.97fps we would have to shoot for about 45 minutes. That's just an example, it all depends on the shooting interval, how long you want your final video to last and at what frame-rate it will play, so a lot of preparation is required before you really do it, of course you can just go ahead and do it just for testing purposes or "fooling around" but if you intend to publish your work on specific media sites and sell them (like I do) or want to share them on Youtube or Instagram you really have to understand what video encodings those sites use or accept, they all differ. I put my time-lapse videos on pond5.com for sale and they are very strict with quality, sizes, frame-rates and so on, so first visit the websites help section where you intend to publish your videos to check what specs are acceptable.
 

Now, the important part, the GEAR!

You must be thinking by now that you need a super high end camera or video camera to achieve this. Truth is, you don't. I have even used my mobile phone for this with amazing results, yes, you read that one right! I will explain.


Video resolutions are very different to photographic resolutions, although we will be taking many single shots and think like a photographer for each individual shot, at the end, the size of the images don't have to be super big! As photographers we usually think in Mega-Pixels, we have been brain washed by camera manufacturers that the higher the better for great photography (I will not get into this argument now, but it's not always true!).

The standard resolution for today's modern High Definition TV widescreen format known as 1080HD has a resolution of 1920x1080 pixels, so if we multiply those numbers we get a total of 2,073,600 pixels, that's still under 3 Mega-Pixels! Now I'm not saying to go and shoot so low, but I do want you to understand that you will not need to use your camera's full sensor capabilities for this. Some DSLR's have way above 20 Mega-Pixel sensors, I think that's overkill for both your camera to process so many shots in a period of time and the computer to post process all those shots, also think of the amounts of hard drive space to store all these shots. If we take the same example I mentioned above, that shooting time and frame rate will give us a total of 900 shots, now you see where I'm going? So don't shoot so high! Just find a resolution that you can work with. I usually shoot for 1080HD so I shoot approximately at 5MP for this because it's always good to have that extra image information in case I need to crop an area, you know framing the perfect shot is not always possible, so shoot just a little higher than what you will really need the final video at, it never hurts to have a little extra, but the truth is that even your mobile phone could take photos at a higher resolution than some of the conventional high end video cameras which do shoot natively at 1080HD.

Here's a comparison of different camera resolutions, you will see that the one in red is the standard 1080HD video size that I usually work with, really small compared to what a DSLR can shoot up to:


So, by the image above, we could say that if you shoot your images at 5MP you will be far safer than you think if 1080HD is your target final video size and will be viewed in a big 40-some inch HD widescreen TV. Now, if you think your time-lapse videos will hit the big cinema, then you can see pretty much in the image above how large of a resolution you will need to shoot at  (4K Cinema) but will still be quite below some of the newer DSLR camera resolutions. Anyway, for simplicity's sake, we'll stick to the standard 1080HD size in this guide.

So let's go back to the gear:


 GEAR:

 1.- Camera! (Yes, you will need one of these, sigh!) Any camera should do, but it must have either the option to be able to have an intervalometer connected to it or it should have an integrated intervalometer function in its firmware. Some Nikon cameras do have intervalometer functions already in them, you will probably have to dig deep in your camera's manual and settings to see, most Canon cameras don't, so you will need to purchase an intervalometer for them.

One thing to consider is that doing time-lapses introduces some tear and wear to your camera, so I wouldn't choose my favorite DSLR for this type of work. A few time-lapses won't hurt but if you are using a full DSLR with physical shutter for this too often you will end up killing your camera sooner, you have to understand that the shutter will be operating continuously at short intervals in small periods of time, also the sensor will start failing after some time (they usually do even with normal usage), so yes, too much of this will add extra mileage to your camera sooner than expected! You could buy a cheaper refurbished camera like I did for this as I explain below, Canon PowerShot models would be the best, but then again, a camera is to be used, not to be kept in a glass bubble.

If you have or do get a Canon Point and Shoot such as a PowerShot model, chances are that you can hack it with a firmware (not permanently) with CHDK, this hack will let you use your PowerShot with cool scripts such as intervalometer and with more manual settings, you can even do really long exposures at very high ISO's if you want to do star trail or astro-photography and even shoot in RAW using the DNG format. I use it on my Canon SX510 HS, and it works perfectly well.

WARNING: I will not be responsible if you end up with a "bricked" Canon camera if you do choose to do the CHDK hack, although there is no reported issues of camera malfunction with the hack, you just never know. What I did was buy a refurbished SX510 HS just to do this type of things with it, maybe you can try doing the same as I did.

You will want to see what Canon point and shoots are supported by the hacked firmware, so just head up to the website and see if your camera or one you intend to buy for this is supported, but please don't ask me for support on it, I have absolutely nothing to do with it, if you have questions, you will have to get in touch with them.

Here's the link to CHDK:

http://chdk.wikia.com/wiki/CHDK
  

CELL PHONE/MOBILE USERS: Not to worry! There's a great app called CAMERA FV-5, it's what I use when I have to use my mobile for doing time-lapses, purchase it, it's really worth it and it has intervalometer function in it!  Here's the address:

http://www.camerafv5.com/ 

I think there's only for Android, because that's what I use, not sure, if you are on iOS/i-whatever you'll have to search for a similar camera app that has intervalometer function. 

2.- Intervalometer (Only if your camera doesn't have this function).

3.- A sturdy tripod, unless you want to stand still for about an hour or so and have extreme shaking in your videos...

If you're using your mobile, you'll probably want to get an adapter to be able to mount your phone on the tripod, or maybe even build an adapter, I made a pretty simple one out of MDF (Medium Density Fiberboard) which works well and locks my phone nice and tightly when I use it for time-lapsing.

4.- A little patience, hmmm, maybe just a little more...


LET'S DO IT!


MANUAL MODE, MANUAL MODE, MANUAL MODE...

Digital cameras are wonderful pieces of photographic hardware. They all have amazing assistants and automatic scene/focus functions. But please, remember to set your camera in manual mode for this type of work! When I mean manual, I mean manual on everything!

NO AUTOFOCUS
NO AUTO LWB (Light White Balancing)
NO AUTO ISO
NO AUTO EV (f values or stops)

Otherwise you will end up having very noticeable and horrible flickering on the finished video, for example, if you are doing a beautiful time-lapse of a landscape where you have a lot of clouds rolling thru the scene, your camera will be automatically adjusting itself to light/color levels as the light changes by the position of the clouds and even the position of the sun, a lot of things can happen in less than an hour. When you are ready to shoot, focus manually on a steady object, and disable the auto focus.

Shoot in RAW if you can!

Not a must but it's a great benefit to shoot in RAW especially if you will post-process your images, since JPEG files already have compression in them and the shadow/highlight details are not the best, you can still do it in JPEG, I do it sometimes if I have to, I just try to be very careful with my exposures, we'll get to the post-processing later...


Intervalometer/shooting times:

Program your intervalometer, usually 3-5 seconds between each shot gives some nice results for cloud movement, 5 seconds will make them look faster on the final video but will still have that nice transitional smoothness. This is something you will learn with experience, because wind speed is another great factor. You should look for some apps that can assist you with number of shots or shooting time for a video that lasts so much time at certain FPS. Just look up for anything like "time-lapse calculator", there's quite a few that are free and pretty good.

For starters, I would suggest do it pretty much like I do, let's do a 1080HD 29.97fps time-lapse video that will have a total playing time of 20 seconds. So if we do our math right, that means that for every second we need 29.97 shots, let's round that one to 30.

So 30 shots x 20 seconds of playback gives us a total of  600 total shots.

But, at what intervalometer speed?

If we shoot a shot every 3 seconds the total shooting duration will be of 30 minutes.

If we shoot a shot every 5 seconds the shooting time will be of about 50 minutes.

So you can see the intervalometer time affects the shooting time quite a bit! Let's do it at every 3 seconds, I like to use this with landscapes, although every 5 seconds can be nice also to record more sun position changes.


So once you do your shooting, you should have roughly about 600 total shots. I will use as an example, one of my own favorites that I did in a lake in my Mexican hometown. I did this one with my mobile so you can see that yes, even a mobile phone can be good enough sometimes. The original files are 2560x1920 px (4:3 aspect ratio). I am putting a side by side comparison of the very first shot and the last one so you can "imagine" all what went through the whole 30 minute shooting process...





PREPARING YOUR PHOTOS:


By preparing your photos, I mean quite some work here, it all depends on the amount of quality you are willing to have at the end which does pay off very well after all.

First it's the unwanted objects. When you do a time-lapse you will have things like birds and bugs flying around your shots, usually all the time mostly if you are out in the wild, and they will not be smooth looking and consistent, they will appear as fast momentary small speckles to large dark blotches, depending on the size of these objects and yes, even if they appear for a very fast fraction of the playing time, they can be very distracting!

Things like airplanes can be more acceptable, it all depends, sometimes jets will leave their jet-trails and they can be cool sometimes, mainly because they are consistent, but maybe the type of scenery you are working with will require removing them, that's up to you.

So some photo editing skills and some patience will be required for this.

You don't have to really go through your whole set of shots and analyze them one by one, what I usually do is I encode a test video with all my shots to look at and see if there are things or objects that catch my eye, I will look at this test video encoding a few times to make sure and see what objects really bother me, there will be things that your eyes won't pick up and can be ignored. If there's something, I look at the playing time position of the video, do the math to figure out which frame/shot number it could be. Then I open up my image editing program (I use GIMP which is free, Photoshop for those using mac/windows, if you don't have Photoshop, you can download GIMP for free also), then I open that specific shot and load as a layer either the very previous or very next shot and copy the area of where the object is from the layer to the affected image. I do it with a cloning brush so it's smooth, not a rigid square, but you really don't have to be so precise with it, the eye will not pick that up at the playing rate like it would with a dark object (birds in sky for example), and I will do this with all frames that do distract me or catch my attention. Remember before saving the retouched shot to remove the layer where you copied the area from. I know, it's tedious work, but it's worth doing it!


EDITING THE PHOTOS:

Next, what I do, is color correction, level & exposure correction, cropping and all that to my shots. Not to worry! I don't do this one by one...

What I use is "Darktable". It's an amazing free open-source program similar to Adobe's Lightroom. In my opinion it's even better, but that's my opinion. Only Available for Linux and mac. You can download it here:

http://www.darktable.org/

I load all the shots from the folder where they are located, look for one of the brightest shots, since I will only edit this specific shot and apply those settings to the rest, I want to make sure I don't over blow the highlights by working with a darker shot:




I go on into the darkroom (editing mode) and work with that specific image:



The very first thing I do is crop and rotate my image so it's straight, in this case since we will be working with a 1080HD video, it has a 16:9 aspect ratio, so you can see in dark what will be cropped out (yes, it sometimes hurts to see all that go away), just make sure that when you are cropping you don't go below the final video resolution size, in this case I would not crop lower than 1920x1080px:


Then I do some exposure, level and color correction and throw in a bit of global tone-mapping (a subtle HDR), but I do try not to over do it, just so those details pop out and make the beauty shine:


Once I finish editing that specific shot and I am positive about how the final video will look, I exit the editing mode, copy the settings of that specific photo and just apply it to the rest of the shots, it's all nicely automated:


Then I batch export all my shots. Darktable is a non-destructive photo editor, it will output new files and it has a nice sub-program for batch processing, it can be quite cpu and memory expensive and can take a bit of time. You will have to read and learn Darktable to really see how to batch export hundreds of files at once. But it's usually something like this from a terminal and from the directory where you loaded your shots from:

for i in *.RAW ; do darktable-cli "$i" /where/to/store/result/"$(basename "$i" .RAW)".jpg ; done

Depending on your file types and where you want to store your final shots is what's on bold.

I don't know If that same process can be done in Adobe Lightroom, but I'm sure it can export hundreds of edited shots on the fly.

Then I run all those exported photos through a "deflickering" process. Yes, even if you shot at 100% manual mode you will still get a bit of flickering because camera sensors still respond to subtle light variations, but it's not as noticeable as if leaving it in auto mode. In Linux, I use a perl script created by Vangelis Tasoulas aka "CyberAngel", it's a great script, does the work well. If you are on mac or Windows you will have to look for something similar.

So if you are a Linux user just download the script from here:

Time-lapse_Deflicker

You can also download it directly from Vangelis git repository, you'll might find a more updated version there:

https://github.com/cyberang3l/timelapse-deflicker

To be able to run it you will have to make sure you have Perl and Imagemagick installed with the following modules:

libfile-type-perl
libterm-progressbar-perl

They should all be in your Linux distribution's sources.

Extract the script where your exported photos by Darktable are, make it executable and just run it from there in a terminal:

./timelapse-deflicker.pl -p 2 -v

If you do:

./timelapse-deflicker.pl -h

You will get a brief explanation of the script.

This script WILL NOT touch the exported files by Darktable! It will load them, analyze their luminance levels, then it will write a new folder where those photos are stored in and save the "deflickered" versions.



VIDEO ENCODING:

Finally! Now we can encode our final video!

For this I use Blender. Yes, another free and open-source piece of "goldware". Blender is mostly used for 3D CGI graphics, but it's also an amazing animation and video editor.

You can download it for free for Linux, mac and Windows here:

http://www.blender.org/


Once I fire up Blender, I go to the render/output settings first, they are on the right hand side of the initial pane:


 I enter the output format there for the 1080HD video encoding settings, these are about the best I have found balancing both quality and file size:

Select HDTV 1080p from the dimension presets
Then choose 29.97 FPS from the frame/rate list
Then you want to choose where to output your encoded video
Select H.264 as output format
Select Quicktime and DNxHD as the CODEC
In the default bitrate I usually use 220,000 and 220,000 in Maximum, I leave 0 in Minimum, I leave the rest in default values.

These settings will give me a nice 1X size video in high quality Quicktime format with a final size of about 500MB

For smaller video sizes you can play with the settings, if you will post your videos in Youtube or Instagram MP4 or smaller settings in Quicktime will usually do. You will have to google up a bit about all these settings.

When I post on instagram I usually do the final on MPEG-4 with bitrates not higher than 16,384, even if you won't add sound you should encode with audio because Instagram will fail to post your video without audio encoded into it.

If you plan to add some audio it's best to select AAC with a bitrate of 192

Next is to switch to the Video Editing view:

 



And import your "deflickered" photos...

 


Now you should have something like this:

In this part you should set the end point of your time line to line up exactly where the last shot or frame is located. Also in this part you can do extra things, you can even load other time-lapse shots and blend them with nice fade-ins and outs, and put titles or whatever comes to mind, mixing with some nice music is always nice, you can even still correct or change some colors or brightness/contrast of the final video here. You will really have to get into the Blender user manual to learn all this.

You can go back to the default view and hit the "Animation" button and just wait until your encoded video is done, it will be saved where you told it to output it:


And you should now have a beautiful nice time-lapse that should look something like this, actually it should look better than this version of mine, because this is encoded at a much lower quality for you to be able to view here, otherwise, if I posted the real +500MB video, it would take a lifetime to download for you to view :)






Something I like to do before I delete all these huge amount of shots after creating my final time-lapse video, is to blend some of them together to create a long exposure simulated shot as a personal "memoir" for each time-lapse I do. In the example below I blended the first 200 shots in "average" mode to get a nice long exposure effect. I love to do them mostly in B&W because they look more dramatic:




I really hope this guide helped you somehow, I know I could of explained a lot more things like what exactly I do in Darktable to edit the shots or more on Blender, but this guide could become just a bit too more complex than what it already is, besides I think it's always good to leave a lot open for experimentation, but you can see it really isn't that hard, just a bit tedious as I said before.

If you do a time-lapse with the help of this guide I would really love to see it! So please share!

If you are on Instagram you can follow me there if you wish! My name there is @joegiampaoli

Happy Time-lapsing!




19 comments:

  1. Thanks for the nice write-up!
    I didn't know that you can use Blender for video editing! I only used kdenlive so far.

    Eventually I uploaded the deflickering script at github so you can always find the latest version (although I haven't really done many changes to the script) here: https://github.com/cyberang3l/timelapse-deflicker

    Vangelis

    ReplyDelete
  2. Hey Vangelis! Son wonderful to hear from you! I will later change, update or add an additional link to your script so users can always have the latest updated version. It's a great script and it gets the job done!

    Absolutely! Blender has gone a long way, surprises me with all the things you can do with it now!

    Cheers!

    Joe Giampaoli

    ReplyDelete
  3. With ffmpeg you can do this from the command line:

    ffmpeg -f image2 -pattern_type glob -i '*.jpg' -c:v libx264 foo.mp4

    The default is 25fps.

    ReplyDelete
  4. Check out Pixelio-helpfull device with shooting 360 timelapse, video, photo.

    Pixelio can become a portable laboratory for 3D scanning and a mobile
    mini photo studio. It also offers a number of new features that similar
    older devices did not have. Compatible with GoPro, all smartphones.
    http://www.smart-3d.co

    ReplyDelete
  5. Thanks for the Perl script - hopefully I can load imagemagick and the perl libs on my mac to replace LRTimelapse (which I don't want to pay for), and probable leaving Adobe Creative Cloud and LR as well. I'm familiar with Darktable, have used Blender a lot, so the best news here is the deflicker script.

    ReplyDelete
  6. Hi Joe. I have just started experimenting with Darktable and I am amazed by this tool. There is a way to avoid getting down to the script level to export your images. You can select multiple files and have Darktable export each file while applying a style. The style can have all the rotate, crop and levels settings.

    You mentioned you like to create a picture from a blend of "the first 200 shots in "average" mode". What program are you using to do this average function. Is it Darktable or Blender or some other tool. You are doing some great work.

    ReplyDelete
    Replies
    1. Hey Mike! Thanks for your reply! I remember doing it that way, but for some reason I opted by doing it with the command line and I don't remember if it was because Darktable would take longer or something, but I think it has to do by the amount of shots, and RAM isn't really an issue for me, but anyway, I'll give it a shot sometime and if all goes well I'll might update my blog with that info.

      For blending: I use "enfuse" which is one of "Hugin's" included libs or tools. If you have Hugin Panorama maker chances are you already have it, installed, if not this is where you can get it:

      http://enblend.sourceforge.net/

      It's a command program so you'll have to check out how to do it.

      Another approach is using Luminance-HDR, load all the shots (be warned, it uses a lot of RAM and can freeze your PC with too many shots, so the more RAM the better for this one), then I do very slight tone mapping, nothing to exaggerated, export to a 32 bit tiff (maybe 16 bit, but not 8) and load it in Darktable and work it like any regular photo.

      Hope that helps and thanks again!

      Best luck with your time-lapses, they are most boring when shooting, but once you see the results, tears roll out of your eyes :D ha!

      Delete
  7. Hi Joe, A very good write up. Briefs each step of the timelapse creation in a crisp and easy to understand manner. Couples of things to note.

    1. Since rendering is thru blender, no need to resize the image to 1920x1080. Blender will automatically do it for you.

    2. I used to create timelapses using kdenlive until I moved over to Blender recently. You can do pan & zoom ( and many other things ) to your timelapse in blender like the one I have done here https://www.youtube.com/watch?v=F-CetHeBjxE. There is a nice series of tutorials on YouTube on how to use Blender as video editor by Mickeycal at https://www.youtube.com/playlist?list=PLjyuVPBuorqIhlqZtoIvnAVQ3x18sNev4. May be of some help for people reading this blog, I learned most about blender video editing from watching those tutorials.

    ReplyDelete
    Replies
    1. Hey! Thanks for dropping by! That's a really neat time-lapse!

      Actually yes, I have been playing more with blender video editing and have seen how I can adjust cropping sizes and areas with layered transformations. I have done it already with a panning effect similar to yours. Mine just goes scrolls from the bottom to the top but the result is quite impressive, does look like a camera tilt. When I have some time I'll might update my blog with that. Thing is that I also want to keep it as simple as possible for other readers. Some people have to get their feet wet with blender, and at first sight, it's a very intimidating program.

      Take care and thanks again! Glad you liked this post!

      Delete
  8. Hi Joe, I would really like to know how you did layered transformations in Blender. Hope to see a blog post from you sooner.

    I came to know about your blog from the link posted in timelapse-deflicker github page.

    ReplyDelete
  9. Hi Joe - I am really new to all this but took the time to read your blog. Just writing to say thanks! Good luck, Jamie

    ReplyDelete
  10. Joe,
    que impresionante trabajo haz hecho explicando como hacer time-lapses en Linux.
    Muchas gracias y por favor sigue publicando.
    Alejandro
    Santiago - Chile

    ReplyDelete
    Replies
    1. Gracias a ti por tu comentario. Que bueno que te haya servido de algo. Saludos!

      Delete
  11. Pretty solution. Blender is a hard tool to handle, i spent nights more than 10 years ago to make some 3D videos… that was amazing. Even with this my background, i did search a few minutes to find where to click to add the images, and where to find the «animation» button :-D Maybe it would help to add a few more screenshot to point some of the buttons / list / fields to click or type in. Thanks for this page :)

    ReplyDelete
  12. Hi Joe, I loved the tutorial. Blender took a while to figure out so I made a screencast: https://www.youtube.com/watch?v=NNsSz8lF4Uc

    ReplyDelete
  13. Thanks for providing this informative information you may also refer.
    http://www.s4techno.com/blog/2016/07/15/write-command-find-files-accessed-within-last-30-days/

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. Thanks a lot for this guide. As a Linux user this was an excellent help. I've followed the steps and got manage to produce a "not-to-be-ashamed-of" time lapse.
    Best regards.

    ReplyDelete
  16. Clear & intuitive graphical user interface
    Reliable and professional software offers quick and easy Binary Trading Software to handle interface that really helps to save time. Users to don't need to invest time learning new controls and top features of the program.

    ReplyDelete