Many of the novice programmers such as would like to start their fun with Raspberry. Most of them search the Web for scripts and programs written in Python to take full advantage of Pi. Today, a short program that encloses a camera for a specified time dividing files into time-defined files.
Recently, I became the owner of Raspberry 4. I also decided to learn Python programming. I would like to be able to take full advantage of Pi, I have some nice ideas for servicing the entire home along with mining cryptocurrencies. I want to buy Raspberry to have one device in each room. Each of them is to measure the temperature, record movement, measure the air level, warn of poor air quality, high dustiness, open windows when necessary, warn of smoke and smoke from the furnace. For this, the central unit is to serve as an alarm and fire control panel. I have a few other ideas but more on that later.
Returning to the subject, as if it were if I had Raspberry and I did not buy the periphery. On AliExpress I bought an infrared camera. Waiting time only 2 weeks. After connecting to Pi you would have to run the webcam to start the fun. The course on forbot.pl comes with help here. Two days later I wanted to launch the webcam, but this time from Python. Quickly on the network I found a short program that allowed me to run and record a webcam video.
import picamera camera = picamera.PiCamera() camera.resolution = (640, 480) camera.start_recording('moje_video.h264') camera.wait_recording(60) camera.stop_recording()
The applet allowed to launch the webcam and record the movie in 640 × 480 resolution and 60 seconds length. Unfortunately, the movie lacked a time stamp. After all, what if I had to record a film lasting 12 hours? I started searching for a program that will allow me to record a movie for 12 hours by dividing it into hourly parts. Finally succeeded. The program recorded a movie with a time stamp, it was enough to modify it to meet my criteria.
Thanks to the beginner course, I looped the program that now allows me to record as many hours as I want, saving hourly parts.
import picamera import datetime as dt camera = picamera.PiCamera(resolution=(640, 480), framerate=24) #Podgląd bieżący z kamery, wystarczy usunąć # #camera.start_preview() camera.annotate_background = picamera.Color('black') camera.annotate_text = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S') camera.start_recording('1.h264') for i in range(2, 6):# 6 - to ilość godzin w nagrywaniu -1 start = dt.datetime.now() # 3600 - czas trwania jednego filmu while (dt.datetime.now() - start).seconds < 3600: camera.annotate_text = dt.datetime.now().strftime('%Y-%m- %d %H:%M:%S') camera.split_recording('%d.h264' % i) camera.wait_recording(10) camera.stop_recording()
This is not the best solution, but it works. Over time, as I continue to deepen my knowledge, I will probably make better improvements or write my program, but it must be enough for today.
The program fulfills its role. Making an entry in crontab, the camera records infrared films every day from 23 to 7 am, so I know what's happening at night on the terrace at the back of the house. Maybe beginners will need this knowledge. Greetings.