Skip to content

jiinurppa/Raspi-Camera

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 

Repository files navigation

Raspi-Camera

Notes for Raspbian & Raspberry Pi Camera Module. Tested on Raspberry Pi 3 B+.

Watch Live Feed

Requirements: mplayer or mpv (for desktop)

  1. From desktop run either
    1. nc -l 8111 | mpv --no-correct-pts --fps=30 --no-audio - or
    2. nc -l 8111 | mplayer -fps 30 -vf scale=1920:1080 -nosound -cache 4096 -
  2. From Raspberry Pi run either
    1. pi_camera_server.py (instructions in file) or
    2. raspivid -t 0 -w 1920 -h 1080 -fps 30 -o - | nc desktop-ip-here 8111 (replace desktop-ip-here with correct IP)

❗ Get desktop IP with:

  • Linux: hostname -I
  • macOS: ipconfig getifaddr en0 (ethernet) or ipconfig getifaddr en1 (wifi)

Record Time Lapse Using raspistill

Requirements: External drive for pictures, screen, ffmpeg

These notes are for the NoIR module. If you're using a regular camera, remove the -awb greyworld option.

❗ I suggest disabling leds on the Raspberry Pi so you don't accidentally get reflections of them on camera:

  • Disable red PWR led by running sudo sh -c 'echo 0 > /sys/class/leds/PWR/brightness'
  • Disable green ACT led by running sudo sh -c 'echo 0 > /sys/class/leds/ACT/brightness'
  1. Install SunTime by running pip3 install suntime
  2. Create mount point for external drive with sudo mkdir /media/extusb
  3. Mount your external drive by running sudo mount -t auto /dev/sda1 /media/extusb
  4. Save the following script as timelapse.py or download it with wget https://raw.githubusercontent.com/jiinurppa/Raspi-Camera/master/timelapse.py:
#!/usr/bin/env python3
import os
import time
from datetime import datetime, timezone
from suntime import Sun, SunTimeException

# Setup Camera
quality = 100
width = 1920
height = 1080
amount = 1440
delay = 60
current_pic = 0
folder_path = '/media/extusb/timelapse'
# Setup Night Exposure
latitude = 61.49
longitude = 23.76
sun = Sun(latitude, longitude)

if not os.path.isdir(folder_path):
    os.mkdir(folder_path)

while current_pic < amount:
    start_time = time.perf_counter()
    command = f'raspistill -w {width} -h {height} -q {quality} -awb greyworld '
    night = False
    try:
        sunrise = sun.get_sunrise_time()
        sunset = sun.get_sunset_time()
        now = datetime.now(timezone.utc)
        if now < sunrise or now > sunset:
            command += '-ex night '
            night = True
    except SunTimeException as e:
        print('Can\'t determine sunrise or sunset')
    filename = f'{folder_path}/{current_pic:08}.jpg'
    command += f'-o {filename}'
    os.system(command)
    current_pic += 1
    timestamp = f'{datetime.now():[%H:%M:%S %d.%m.%Y]}'
    print(f'{timestamp} Captured picture {current_pic}/{amount} Night exposure: {night}')
    end_time = time.perf_counter()
    elapsed_time = end_time - start_time
    if current_pic < amount:
        time.sleep(delay - elapsed_time)

print('Time lapse done!')
  1. Change latitude and longitude to match your location
  2. Make script executable by running chmod u+x timelapse.py
  3. Start screen by running screen -S timelapse
  4. Run script with ./timelapse.py
  5. Detach from screen with Ctrl-a + d and let the script run in the background
  6. Check the progress by running screen -r timelapse, when it's done you should see Time lapse done!
  7. Exit screen with exit and run cd /media/exfat/timelapse
  8. Create a video by running ffmpeg -r 24 -f image2 -i %08d.jpg -r 24 -s 1920x1080 -c:v libx264 -preset slow -crf 20 timelapse.mkv

Record Time Lapse Using PiCamera (old)

Requirements: External drive for pictures, screen, ffmpeg

You'll get better results (and greyworld support) using the raspistill version above.

❗ I suggest disabling leds on the Raspberry Pi so you don't accidentally get reflections of them on camera:

  • Disable red PWR led by running sudo sh -c 'echo 0 > /sys/class/leds/led1/brightness'
  • Disable green ACT led by running sudo sh -c 'echo 0 > /sys/class/leds/led0/brightness'
  1. Create mount point for external drive with sudo mkdir /media/exfat
  2. Mount your external drive by running sudo mount -t auto /dev/sda1 /media/exfat
  3. Save the following script as timelapse.py:
#!/usr/bin/env python
import os
import math
from picamera import PiCamera
from time import sleep
from fractions import Fraction

# Setup
width = 1920;
height = 1080;
amount = 1440;
hold = 4;
current_pic = 0;
folder_path = '/media/exfat/timelapse';

if not os.path.isdir(folder_path):
    os.mkdir(folder_path);

while current_pic < amount:
    camera = PiCamera();
    camera.resolution = (width, height);
    sleep(hold);
    camera.capture(folder_path + '/' + '{0:0>8d}'.format(current_pic) + '.jpg');
    camera.close();
    current_pic += 1;
    print('Captured picture ' + str(current_pic) + '/' + str(amount));
    sleep(60 - hold);

print('Time lapse done!');
  1. Make script executable by running chmod u+x timelapse.py
  2. Start screen by running screen -S timelapse
  3. Run script with ./timelapse.py
  4. Detach from screen with Ctrl-a + d and let the script run in the background
  5. Check the progress by running screen -r timelapse, when it's done you should see Time lapse done!
  6. Exit screen with exit and run cd /media/exfat/timelapse
  7. Create a video by running ffmpeg -r 24 -f image2 -i %08d.jpg -r 24 -s 1920x1080 -c:v libx264 -preset slow -crf 20 timelapse.mkv

About

Notes for Raspbian & Raspberry Pi Camera Module

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages