Latest:
- Sailfish OS and memory
- Hillshade tile server
- Statistics of OSM Scout for Sailfish OS
- Nebezpečný router
- Tree model with Silica components
By month:
- November 2021
- January 2019
- December 2017
- December 2016
- May 2014
- April 2014
- November 2013
- April 2013
- April 2011
- February 2011
- January 2011
- August 2010
- May 2010
- March 2010
- January 2010
- October 2009
- April 2009
- February 2009
- October 2008
- September 2008
- August 2008
- April 2008
- March 2008
- February 2008
Topic:
Howto create time-lapse video in Linux
Some people in Avast had crazy idea – take all people from R&D (Research and Development), rent a plane and fly 2 200 km (1 400 miles) to north, for amazing teambuilding. This dream becomes true end of March this year. We spend 24 hours at Tromsø, Norway, north of Polar Circle. Our main goal was to see aurora borealis. Full story of this teambuilding is on Avast blog, nice photoreports in albums of Pepa Havlin and Honza Havelka.
I planned to create time lapse video with aurora from series of photos. Two years before, I used Kdenlive video editor for experimenting with time lapse, but result was not smooth. Transitions between photos are disruptive. I don't found any other tool with GUI with better results, so I decided to create video with set of standard command line tools. Some tool for process photo RAWs, ImageMagick for prepare movie frames and avconv for join frames to video.
Step 1: Process RAW photos to JPEGs
I setup my camera to take photo every 20 seconds with 10 seconds explosure and ISO sensitity to 1 600 (aperture F3.5).
First step is convert many RAW photos from camera to jpeg. I tried RawTherapee, RawStudio and UFRaw. I have best experience with UFRaw, that is able minimize noise and support batch processing.
ufraw-batch --conf=aurora_ufraw.xml --out-type=jpeg --compression=100 --exif --out-path=./jpegs *.NEF
Step 2: Resize images to final video resolution
This step is simple. For change resolution of many images is the best tool
convert
from project ImageMagick.
#!/bin/bash res=1920x1080 echo "resize to $res..." mkdir -p resized i=1 for f in `ls -1 jpegs/*.jpg` ; do num=`printf "%0*dn" 4 $i` convert $f -resize $res! -quality 100 ./resized/$num.jpg i=$(( $i + 1 )) done max=$i
Step 3: Create smooth transition between frames
If we want create one minute video with 15 fps (900 frames) from series, that was one hour long originaly and we take photo each 20 seconds (180 photos), we have to use one photo for 5 video frames. In order to smooth result, we have to „morph“ two images to 5 frames transition…
#!/bin/bash mkdir -p morphed i=1 while [ $i -lt $(( $max - 1 )) ] ; do num=`printf "%0*dn" 4 $i` num2=`printf "%0*dn" 4 $(( $i + 1 ))` convert resized/$num.jpg resized/$num2.jpg -quality 100 -morph 4 ./morphed/${num}_%05d.jpg i=$(( $i + 1 )) done
Step 4: Create video from frames
We can use avconv
utility for joining frames to video. (Avconv
is fork of ffmpeg
, so we can use ffmpeg too,
but arguments can be unlike.)
#!/bin/bash fps=15 res=1920x1080 bitrate=40000k echo "rename for avconv..." i=1 for f in `ls -1 morphed/*.jpg` ; do num=`printf "%0*dn" 6 $i` mv $f morphed/$num.jpg i=$(( $i + 1 )) done echo "process with avconv..." avconv -f image2 -r $fps -s $res -i morphed/%06d.jpg -b:v $bitrate -c:v libx264 -r $fps video.mkv