Sunday, 8 May 2016

Sunset timelapse: Raspistill vs PiCamera

There two ways (that I know of)  that the Raspberry pi camera can be triggered to take a still image, using Raspistill, or PiCamera.  PiCamera is a python interface for the Raspbery Pi camera. Raspistill can be called from the command line [or... within a python script using os.system("raspistill commend etc").

My preliminary attempts at sunrise timelapses using PiCamera have lead to over exposed skies, with all the details blown out.  This side by side comparison compares:  PiCamera (LEFT) to Raspistill (RIGHT).  

These timelapses are made from a consecutive series of alternate jpgs (PiCamera then RaspiStill) on default settings, as follows (I've left out any referenced variables to stop it getting too unwieldy):
PiCamera
def imagePiCamera():

 with picamera.PiCamera() as camera:

  camera.led = False
  camera.resolution = (2592, 1944)
  camera.framerate = (1, 1)
  camera.vflip = False
  camera.hflip = False
  camera.quality = 100
  camera.exposure_mode = 'auto'
  camera.awb_mode = 'auto'
  camera.image_effect = 'none'
  camera.color_effects = None
  camera.start_preview()
  time.sleep(2)
  camera.annotate_bg = True
  camera.annotate_text = dt.now().strftime('%Y-%m-%d %H:%M:%S')
  camera.capture(folderToSave + "/" + s_fileSerialNumber + "_PiCamera.jpg")

RaspiStill
def imageRaspiStill():    
 os.system("raspistill -w " + str(imgWidth) + " -h " + str(imgHeight) + " -o " + str(folderToSave) + "/" + s_fileSerialNumber + "_imageRaspiStill.jpg --nopreview -awb auto") 

My take on this is that I get a better sky / sun using RaspiStill, which is a bit of a disappointment since I like being able to annotate with text (as you can see in the PiCamera version (LEFT)... which is no use in a timelapse, I just forgot to switch it off...)

For interest, the 'grouped per-method' images are make into a video as follows:
#rename files
aa=0;for i in `ls`; do sudo mv $i `printf "%04d" $aa`.jpg; aa=$(($aa+1));done
#make timelapse
avconv -r 24 -i %04d.jpg -r 24 -vcodec libx264 -crf 20 -g 15 output.mp4

I got fed up waiting for this to run on my Raspberry pi, so run it on a linux virtual machine through virtualBox on a windows PC = much faster.  The RaspPi3 will compile a 800 image timelapse in approx 30 min using this approach.  Takes me approx 1 min using the other approach.

For the comparison... A side-by-side stitch of the two sunset timelapses as follows:
ffmpeg -i timlapse_PiCamera.mp4 -i timlapse_RaspiStill.mp4 -filter_complex \
'[0:v]pad=iw*2:ih[int];[int][1:v]overlay=W/2:0[vid]' \
-map [vid] -c:v libx264 -crf 23 -preset sideBySide.mp4