Page 1 of 6 123 ... LastLast
Results 1 to 10 of 57

Thread: HOWTO: Make Time Lapse Videos from Photographs

  1. #1
    Join Date
    Nov 2005
    Location
    Athens,Greece-Oslo,Norway
    Beans
    366
    Distro
    Kubuntu

    Post HOWTO: Make Time Lapse Videos from Photographs

    After looking around, searching, reading and experimenting, I ended up with a bunch of commands to quickly make high quality time lapse videos under Linux. One of the hardest (almost impossible) things to find, is software for photo deflickering so for solving this (or at least improve the results), I created my own little Perl script to compute and change the average luminance (brightness) of all of the photographs.

    If some of the commands below are not working, you might need to apt-get install some extra software, but all of it is available in the repositories

    A Quick Introduction to Time Lapse Videos
    From Wikipedia: Time-lapse photography is a technique whereby the frequency at which film frames are captured (the frame rate) is much lower than that used to view the sequence. When played at normal speed, time appears to be moving faster and thus lapsing. For example, an image of a scene may be captured once every second, then played back at 30 frames per second. The result is an apparent 30-times speed increase. Time-lapse photography can be considered the opposite of high speed photography or slow motion.


    How to take good pictures to compose a time lapse video afterwards
    The rest of the steps might not be reproducable with compact point and shoot cameras.

    Tripod
    First of all the camera needs to be very stable between shots to make the composition easy later on, therefore, a tripod needs to be used.

    Intervalometer
    Choose how many total pictures need to be taken and set your camera to take one picture every some predefined interval (for example one every 5 seconds). This can be done either with computer software, or the camera itself. Some cameras have a built in intervalometer or they can accept external accessories.

    Calculate Final Video Length
    If you choose to take 300 pictures, and you make a final video running at 10 frames per second, then your video will be 30 seconds long (300/10=30s). At 25 frames per second, the same video will be only 12 seconds long (300/25=12s). It is a good idea to plan the desired length for your video beforehand, and take some more photographs to achieve a smoother movement with higher frame rates (especially when moving objects are near your camera).

    Camera Settings
    For a good time lapse video, the camera needs to be set to Manual mode and choose a non changing Aperture (A), Shutter speed (S), ISO and Focus. This will reduce flickering (different brightness between pictures) a lot as the overall brightness of the pictures will not be changing between shots.
    What I usually do, is that I put the camera on the tripod and take pictures in auto mode until I am satisfied with the result. Then I look at the chosen from the camera settings (A, S, ISO), change the mode to manual and use the same settings as the camera did in auto mode. The auto focus is used to focus on the main object properly, and before starting the intervalometer, I change it to manual focus as well as the other settings, because all of the pictures need to have exactly the same focus.

    There are certain cases (sunset is one of them) that lighting conditions might change a lot during your shots, and a fixed set of A, S and ISO settings might not give good results after sometime. In this case, I always choose a stable Aperture to avoid changes in the depth of field (DOF), ISO and focus, and let the shutter speed vary (Usually the A or Aperture mode of your camera can do this). This technique will introduce more flickering because the exposure metering of your camera will calculate slightly different values sometimes.

    Making the Video
    This is the actual purpose of this tutorial. To show you how to use Linux to put everything together fast.

    Step 1
    Make a new folder and copy all of your photographs taken for the time lapse into it. Sort the images by capture date/time and store them in a new folder called "renamed". This is useful if your camera messes up the filename ordering when it starts counting from 0001 after reached the highest possible number (e.g. ..., DSC_9998, DSC_9999.jpg, DSC_0001, DSC_0002).

    Code:
    mkdir source_folder_of_pictures
    cp /media/cf/* source_folder_of_pictures/
    cd source_folder_of_pictures
    mkdir renamed
    counter=1
    ls -1tr *.jpg | while read filename; do cp $filename renamed/$(printf %05d $counter)_$filename; ((counter++)); done
    cd renamed
    Step 2
    Resize the images first to 1920x1080 to get a Full HD output or 3840x2160 if you need 4K output. All the rest of the operations will be much much faster if you do this now since you will be working with smaller sized files.

    Code:
    mkdir resized
    mogrify -path resized -resize 1920x1080! *.JPG # If you want to keep the aspect ratio, remove the exclamation mark (!)
    # You can also use the mogrify from graphicsmagick package which is faster, I use it in combination with the command "parallel" in order to utilize all of my CPU cores and perform the resize much faster.
    # Of course, you can use the command "parallel" with the imagemagick mogrify
    # parallel --progress gm mogrify -quality 100 -output-directory resized -resize 1920x1080! ::: *.JPG # Similar as before, remove the exclamation mark in order to keep the aspect ratio.
    cd resized
    Step 3 (OPTIONAL)
    If you photos have noticeable flickering which is caused by slightly different exposure between taken photos, download the attached script, put it in the directory source_folder_of_pictures/renamed/resized/, make it executable and run it. The script will create a subdirectory "source_folder_of_pictures/renamed/resized/Deflickered" to store the processed photos.
    You can get the latest version of the script at https://github.com/cyberang3l/timela...e-deflicker.pl

    Code:
    sudo apt-get install libfile-type-perl libterm-progressbar-perl
    chmod +x timelapse-deflicker.pl
    ./timelapse-deflicker.pl -h
    ./timelapse-deflicker.pl -v
    cd Deflickered
    Step 4
    Use ffmpeg to combine all of the photos in one video without losing quality! This will create a big file as it will only put all of the JPG files together in a single uncompressed video. Change the "-r 25" in the following command, to match your frames per second you wish to get in the final video.
    Note: Use ONLY ONE of the following 3 commands. I usually choose the first one if I am working with jpeg files, as it will simply copy the source images and each one will occupy one frame in the resulting video. It is also ultra fast since it doesn't do any re-compression.
    Code:
    ffmpeg -r 25 -pattern_type glob -i '*.jpg' -c:v copy output.avi # Change -r 25 to define the frame rate. 25 here means 25 fps.
    # Alternative commands, but your jpeg images will be recompressed (maybe you want to use one of these if you have png or any other kind of images, or you want a smaller sized video)
    ffmpeg -r 25 -pattern_type glob -i '*.jpg' -c:v mjpeg -q:v 2 output.avi # -q:v can get a value between 2-31. 2 is best quality and bigger size, 31 is worst quality and least size)
    ffmpeg -r 25 -pattern_type glob -i '*.jpg' -c:v ljpeg output.avi # Lossless jpeg resulting in a huuuuuuuge file. Even larger in size than the sum of all of the input pictures together in the case of jpg images.
    Step 5 (OPTIONAL)
    Here you might want to use a non linear editor like kdenlive (which is the best non linear video editor I have found for Linux so far) to add some music to your video and introduce some effects (like smooth fade from black in the beginning of the video or fade to black in the end), but remember to export in a lossless quality format so that you won't get any noticable loss in quality.

    On my latest attempt to create a 4k video with kdenlive, I had to create a custom 4k project profile (accessible from Settings -> Manage Project Profiles)

    1.png

    and a custom rendering profile (Project -> Render -> Create new profile) with the following contents:
    Code:
    acodec=ac3 ab=448k ar=44100 ac=2 vcodec=libx264 crf=15 rc-lookahead=60 coder=1 flags=+loop cmp=+chroma partitions=+parti8x8+parti4x4+partp8x8+partp4x4+partb8x8 me_method=umh subq=10 me_range=24 g=250 keyint_min=25 sc_threshold=40 i_qfactor=0.71 b_strategy=2 qcomp=0.6 qmin=0 qmax=51 qdiff=4 bf=8 refs=9 directpred=1 flags2=+mixed_refs+dct8x8+fastpskip+mbtree cqp=0 wpredp=2 trellis=2 weightp=2 deblock=1:0:0 direct=auto muxer=auto aspect=%dar
    2.png


    Step 6
    Use ffmpeg to compress the video into a high quality Full HD one.
    Code:
    ffmpeg -i output.avi -c:v libx264 -preset slow -crf 15 output-final.mkv
    If you created a 4k video and you want to resize it to 1080p, use the following command:
    Code:
    ffmpeg -i output.mkv -s 1920x1080 -c:v libx264 -preset slow -crf 15 output-final.mkv
    Check here for more encoding options: https://trac.ffmpeg.org/wiki/Encode/H.264

    You should definitely take a look in this post from FakeOutdoorsman: http://ubuntuforums.org/showthread.p...6#post13191696
    You can find many nice tips.

    You are done!
    Congratulations! Enjoy and brag for your own time lapse video
    Attached Files Attached Files
    Last edited by CyberAngel; December 21st, 2014 at 11:34 PM. Reason: Updated information for 4k time lapse videos

  2. #2
    Join Date
    Aug 2005
    Location
    South Carolina, USA
    Beans
    26,047
    Distro
    Ubuntu Development Release

    Re: HOWTO: Make Time Lapse Videos from Photographs

    Awesome! I have been experimenting unsuccessfully with time lapse for some time now. I have used a variety of tutorials and have been disappointed with the result. I just tried your steps and, with one exception, found it perfect.

    I have been an interval shooter for some time and have been strict with aperture, shutter speed and ISO. I also hardly ever shoot any photographs without a tripod, even the cat! Accordingly, I skipped the deflicker step and can't say if it works or doesn't. All the other steps produced an excellent result. I appreciate your hard work and, moreover, your generosity in posting it here. I have bookmarked and printed your posting and can hardly wait to get out under the stars for three or four hours with my Nikon, some Irish coffee and my best gal!
    "Oh, Ubuntu, you are my favorite Linux-based operating system" --Dr. Sheldon Cooper, B.Sc., M.Sc., M.A., Ph.D., Sc.D.

  3. #3
    Join Date
    Nov 2005
    Location
    Athens,Greece-Oslo,Norway
    Beans
    366
    Distro
    Kubuntu

    Re: HOWTO: Make Time Lapse Videos from Photographs

    Makes me happy that this information was found useful for someone else except me

    Here are three videos I made with this technique:

    http://www.youtube.com/watch?v=lI75_Uce-2w
    http://www.youtube.com/watch?v=BWjC2KOZTIc
    http://www.youtube.com/watch?v=yWgASCOfHng

    The first two of them, use a variable shutter speed (you will see that the sun sets but the video is still bright) and for the 3rd one with the stars all of the settings are fixed. I wasn't out there with the camera and an Irish coffee though cause it was -20 degrees... I chose the cabin instead hehe

    None of these videos use the deflickering script as this is something I made a couple of days ago.
    The results of the deflickering script can be seen here:
    http://www.youtube.com/watch?v=SNfq__chC5M

  4. #4
    Join Date
    Aug 2005
    Location
    South Carolina, USA
    Beans
    26,047
    Distro
    Ubuntu Development Release

    Re: HOWTO: Make Time Lapse Videos from Photographs

    -20 degrees? But you use that funny centigrade there, don't you? You are right, that's cabin time for me, too. I usually quit about -10 C.

    Very nice work there! I enjoyed them all.

    Of course, this guy is the master: http://www.timescapes.org/ I love his moving stars. He uses a dolly for the camera, as well.

    I find myself doing more photography these days after midnight.

    Thanks again for your excellent tutorial.
    "Oh, Ubuntu, you are my favorite Linux-based operating system" --Dr. Sheldon Cooper, B.Sc., M.Sc., M.A., Ph.D., Sc.D.

  5. #5
    Join Date
    Nov 2005
    Location
    Athens,Greece-Oslo,Norway
    Beans
    366
    Distro
    Kubuntu

    Re: HOWTO: Make Time Lapse Videos from Photographs

    Quote Originally Posted by chili555 View Post
    -20 degrees? But you use that funny centigrade there, don't you? You are right, that's cabin time for me, too. I usually quit about -10 C.

    Very nice work there! I enjoyed them all.

    Of course, this guy is the master: http://www.timescapes.org/ I love his moving stars. He uses a dolly for the camera, as well.

    I find myself doing more photography these days after midnight.

    Thanks again for your excellent tutorial.
    Yes, we use Celcius here

    I didn't know timescapes.org! Indeed the master...

    Terje Sorgjerd is another great one! Take a look here:
    http://vimeo.com/terjes

  6. #6
    Join Date
    Apr 2006
    Location
    Addis Ababa, Ethiopia
    Beans
    Hidden!
    Distro
    Xubuntu

    Re: HOWTO: Make Time Lapse Videos from Photographs

    Hi CyberAngel,

    I was hoping to try your deflickering script but I ran into an error:

    Can't locate File/Type.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at ./timelapse-deflicker.pl line 25.
    BEGIN failed--compilation aborted at ./timelapse-deflicker.pl line 25.
    Any idea what I'm doing wrong or if there's anything I need to install?

    Thanks in advance,
    David

    Edit: Learnt how to install the necessary PERL modules. Running the script right now
    Last edited by dckirba; August 16th, 2012 at 07:48 PM. Reason: Figured it out ;)

  7. #7
    Join Date
    Nov 2005
    Location
    Athens,Greece-Oslo,Norway
    Beans
    366
    Distro
    Kubuntu

    Re: HOWTO: Make Time Lapse Videos from Photographs

    Quote Originally Posted by dckirba View Post
    Hi CyberAngel,

    I was hoping to try your deflickering script but I ran into an error:



    Any idea what I'm doing wrong or if there's anything I need to install?

    Thanks in advance,
    David

    Edit: Learnt how to install the necessary PERL modules. Running the script right now
    Nice that you found solved the problem on your own

    Did you see any improvement in the flickering?

  8. #8
    Join Date
    Apr 2006
    Location
    Addis Ababa, Ethiopia
    Beans
    Hidden!
    Distro
    Xubuntu

    Re: HOWTO: Make Time Lapse Videos from Photographs

    Quote Originally Posted by CyberAngel View Post

    Did you see any improvement in the flickering?
    I definitely did. I'm trying to upload both version on Vimeo and I'll post links here. I was shooting around sunset so I guess the lighting lends itself to even more flickering than usual Thanks for the script!

  9. #9
    Join Date
    Nov 2005
    Location
    Athens,Greece-Oslo,Norway
    Beans
    366
    Distro
    Kubuntu

    Re: HOWTO: Make Time Lapse Videos from Photographs

    Anyone knows why I cannot edit the first post to make some corrections?

    I ran into some problems for some time lapses with this line of code:

    Code:
    ls -1tr | grep -v files.txt > files.txt
    It should be:

    Code:
    ls -1 | grep -v files.txt > files.txt

  10. #10
    Join Date
    Jun 2011
    Location
    United Kingdom
    Beans
    Hidden!
    Distro
    Lubuntu Development Release

    Re: HOWTO: Make Time Lapse Videos from Photographs

    Quote Originally Posted by CyberAngel View Post
    Anyone knows why I cannot edit the first post to make some corrections?

    I ran into some problems for some time lapses with this line of code:

    Code:
    ls -1tr | grep -v files.txt > files.txt
    It should be:

    Code:
    ls -1 | grep -v files.txt > files.txt

    Hi CyberAngel,

    there are two points to make:

    1. There is now a post-editing limit in force. You are now only allowed to edit your posts before 7 days have elapsed.

    2. Tutorials and tips should now be made into wiki pages on the Ubuntu wiki: see http://ubuntuforums.org/showpost.php...64&postcount=1

Page 1 of 6 123 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •