The previous post shows you pictures of a thunderstorm, and how to create a composite from the images. This one shows you how to make a video from the images.
Two week-ends ago, a fairly strong thunderstorm struck, with clear views from my window. I mounted my camera on a tripod, and I took close to 1000 shots in about 45 minutes, each with 2 seconds exposure.
The previous post shows you some sample pictures, as well as a composite of many lightnings.
Composite shot, see previous article. |
The idea is therefore to create some burn-in effect, where the bright lightning stay for a number of frames, slowing fading away. The resulting video is below (go to Vimeo for higher resolution):
.
Technique
The first step to create a video is to resize the images to HD format, that is 1080p (1920x1080):
mkdir sm1080
ls *.JPG | xargs -I{} convert -crop 4380x2464+143+67 -resize 1920x1080 -quality 95 {} sm1080/{}
I also do a bit of cropping, as my original framing shows some of the wall next to the window.ls *.JPG | xargs -I{} convert -crop 4380x2464+143+67 -resize 1920x1080 -quality 95 {} sm1080/{}
We then add the required "burn-in" effect, so that bright light will appear quickly, and slowly fade away. I tried several methods to create this effect, but this very simple method seems to work best:
- Get the maximum between the last output frame and the current frame.
- Blend this maximum image with the current frame (93% maximum, 7% current): this is your next output frame.
- Iterate on the next input frame.
I tried different parameters, 90% made lightnings appear for a too short duration, and 95% led to significant artifacts: 93% seems to be a sweet spot.
This simple Ruby script, that calls ImageMagick, does the job for you:
#!/usr/bin/ruby
list = Dir.new(".").to_a.select{|x| x.match(/.*\.JPG/)}.sort
system("mkdir output")
system("rm output/*")
system("cp #{list[0]} output/#{list[0]}")
list.each_cons(2){|k1, k2|
system("convert output/#{k1} #{k2} -evaluate-sequence max output/max-#{k2}.tiff")
system("composite output/max-#{k2}.tiff #{k2} -blend 93% output/#{k2}")
}
I output the maximum images as TIFF, as to avoid additional JPEG compression artifacts.list = Dir.new(".").to_a.select{|x| x.match(/.*\.JPG/)}.sort
system("mkdir output")
system("rm output/*")
system("cp #{list[0]} output/#{list[0]}")
list.each_cons(2){|k1, k2|
system("convert output/#{k1} #{k2} -evaluate-sequence max output/max-#{k2}.tiff")
system("composite output/max-#{k2}.tiff #{k2} -blend 93% output/#{k2}")
}
It is easy to check out the resulting video with mplayer:
mplayer mf://sm1080/output/*.JPG -mf fps=25:type=jpg
Once you are happy with the results, you can then encode the output (I chose highest quality x264 encoding):
mencoder mf://sm1080/output/*.JPG -mf fps=25:type=jpg -ovc x264 -x264encopts preset=veryslow:tune=film:crf=15:frameref=15:fast_pskip=0:threads=auto -o video.avi
The video can be seen in 720p on Vimeo, and in 1080p on Youtube (unfortunately, Youtube does not let me choose a good thumbnail image, so I switched to Vimeo for this reason).
No comments:
Post a Comment