Alexandre_mgrd
Posts: 8
Joined: Thu Jan 30, 2020 4:00 pm

camera raspberry v2

Thu Jan 30, 2020 4:23 pm

Hello,

First I explain my project, I want to film with the raspberry camera v2 only by pressing a button (to start recording) then pressing a second time, stop recording and save it in sd card. I already install raspbian on the map but I haven’t found how to create a code to do exactly what I described above

gordon77
Posts: 4512
Joined: Sun Aug 05, 2012 3:12 pm

Re: camera raspberry v2

Thu Jan 30, 2020 5:00 pm

Try this...

Code: Select all

#!/usr/bin/env python3
import picamera
import datetime
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO_SWITCH = 7  # Physical pin 26, switch to GND
GPIO.setup(GPIO_SWITCH,GPIO.IN,pull_up_down = GPIO.PUD_UP)

print ("  Press Ctrl & C to Quit")

Record = 0

try:
   while True:
      with picamera.PiCamera() as camera:
         camera.resolution = (1280, 720)
         camera.framerate = 25
         while GPIO.input(GPIO_SWITCH) == 1 :
            time.sleep(0.25)
         Record = 1
         print ("Recording")
         now = datetime.datetime.now()
         timestamp = now.strftime("%y%m%d%H%M%S")
         camera.start_preview()
         camera.start_recording(str(timestamp) + '.h264')
         time.sleep(.5)
         while Record == 1:
            camera.wait_recording(.01)
            if GPIO.input(GPIO_SWITCH) == 0:
               print ("Stopped")
               camera.stop_recording()
               Record = 0
               while GPIO.input(GPIO_SWITCH) == 0:
                  time.sleep(0.1)
               time.sleep(.5)
 
except KeyboardInterrupt:
  print ("Quit")
  GPIO.cleanup()   

Alexandre_mgrd
Posts: 8
Joined: Thu Jan 30, 2020 4:00 pm

Re: camera raspberry v2

Mon Feb 10, 2020 9:36 am

Thank you for your help, but I don’t understand your code, where should I insert it? Should I go through raspbian? and how do I configure where I want to record the video? because I want to record it on sd card, and do as a go pro.

gordon77
Posts: 4512
Joined: Sun Aug 05, 2012 3:12 pm

Re: camera raspberry v2

Mon Feb 10, 2020 9:49 am

Its a python script. Save it as v2camera.py in /home/pi

in a terminal window type python3 v2camera.py

Alexandre_mgrd
Posts: 8
Joined: Thu Jan 30, 2020 4:00 pm

Re: camera raspberry v2

Mon Feb 10, 2020 9:50 am

Thank you, your code seems to work but I don’t understand where the video is recording, do I need to change the code to configure the recording folder.

Natoons
Posts: 4
Joined: Mon Jan 27, 2020 9:34 am

Re: camera raspberry v2

Mon Feb 10, 2020 10:08 am

Now record a video!
The Python picamera library allows you to control your Camera Module and create amazing projects.
Open a Python 3 editor, such as Thonny Python IDE:

Code: Select all

camera.start_preview()
camera.start_recording('/home/pi/Desktop/video.h264')
sleep(5)
camera.stop_recording()
camera.stop_preview()

gordon77
Posts: 4512
Joined: Sun Aug 05, 2012 3:12 pm

Re: camera raspberry v2

Mon Feb 10, 2020 11:15 am

Alexandre_mgrd wrote:
Mon Feb 10, 2020 9:50 am
Thank you, your code seems to work but I don’t understand where the video is recording, do I need to change the code to configure the recording folder.
They are in the home dir /home/pi/

You could change as required, E.g. to camera.start_recording('/home/pi/Videos/' + str(timestamp) + '.h264')

Return to “Français”