====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
peripherals:camera:timelapse [2016/05/21 03:13]
admin [Power Management]
peripherals:camera:timelapse [2017/03/01 18:19]
admin [Convert / Modify images before combining]
Line 14: Line 14:
 ===== PiCamera Timelapse Code ===== ===== PiCamera Timelapse Code =====
  
-Before going further, be sure to have the [[peripherals:​camera#​picamera|picamera python library installed]] on your Raspberry Pi. +Before going further, be sure to have [[:​peripherals:​camera#​activating_the_camera|the camera activated]] and the [[peripherals:​camera#​picamera|picamera python library installed]] on your Raspberry Pi. 
  
 ==== Python Script ==== ==== Python Script ====
Line 172: Line 172:
 ===== Power Management ===== ===== Power Management =====
  
-Before we automate the file transfer process, it might be interesting to have a look at our system's power consumption. ​A few points must be taken into account here that, in regard ​to each particular use-case, they will help one decide on the most appropriate solution to use.+A timelapse system will often have to work as a standalone solutionrunning on batteries. Therefore ​it's probably ​interesting to consider reducing it's power consumption. ​Some possible options ​to do this are described in [[:power|the Power Management page of this wiki]].
  
-  - Does the system require a network (or Internet) connection? 
-  - Should the system care about power consumption (running on batteries)? 
-  - What is the //value// of each newly taken photo? 
-  - How much storage space is available on the embedded system? 
  
-__**No Network (or Internet) Access**__ 
- 
-If your timelapse system doesn'​t have a network, or Internet, connection at all, the question shouldn'​t even be asked. You'll have to bring back the beast (or at least it's SD card), and use one of the below mentioned methods to access the images. 
- 
-The main parameter in this scenario will most probably be the available embedded storage space. For example having a 15sec timelapse at maximum resolution (Pi Camera v1: 2592x1944), will generate a jpg file weighting about 3MB every 15sec. This would saturate a 16GB SD card in about 16h30m... Way before you battery pack goes out! 
- 
-**Side note**: When the SD card gets saturated, and there is //really// no more space left on it, the OS itself will get inoperable. This is because it requires a minimum amount of storage space to function. For example trying to issue any command on a RasPi'​s console while running on a saturated SD card will return: 
-<​Code:​bash>​ 
-> -bash: cannot create temp file for here-document:​ No space left on device 
-</​Code>​ 
- 
-At this stage your only option will be to plug the SD card into a reader on another platform and erase at least a few of the images. 
- 
-__**"​Costly"​ Internet Access (like GSM 3/4G)**__ 
- 
-In case you have a "​costly"​ connection, like a GSM stick holding a 3/4G SIM card, you'll probably want to minimize the bandwidth usage. 
- 
-Covering the subject of optimizing Internet access while using a 3/4G GSM connection is outside the scope of this article but a starting point would be the following [[http://​www.kinisi.cc/​blog/​2015/​8/​9/​getting-cellular-gsm-internet-on-your-raspberry-pi-in-15-minutes|Get Cellular (GSM) Internet on your Raspberry Pi in 15 minutes article]]. 
- 
-I'll try to give a more in-depth coverage of this point whenever I get the opportunity to access the required hardware. 
- 
-__**Reduced Power Consumption**__ 
- 
-This article assumes we're working on any //Raspberry Pi Model B//, fully equipped with network adapter, USB ports and HDMI. //Pi Zero// and //Model A// are already built in such ways that their power consumption is much lower than Model Bs. 
- 
-__Network and USB adapters__ 
- 
-The power hungry monsters in the Raspberry Pi are certainly the USB and Network Adapters. They were reported to consume as much as 200mA! Since they'​re not mandatory for our timelapse system to function, we're better turning them off to enhance our system'​s autonomy when running off a power bank. 
- 
-__//USB//__ 
- 
-To switch the USB bus on a RasPi one can use the following commands: 
-<​Code:​bash |**Turn off USB** on the Raspberry Pi:> 
-> echo 0x0 > /​sys/​devices/​platform/​bcm2708_usb/​buspower 
-</​Code>​ 
- 
-When you need to turn it back on: 
-<​Code:​bash |**Turn on USB** on the Raspberry Pi:> 
-> echo 0x1 > /​sys/​devices/​platform/​bcm2708_usb/​buspower 
-</​Code>​ 
- 
-__//Network Adapter//__ 
- 
-To switch the network adapter on a RasPi one can use the following commands: 
-<​Code:​bash |**Turn off Network Adapter** on the Raspberry Pi:> 
-> /​etc/​init.d/​networking stop 
-</​Code>​ 
- 
-When you need to turn it back on: 
-<​Code:​bash |**Turn on Network Adapter** on the Raspberry Pi:> 
-> /​etc/​init.d/​networking start 
-</​Code>​ 
- 
-Of course, turning off the network adapter will prevent you from accessing the RasPi from any remote workstation.\\ 
-<color darkorange>​**Be aware that turning off both the USB and network adapters might lockout your entire RasPi system!**</​color>​ 
- 
-__//​HDMI//​__ 
- 
-Referring to [[http://​www.pidramble.com/​wiki/​benchmarks/​power-consumption|this article concerning Raspberry'​s models power consumption]],​ we observe that HDMI and LED usage are using about 30 mA (for a RasPi 3). Another [[http://​www.mikeslab.net/?​p=455|interesting article about RasPi'​s power consumption]] states that turning off HDMI in a "​headless"​ configuration saves about 20mA. 
- 
-To turn off HDMI on the RasPi, simply issue this command: 
-<​Code:​bash |**Turn off HDMI** on the RasPi:> 
-> sudo /​opt/​vc/​bin/​tvservice -o 
-</​Code>​ 
- 
-Unfortunately this command won't survive a reboot, so if we known the system is going to be headless we should trigger this on each boot. 
 ===== Accessing Recorded Timelapse Images ===== ===== Accessing Recorded Timelapse Images =====
  
Line 330: Line 260:
 ---- ----
 ==== 4- Process files on the Raspberry Pi ==== ==== 4- Process files on the Raspberry Pi ====
-----+**Note:** all recommendations hereafter are based on a [[:​os:​minibian|Minibian install]] (2016-03-12-jessie), it is supposedly very close to Raspbian but we haven'​t have the opportunity (yet) to test if all works the same on Raspbian. 
 + 
 +=== A View image files with FIM === 
 + 
 +There is a nice piece of software called [[http://​www.nongnu.org/​fbi-improved/​|FIM]] that allows to visualize image files straight into the Linux shell! 
 + 
 +We'll follow the [[http://​www.nongnu.org/​fbi-improved/​|Download and build instructions]] from the FIM website: 
 + 
 +<​Code:​bash |Download and install FIM> 
 +> wget http://​download.savannah.nongnu.org/​releases/​fbi-improved/​fim-0.5-rc1.tar.gz 
 +> wget http://​download.savannah.nongnu.org/​releases/​fbi-improved/​fim-0.5-rc1.tar.gz.sig 
 +> gpg --search '​dezperado autistici org' 
 +# import the key from a trusted keyserver by following on screen instructions 
 +> gpg --verify fim-0.5-rc1.tar.gz.sig 
 +</​Code>​ 
 + 
 +We'll need a few additional packages to go on: 
 +<​Code:​bash |Install FIM required packages:>​ 
 +> apt-get install gcc gcc-c++ g++ build-essential flex bison libreadline-dev libexif-dev 
 +> ./configure  
 +> make -j 6 
 +> make install 
 +</​Code>​ 
 + 
 +**Notes:​** 
 +  * although ''​libreadline-dev''​ was installed we had to use the ''​--disable-readline''​ option to be able to configure 
 +  * we used ''​make -j 6''​ to take advantage of the 4 cores in the Pi3 ([[https://​www.raspberrypi.org/​forums/​viewtopic.php?​f=29&​t=103001|see this]]) 
 + 
 +=== B - Install ffmpeg on The RasPi ===
  
 This will require us to install ffmpeg on the Raspberry Pi. The process for doing this is described on [[http://​www.jeffreythompson.org/​blog/​2014/​11/​13/​installing-ffmpeg-for-raspberry-pi/​|jeffreythompson.org'​s blog]]. This will require us to install ffmpeg on the Raspberry Pi. The process for doing this is described on [[http://​www.jeffreythompson.org/​blog/​2014/​11/​13/​installing-ffmpeg-for-raspberry-pi/​|jeffreythompson.org'​s blog]].
Line 361: Line 319:
  
 We now have a //​my_timelapse.mp4//​ movie which is full HD (1920×1080). We now have a //​my_timelapse.mp4//​ movie which is full HD (1920×1080).
 +
 +==== Convert / Modify images before combining ====
 +----
 +
 +Sometimes it may be suitable to adjust,​convert or otherwise modify images before they are integrated as a movie.
 +
 +[[https://​www.imagemagick.org/​script/​convert.php|ImageMagick]] offers a set of command line tools that can be used to manipulate images from the command line. In the following example, we're going to ''​convert''​ all captured images to grayscale, it's also called desaturate. Therefore, we'll be using the imagemagick ''​[[https://​www.imagemagick.org/​script/​convert.php|convert]]''​ command. To enhance the output result, we'll also make use of the ''​-normalize''​ option.
 +
 +Here is how to **convert a single file**:
 +<​Code:​bash|Single file conversion>​
 +> convert my_originals/​img01.jpg -colorspace Gray -normalize my_converted/​img01.jpg
 +</​Code>​
 +
 +Here is how to **batch convert multiple files** at once:
 +<​Code:​bash|Multiple files conversion>​
 +> for f in my_originals/​*.jpg ; do convert "​$f"​ -colorspace Gray -normalize "​my_converted${f%my_originals}"​ ; done
 +</​Code>​
 +
 +Another interesting usage of ImageMagick here would be to "water mark" all images before integrating them into the movie, your timelapses can be "​signed"​ using this method.
 ==== MP4 Optimization for Web Streaming ==== ==== MP4 Optimization for Web Streaming ====
 ---- ----
Line 368: Line 345:
 ---- ----
  
-Using all of the above, sticking the camera equipped Raspberry Pi to my bedroom window with the Romoss battery pack charged at 45% here is what came out as the final timelapse video:+Using all of the above, sticking the camera equipped Raspberry Pi to my bedroom window with the Romoss battery pack charged at 45% here is what came out as the final timelapse video. Please note that it is the original video here which was cut in length (only showing a selected 50secs sequence) but hasn't been optimized for web streaming, you can play it full screen to judge of the effective quality (1920x1080): 
 + 
 +{{:​peripherals:​camera:​boulevard2-cut.mp4}}