Avoiding CCTV image loss due to mains power fail

Whilst it's relativly simple matter to add a battery pack to keep the Pi CCTV running, a total mains power failure will likley take out your LAN and all the computers on it. So, to avoid CCTV being lost due to mains failure, you need to write them to the Pi SDHC card (before sending them across your LAN). Writing and reading the CCTV A class 4 card (4mbs = 32mbps) is only just able to cope with HD movie 'one way'. So if you expect your CCTV to deliver 30fps HD resolution, you may have to 'get clever' with RAM disks (since you can't just write to SDHC and then read back from SDHC to the LAN) A class 10 SDHC will support data rates of at least 10 MB/s (80mbps) with some achieving double that (i.e. 160 mbps, still well within the Pi limit i/o of approx 320mbps). Whilst a class 10 SDHC can support simultaneous reading with writing of two full 1080p data steams, even an over-clocked 1GHz Pi CPU will be hard pressed to find sufficient CPU cycles to do much processing of that data. HD at 1080p, 18mpbs, uses 8 Gb per hour (domestic DVR's typically use half that - which shows how poor the 'broadcast' quality of HD really is ...). Of course HD data rates depend on the level of compression used. Whilst the Bluray specification supports up to 30Mbps, for standard quality MPEG-4 AVC(h.264) Video at 1080p the data rate will be no more than 18 Mbps (Mega bits per second). For 720p, it will be less than half that (8 Mbps). The actual Pi HD 1920×1080 data bit-rate is 17Mbs (or about 7.5Gb/Hr), however whilst this can be written direct to SDHC that's without adding any 'headers'. Needless to say, adding .mp4 'wrapper' to a movie clip will require yet more reading and re-writing ('raw' file read, movie with header write) ! However this does let us calcy=ulate that a 32Gb SDHC card can hold about 2.5 Hrs of movie data - so your UPS battery backed Pi only needs to keep running for that time. Still frames Recoding still frames 'raw' (using 'raspistill --raw', which gets you the JPEG with a packed binary RAW data block appended) requires typically 10 MB a shot. This gives you maximium possible quality CCTV but is going to chew up your SDHC space even faster and a class 10 SDHC is only 'guaranteed' to support 10Mbytes/sec (although many will do 20) so at 'full speed' you will be lucky to get 1 (or 2) shot(s) per second ! If we go for (M)JPEG it's about 2Mbytes per (5M pixel full frame) photo so with the best class 10 SDHC, you could get up to 10 frames a second. However that's going to chew through (2x10x60=1200) over 1Gb a minute (so a 32Gb card will get you less than half an hour). Of course, to keep the storage requirement down, the Pi can use 'motion detection' - however detecting motion (even with the Pi CPU working off thumbnails - taken at the same time as the 'main' photo**) will result in 5 seconds a frame (rather than 5 frames a second !), so you might be better just storing 'everything' and sorting out the 'motion detection' later. **For more on the Pi camera modes, see below.