Saturday, February 2, 2019

Time lapse video of stars moving through the sky

I made a time lapse video of stars moving through the sky.  I had 3 attempts that I stitched together into a video:

How

taking the photos

  • used a tripod
  • used a 30 second exposure
  • ISO setting was 200
  • f-number (aperture opening) was between 5 and 10
  • 1-3 seconds delay between photos
Bringing the camera in from the cold, the lens quickly frosted over, so after that I put the lens cover on every time I brought it in the house to prevent that.

creating the 1st card - the first image of the time lapse with text overlaid

convert attempt_01/orig/DSC_0623.JPG -font Arial -pointsize 144 -draw " gravity center fill white  text 1,11 '1st Attempt' " 1st_attempt_card.jpg 

Adapted from "Watermarking with Text" in the ImageMagick instructions.

creating the 2nd and 3rd cards - a script for creating crossfades between images

I came up with this script (using the command found here) to generate a series of images that crossfade between 2 original images - make_cross_fade.sh:
#!/bin/bash

start_image=$1
end_image=$2

framerate=$3 #number of frames per second
duration=$4 #in seconds - determines how many images are created - duration divided by framerate is number of images

ffmpeg -loop 1 -i "$start_image" \
     -loop 1 -i "$end_image" \
     -filter_complex "[1:v][0:v]blend=all_expr='A*(if(gte(T,$duration),1,T/$duration))+B*(1-(if(gte(T,$duration),1,T/$duration)))'" \
     -r $framerate \
     -t $duration image_%03d.jpg
Probably should also include another variable for zero-padding count :)

Creating the crossfade transitions

Used make_cross_fade.sh to create the crossfade images between the last image of attempt 1 and the first image of attempt 2:
make_cross_fade.sh ../attempt_01/orig/DSC_0653.JPG ../attempt_02/DSC_0659.JPG 4 3
4 is the framerate (4 frames per second)
3 is the duration, in seconds

Added text to these cards:

for a in image_0*; do new_name="2nd_attempt_card_$a"; echo $a $new_name; convert "$a" -font Arial -pointsize 144 -draw " gravity center fill white  text 1,11 '2nd Attempt' " "$new_name"; done
Making crossfade between 2nd and 3rd attempts ran into a problem - the orientation of the pictures was different.  Rotated the 3rd attempt pictures so they would be in landscape (from  here):

for a in DSC_0*; do new_name=rot_$a; echo $a $new_name; convert "$a" -rotate 90 $new_name; done
For some reason had to run the other image through imageMagick as well to get ffmpeg to work - rotated 360 so that it would effectively "do nothing":

convert ../attempt_02/DSC_0684.JPG -rotate 360 temp.jpg
Create the crossfade between the 2nd and 3rd attempts:

make_cross_fade.sh temp.jpg ../attempt_03/rot_DSC_0687.JPG 4 3
Add text to the above:

for a in image_0*; do new_name="3nd_attempt_card_$a"; echo $a $new_name; convert "$a" -font Arial -pointsize 144 -draw " gravity center fill white  text 1,11 '3rd Attempt' " "$new_name"; done

assembling links, assembling the video

Created a directory, populated it with symbolic links to the actual files, with the links named to have integer indexes and be in the desired order.

1st I added some links for the 1st card - since I'm using a framerate of 4, and I want the card to be on the screen for 3 seconds, needed 12 links - all to the same image:
for ((a = 0; a < 12; a++)); do link_name=image_$(seq -f "%03g" $a $a).jpg; echo $a $link_name; ln -s ../1st_attempt_card.jpg $link_name; done
Added links to the 1st attempt:

b=12; for a in ../attempt_01/orig/DSC_06*; do link_name=image_$(seq -f "%03g" $b $b).jpg; echo $b $a $link_name; ln -s "$a" $link_name; let b=b+1; done
b here is the counter variable, it starts at 12 b/c we created 12 links initially for the initial card.  We then loop through the individual image files of attempt 1, creating a link for each.

Create links for 2nd attempt cards - no need to set b this time since it is carried over from previous:

for a in ../2nd_attempt_card/2nd_attempt_card_image_0*; do link_name=image_$(seq -f "%03g" $b $b).jpg; echo $b $a $link_name; ln -s "$a" $link_name; let b=b+1; done
Add 2nd attempt images:

for a in ../attempt_02/DSC_06*; do link_name=image_$(seq -f "%03g" $b $b).jpg; echo $b $a $link_name; ln -s "$a" $link_name; let b=b+1; done
Add 3rd attempt card images:

for a in ../3rd_attempt_card/3nd_attempt_card_image_0*; do link_name=image_$(seq -f "%03g" $b $b).jpg; echo $b $a $link_name; ln -s "$a" $link_name; let b=b+1; done
Add 3rd attempt images:

for a in ../attempt_03/rot_DSC_0*; do link_name=image_$(seq -f "%03g" $b $b).jpg; echo $b $a $link_name; ln -s "$a" $link_name; let b=b+1; done
Assemble into a video:

ffmpeg -r 4 -f image2 -s 4496x3000 -i sym_links/image_%03d.jpg -vcodec libx264 -crf 25 -pix_fmt yuv420p temp.mp4
et voila!  The transitions were a disproportionate amount of work, but they made the video less jarring.  Not sure if I would both next time though.

No comments:

Post a Comment