Close

New Feature: One Button Record and Stop

A project log for 90s Raspberry Camcorder

Upgrading a 1993 RCA CC540 VHS camcorder with a Raspberry Pi, HQ Camera module, modern storage, power, and features.

DustinDustin 11/30/2020 at 18:530 Comments

I decided it was time to finally start cleaning up my code this morning, and it's going surprisingly well. I created some basic functions, and basically started over. I finally got a function working that lets me start and stop recording by pressing a button. It's a rather important feature, as it lets me use the single physical record button on the camcorder. The current code is still quite messy, but I'll post it here anyway.

It works just fine, and lays the foundations for easily implementing the rest of the features later. 

Features previously implemented, but not yet implemented in this iteration:

- Photo captures

- White balance adjustments

- Exposure adjustments

- ISO adjustments

Improvements in this iteration, over previous:

- One button record and stop

- Cleaner code, allowing for faster future coding

The code is at a point where someone could install my setup into their Raspberry Pi and have a working camcorder. It's quite easy to make simple scripts that would capture a video file, but I feel mine is a more complete solution than that. It's getting to a point where it would be a useable system for the average person, once installed. No running of scripts and such. Just pressing buttons and pointing the camera. The end goal is a working camera that takes advantage of every single feature of the Raspberry Pi HQ Camera Module, as well as many of the general purpose features of the Raspberry Pi 4.

I have to go clean the car out and such, so back to the real world for a little bit.

The following code is known working at this point, but using it requires the Keyboard module installed.

#Commands:
#r = start recording
#p = take picture
#0-8 = ISO modes 100-800, 0 is auto
#a = auto exposure
#n = night exposure


#Exposure Modes:
#- off
#- auto
#- night
#- nightpreview
#- backlight
#- spotlight
#- sports
#- snow
#- beach
#- verylong
#- fixedfps
#- antishake
#- fireworks

#White Balance Modes:
#- off
#- auto
#- sunlight
#- cloudy
#- shade
#- tungsten
#- flourescent
#- incandescent
#- flash
#- horizon

import time
import keyboard
from time import sleep
from picamera import PiCamera

camera = PiCamera()
camera.resolution = (1920, 1080)
camera.exposure_mode = 'auto'
camera.awb_mode = 'auto'
#camera.start_preview()

print("PiCorder V1.4")
        
            
def record_start():
    camera.resolution = (1920, 1080)
    sleep(2)
    camera.start_recording('/home/pi/Documents/test_files/button.h264')
    print("Recording Started")
    while True:
        if keyboard.is_pressed('r'):
            record_stop()
            print("stop")
            time.sleep(1)
            break
        
def record_stop():
    camera.stop_recording()
    print("Recording Stopped")
    
    
def end():
    camera.stop_preview()
    camera.close()
    print("Killing Program")
    time.sleep(2)
            

while True:
    try:
        if keyboard.is_pressed('r'):
            record_start()
            
        if keyboard.is_pressed('x'):
            end()
            break
    except:
        pass

Discussions