Created
September 21, 2021 13:19
-
-
Save befinitiv/fd44a597a48460c100a54649c97d5984 to your computer and use it in GitHub Desktop.
Super 8 camera code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import glob | |
import socket | |
import time | |
from threading import Timer | |
import picamera | |
import RPi.GPIO as GPIO | |
SENSOR_PIN = 18 | |
W = 1296 | |
H = 972 | |
FPS = 18 | |
IP = '192.168.0.21' | |
PORT = 5000 | |
def start_recording(): | |
global camera_data | |
global camera | |
camera_data = CameraData() | |
camera.start_recording(camera_data, format='h264') | |
print('start') | |
def stop_recording(): | |
global camera_data | |
global camera | |
camera.stop_recording() | |
camera_data.stop() | |
print('stop') | |
def timer_stop(): | |
global stop_timer_running | |
stop_timer_running = False | |
stop_recording() | |
last_sensor_event = 0 | |
stop_timer_running = False | |
def sensor_change(pin): | |
global last_sensor_event | |
global stop_timer | |
global stop_timer_running | |
now = time.time() | |
if abs(last_sensor_event - now) > 0.5: | |
start_recording() | |
last_sensor_event = now | |
if stop_timer_running: | |
stop_timer.cancel() | |
stop_timer = Timer(0.5, timer_stop) | |
stop_timer.start() | |
stop_timer_running = True | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(SENSOR_PIN, GPIO.IN) | |
GPIO.add_event_detect(SENSOR_PIN, GPIO.BOTH, sensor_change) | |
# This class writes data to file and streams it in parallel | |
class CameraData(object): | |
def __init__(self): | |
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
self.client_socket.connect((IP, PORT)) | |
self.connection = self.client_socket.makefile('wb') | |
self.file = open(self.create_unique_file_name(), 'wb') | |
def create_unique_file_name(self): | |
return '%d.h264' % len(glob.glob('*')) | |
def write(self, s): | |
self.connection.write(s) | |
self.file.write(s) | |
def flush(self): | |
pass | |
def stop(self): | |
self.connection.close() | |
self.client_socket.close() | |
self.file.close() | |
# Make a file-like object out of the connection | |
try: | |
camera = picamera.PiCamera() | |
camera.resolution = (W, H) | |
camera.framerate = FPS | |
while True: | |
time.sleep(1) | |
#camera.wait_recording(60) | |
finally: | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Analog camera service | |
After=network.target | |
StartLimitIntervalSec=0 | |
[Service] | |
Type=simple | |
Restart=always | |
RestartSec=1 | |
User=pi | |
ExecStart=/home/pi/cam.py | |
WorkingDirectory=/home/pi/videos | |
[Install] | |
WantedBy=multi-user.target |
antisaint81
commented
Apr 29, 2024
via email
Yeah the code as written was written for bullseye, so if you want to use it as it, you have to run it on the legacy Raspberry Pi OS, otherwise you'll have to change to cover to make it work with bookworm. The legacy OS images are at the bottom of the download page.
Sent from Proton Mail mobile
…-------- Original Message --------
On Apr 29, 2024, 2:06 PM, ctavares-94 wrote:
@ctavares-94 commented on this gist.
---------------------------------------------------------------
***@***.***(https://github.com/antisaint81)
***@***.***:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 12 (bookworm)"
NAME="Raspbian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
—
Reply to this email directly, [view it on GitHub](https://gist.github.com/befinitiv/fd44a597a48460c100a54649c97d5984#gistcomment-5040715) or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AMMRJDH447LP4HWCBOYXMA3Y72D3LBFKMF2HI4TJMJ2XIZLTSGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTCMJZGM4DCMZSU52HE2LHM5SXFJTVOBSGC5DF).
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for [iOS](https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675) or [Android](https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub).
ok its working i think im no longer getting errors and im running Bullseye. The camera is showing a small red LED when running the script now im trying to see the live feed from my computer via web browser and nothing .. i had tried changing the ip address to 192.168.1.117:5000 but that didnt change anything considering the PI is on that address already @antisaint81
actually i believe the issue is i haven't set up the
[camera.service]
(https://gist.github.com/befinitiv/fd44a597a48460c100a54649c97d5984#file-camera-service) where would i implement this..?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment