pal251
Posts: 1
Joined: Fri Dec 28, 2012 3:47 am

Re: Raspberry dashcam wanted

Sat Nov 30, 2013 2:06 am

Newbie here..

Any tutorials for a brand new person to PI to setup the pi to loop constantly and when I hit a switch or button have it start recording it onto another directory to include the current loop and further video?

If nothing else I would be happy with ten minute loops that write over the oldest file until then.

cadsenthilkumar
Posts: 29
Joined: Wed Sep 25, 2013 11:09 am

Re: Raspberry dashcam wanted

Wed Feb 26, 2014 4:32 am

Hi atnu

From your program i saw "raspivid -o /home/pi/video/video_$date.h264 -n -w 1280 -h 720 -b 6000000 -t 9000000 &" is used for store video in the directory /home/pi/video/video_ xx.x. and so on .

Here i have to process the video like gray conversion in the capture video .

If i used your above syntax it store the video and we have to read those video and manipulate the video for gray conversion.

I want to know how to asses the buffer memory of PI-CAM directly for manipulating and storing the processed as gray or edge converted video converted video ????.

Regards
Senthilkumar R



atnu wrote:I have made myself a car camera recorder, here is the info and code (fast and dirty)

-Raspberry Pi Model A
-Camera module
-Tactile button (to start recording, stop recording and to shutdown the Pi if pressed >5s)
-Wifi optional, Get the date and upload the videos
-Anker 10 000mAh battery or phone charger for car

Image

Logic:
Starts recording video right after Pi has started (record.sh) is started from /etc/rc.local
Button code is started right after Pi has started from /etc/rc.local)
place the scripts to /home/pi/video or change the paths

recording.sh

Code: Select all

#!/bin/sh
#
# Launch of code added to /etc/rc.local on the line before "exit 0" :
# sh /home/pi/video/recording.sh

#go to working directory
cd /home/pi/video/
#3Gb free space limit
limit=3000000

#check the size from disk partition /dev/root
size=$(df -k /dev/root | tail -1 | awk '{print $4}')

#remove oldest files according to the free space limit
while [ $size -le $limit ]
do
   #remove .h264 files starting from the oldest file
   ls -1tr |grep .h264 | head -n -1 | xargs -d '\n' rm -f
   #check free space again
   size=$(df -k /dev/root | tail -1 | awk '{print $4}')
done

date=$(date +"%Y%m%d%H%M")

#start capturing video and exit the script
raspivid -o /home/pi/video/video_$date.h264 -n -w 1280 -h 720 -b 6000000 -t 9000000 &

stop_recording.sh:

Code: Select all

#!/bin/sh
#stops the raspivid process
pid=`pidof raspivid`
`kill -2 $pid`
stop_button.py
Press button to: if recording is on, stop it. if recording is off start it, press >5sec to shutdown Pi

Code: Select all

#!/usr/bin/env python
#
# Launch of code added to /etc/rc.local on the line before "exit 0" :
# python /home/pi/video/stop_button.py &
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN) 

recording = True;

while True:
  if(GPIO.input(23) == False ):
    #button pressed down
    if(recording == True):
      recording = False
      os.system("sudo sh /home/pi/video/stop_recording.sh")
    else:
      recording = True
      os.system("sudo sh /home/pi/video/record.sh")
    #press button 5 secs to shutdown raspi
    time.sleep(5)
    if(GPIO.input(23) == False ):
      #os.system("sudo sh stop_recording.sh")
      os.system("sudo shutdown -h now")
      #print('shutdown')
      break
  time.sleep(0.5)
my todo list for the project: startup optimization, video uploading: rsync automatically to server, better casing for camera etc.
I'll put some example videos of the recordings made so far

Update1:
Example video in youtube: http://www.youtube.com/watch?v=hFQeA3epmtI
Original example video: https://dl.dropboxusercontent.com/u/793 ... 601901.mp4

chiruru
Posts: 17
Joined: Sun Apr 20, 2014 8:56 am

Re: Raspberry dashcam wanted

Wed May 07, 2014 1:42 pm

Hi, Could you recording video and streaming at the same time ?

This command is for recording video.
raspivid -o /home/pi/video/video_$date.h264 -n -w 1280 -h 720 -b 6000000 -t 9000000 &

How can I add another command for streaming?
Anybody has idea?

chiruru
Posts: 17
Joined: Sun Apr 20, 2014 8:56 am

Re: Raspberry dashcam wanted

Fri May 09, 2014 10:53 am

I had run python script, the result is below.
Is not working code?

Code: Select all

pi@raspberrypi ~/video $ sudo python stop_button.py
/home/pi/video/stop_recording.sh: 1: kill: Illegal number:
: not founddeo/stop_recording.sh: 4: /home/pi/video/stop_recording.sh:

Broadcast message from root@raspberrypi (pts/1) (Fri May  9 19:40:10 2014):
The system is going down for system halt NOW!
atnu wrote:I have made myself a car camera recorder, here is the info and code (fast and dirty)

-Raspberry Pi Model A
-Camera module
-Tactile button (to start recording, stop recording and to shutdown the Pi if pressed >5s)
-Wifi optional, Get the date and upload the videos
-Anker 10 000mAh battery or phone charger for car

Image

Logic:
Starts recording video right after Pi has started (record.sh) is started from /etc/rc.local
Button code is started right after Pi has started from /etc/rc.local)
place the scripts to /home/pi/video or change the paths

recording.sh

Code: Select all

#!/bin/sh
#
# Launch of code added to /etc/rc.local on the line before "exit 0" :
# sh /home/pi/video/recording.sh

#go to working directory
cd /home/pi/video/
#3Gb free space limit
limit=3000000

#check the size from disk partition /dev/root
size=$(df -k /dev/root | tail -1 | awk '{print $4}')

#remove oldest files according to the free space limit
while [ $size -le $limit ]
do
   #remove .h264 files starting from the oldest file
   ls -1tr |grep .h264 | head -n -1 | xargs -d '\n' rm -f
   #check free space again
   size=$(df -k /dev/root | tail -1 | awk '{print $4}')
done

date=$(date +"%Y%m%d%H%M")

#start capturing video and exit the script
raspivid -o /home/pi/video/video_$date.h264 -n -w 1280 -h 720 -b 6000000 -t 9000000 &

stop_recording.sh:

Code: Select all

#!/bin/sh
#stops the raspivid process
pid=`pidof raspivid`
`kill -2 $pid`
stop_button.py
Press button to: if recording is on, stop it. if recording is off start it, press >5sec to shutdown Pi

Code: Select all

#!/usr/bin/env python
#
# Launch of code added to /etc/rc.local on the line before "exit 0" :
# python /home/pi/video/stop_button.py &
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN) 

recording = True;

while True:
  if(GPIO.input(23) == False ):
    #button pressed down
    if(recording == True):
      recording = False
      os.system("sudo sh /home/pi/video/stop_recording.sh")
    else:
      recording = True
      os.system("sudo sh /home/pi/video/record.sh")
    #press button 5 secs to shutdown raspi
    time.sleep(5)
    if(GPIO.input(23) == False ):
      #os.system("sudo sh stop_recording.sh")
      os.system("sudo shutdown -h now")
      #print('shutdown')
      break
  time.sleep(0.5)
my todo list for the project: startup optimization, video uploading: rsync automatically to server, better casing for camera etc.
I'll put some example videos of the recordings made so far

Update1:
Example video in youtube: http://www.youtube.com/watch?v=hFQeA3epmtI
Original example video: https://dl.dropboxusercontent.com/u/793 ... 601901.mp4

atnu
Posts: 5
Joined: Tue Jun 04, 2013 6:53 am

Re: Raspberry dashcam wanted

Tue Jun 16, 2015 3:30 pm

I ended up doing 9 month (10fps) timelapse from my work commute with my car dashboard project
https://www.youtube.com/watch?v=_fvLJ9hnxDE

I didn't have enough patience to edit it fully, maybe later..

Harold Spud
Posts: 1
Joined: Fri Aug 12, 2016 8:54 am

Re: Raspberry dashcam wanted

Fri Aug 12, 2016 8:57 am

Hi. I've already made one. Works reasonably well. See youtube for how to make it ... cheers.
https://youtu.be/ptcLQ8_K0kE

Code is here :
# Ras-Pi Dasher script
# filename: dasher6.pyw (renamed to dasher_live.py on pi)
# 9/08/2016
# time delay before shutdown.
# higher res video 1920 x 1080. highest possible.
# write to /media/usbdrive1
# filemanage procedure to 'age' files then ditch.
# reconfigured to use one only of 2 x 32G usb drives.
# future enhancements to use t'other one
# v6 : fsck usb drive and force fsck every reboot (-r option)



# night sequence-video not yet sorted.

import os
import shutil
import time
import RPi.GPIO as GPIO
from datetime import datetime

RunLight = 23
LED1 = 7
LED2 = 11
LED3 = 13
LED4 = 15
LED5 = 19
LED6_yellow = 21
LED7 = 29
LED8 = 31
LED9 = 33
LED10 = 35
LED11 = 37
Light_Sense = 40
Power_Sense = 38
PushSwitch1 = 36
GPIO.setmode(GPIO.BOARD)

for x in [RunLight,LED1,LED2,LED3,LED4,LED5,LED6_yellow,LED7,LED8,LED9,LED10,LED11]:
GPIO.setup(x, GPIO.OUT)

GPIO.setup(PushSwitch1, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(Power_Sense , GPIO.IN)
GPIO.setup(Light_Sense, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

for y in [RunLight,LED1,LED2,LED3,LED4,LED5,LED6_yellow,LED7,LED8,LED9,LED10,LED11]:
GPIO.output(y,False)
ledsequence1 = [LED5,LED4,LED3,LED2,LED1,LED1,LED2,LED3,LED4,LED5]
ledsequence2 = [LED7,LED8,LED9,LED10,LED11,LED11,LED10,LED9,LED8,LED7]

def flash_yellows():
GPIO.output(RunLight,True)
GPIO.output(LED6_yellow,True)
time.sleep(0.4)
GPIO.output(RunLight,False)
GPIO.output(LED6_yellow,False)

def dayseq():
for led in ledsequence1 : # daysequence
GPIO.output(led,True)
time.sleep(0.03)
GPIO.output(led,False)
time.sleep(0.01)
GPIO.output(LED6_yellow,True)
time.sleep(0.015)
GPIO.output(LED6_yellow,False)
time.sleep(0.01)
for led in ledsequence2 :
GPIO.output(led,True)
time.sleep(0.03)
GPIO.output(led,False)
time.sleep(0.01)
GPIO.output(LED6_yellow,True)
time.sleep(0.015)
GPIO.output(LED6_yellow,False)
time.sleep(0.01)

def nightseq():
for led in ledsequence1 : # nightsequence
GPIO.output(led,True)
time.sleep(0.005)
GPIO.output(led,False)
time.sleep(0.025)
GPIO.output(LED6_yellow,True)
time.sleep(0.002)
GPIO.output(LED6_yellow,False)
time.sleep(0.01)
for led in ledsequence2 :
GPIO.output(led,True)
time.sleep(0.005)
GPIO.output(led,False)
time.sleep(0.025)
GPIO.output(LED6_yellow,True)
time.sleep(0.002)
GPIO.output(LED6_yellow,False)
time.sleep(0.01)

def haltsys() :
print("Dasher SHUTDOWN NOW !!")
for x in range(6) :
flash_yellows()
time.sleep(0.5)
os.system("sudo shutdown -hF 0")


folder1 = "/media/usbdrive1/"
folder2 = "/media/usbdrive2/"

def tidy():
print("Tidying Video files ")

try: os.remove(folder1+"video8.h264")
except OSError: pass
try: os.rename(folder1+"video7.h264", folder1+"video8.h264")
except OSError: pass
try: os.rename(folder1+"video6.h264", folder1+"video7.h264")
except OSError: pass
try: os.rename(folder1+"video5.h264", folder1+"video6.h264")
except OSError: pass
try: os.rename(folder1+"video4.h264", folder1+"video5.h264")
except OSError: pass
try: os.rename(folder1+"video3.h264", folder1+"video4.h264")
except OSError: pass
try: os.rename(folder1+"video2.h264", folder1+"video3.h264")
except OSError: pass
try: os.rename(folder1+"video1.h264", folder1+"video2.h264")
except OSError: pass


# MAIN SCRIPT

os.system("umount /dev/sda1")
os.system("fsck -y /dev/sda1")
os.system("mount /dev/sda1")



tidy()

vid_name = folder1+"video1.h264"
os.system("raspivid -o " + str(vid_name)+" -t 0 -w 1920 -h 1080 -fps 25 &")

# start LED sequencing

power_warn = 0

while True:
print("Starting main loop cycle")
flash_yellows()
if GPIO.input(Power_Sense):
power_warn = power_warn + 1
print("Power off - warning: ", power_warn)
else : power_warn = 0

if (not GPIO.input(PushSwitch1)) or (power_warn > 1):
print("Shutdown initiated, Power-warn = ",power_warn)
haltsys()
break

if GPIO.input(Light_Sense):
dayseq()
dayseq()
print("Day sequence")
else:
nightseq()
nightseq()
print("NightSequence")
time.sleep(3)

robjharrison
Posts: 19
Joined: Tue Sep 05, 2017 6:48 am

Re: Raspberry dashcam wanted

Tue Apr 16, 2019 10:02 pm

Dragging up an old one is perhaps less than ideal, but it seems to be the right place to do this. The last posted link https://www.stuffaboutcode.com/2013/07/ ... h-obd.html was pretty useful, but has anyone a working (maybe simplified) version of this for python 3+ ?

Asking as the overheads for testing back and forth on a m/bike headless is a slight pain.

rgds

Return to “Beginners”