Guest User

raspi-camera-button.py

a guest
Jul 2nd, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import subprocess
  3. import RPi.GPIO as GPIO
  4. from time import sleep,strftime
  5.  
  6. GPIO.setmode(GPIO.BCM)
  7. GPIO.setup(4, GPIO.IN)
  8.  
  9. while True:
  10.     if (GPIO.input(4) == False):
  11.     sleep(.25)
  12.     time=strftime("%H-%M-%S_%d-%m-%Y")
  13.     if (GPIO.input(4) == True):
  14.         cmd0='raspistill -t 10 -o /home/pi/' + time + '.jpg'
  15.         subprocess.call("%s" % cmd0, shell=True)
  16.         sleep(1.0)
  17.     else:
  18.         loop = 1
  19.                 cmd1='raspivid -t 0 -o /home/pi/' + time + '.h264'
  20.         subprocess.Popen("%s" % cmd1, shell=True)
  21.         sleep(1.0)
  22.         while (loop == 1):
  23.             if (GPIO.input(4) == False):
  24.             cmd2='pkill raspivid'
  25.                         cmd3='MP4Box -add /home/pi/' + time + '.h264 /home/pi/' + time + '.mp4'
  26.             cmd4='rm -f /home/pi/' + time + '.h264'
  27.                     subprocess.call("%s" % cmd2, shell=True)
  28.                         subprocess.call("%s" % cmd3, shell=True)
  29.                         subprocess.call("%s" % cmd4, shell=True)
  30.                     sleep(1.0)
  31.             loop='0'
  32.         sleep(0.1);
  33.     sleep(0.1);
Advertisement
Add Comment
Please, Sign In to add comment