Aug-20-2017, 09:36 PM
I've got a script running from startup on my raspberry pi using
so basically, how can I have it grab the correct timestamp instead of just once when the script is run at startup?
this is my full code:
import timeand
timestamp = time.strftime("%Y-%m-%d_%H:%M:%S")but when I grab a video and timestamps the filename it uses the same timestamp over and over. If I run it manually it puts the correct timestamp, so I think it grabs it once when the script is started but not each time it needs to timestamp, if you get what I mean??
so basically, how can I have it grab the correct timestamp instead of just once when the script is run at startup?
this is my full code:
#!/usr/bin/python # 360 rotation and video from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor, Adafruit_StepperMotor import atexit import RPi.GPIO as GPIO from signal import pause import picamera import time from time import sleep from subprocess import call import os # Setup GPIO Pins GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) #setup camera camera = picamera.PiCamera() #camera.framerate = 25 #camera.resolution = (1280, 720) #Grab the current date & time timestamp = time.strftime("%Y-%m-%d_%H:%M:%S") # Setup Motor # create a default object, no changes to I2C address or frequency mh = Adafruit_MotorHAT(addr = 0x60) # recommended for auto-disabling motors on shutdown! def turnOffMotors(): mh.getMotor(1).run(Adafruit_MotorHAT.RELEASE) mh.getMotor(2).run(Adafruit_MotorHAT.RELEASE) mh.getMotor(3).run(Adafruit_MotorHAT.RELEASE) mh.getMotor(4).run(Adafruit_MotorHAT.RELEASE) atexit.register(turnOffMotors) myStepper = mh.getStepper(200, 1) # 200 steps/rev, motor port #1 myStepper.setSpeed(10) # 10 RPM while True: input_state = GPIO.input(18) # filename = os.path.join(destination, dt.datetime.now().strftime('TFF_%Y-%m-%d_%H.%M.%S.h264 -t 10000 -w 1296 -h 730 -fps 25 > /dev/null')) if input_state == False: print('Button Pressed') sleep(.5) print("Camera recording for 28 seconds") # Setup the camera #with picamera.PiCamera() as camera: # Start recording camera.start_recording("/home/pi/Videos/360Video.h264" ) sleep(2) print("turning motor 1 revolution, approx 26 seconds") myStepper.step(200, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.MICROSTEP) print("motor stopped") sleep(2) # Stop recording camera.stop_recording() # The camera is now closed. print("Camera finished recording") sleep(.5) print("Converting the video to mp4.") # Define the command we want to execute. command = "MP4Box -add /home/pi/Videos/360Video.h264 /home/pi/Videos/360Video_transfer/"+timestamp+"_360Video.mp4" # Execute our command call([command], shell=True) # Video converted. print("Video converted.") sleep(.5) print("deleting h264 file") os.unlink("/home/pi/Videos/360Video.h264") sleep(.5) print("h264 file deleted")