-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_recording.py
69 lines (51 loc) · 1.67 KB
/
video_recording.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Import Library
import time
import cv2
import os
from threading import Thread
from djitellopy import Tello
# Drone Setup
tello = Tello("192.168.31.11")
tello.connect()
# Recording status
keepRecording = True
# Turn on video streaming
tello.streamon()
# Read the frame from video streaming
frame_read = tello.get_frame_read()
# Get the current date as the timestamp
timestamp = time.strftime("%Y-%m-%d")
# Initialize a global file_number variable
file_number = 1
def videoRecorder():
global file_number # Declare file_number as a global variable
height, width, _ = frame_read.frame.shape
while keepRecording:
# Construct the video file name
video_filename = f"VDO_{timestamp}_{file_number}.mp4"
# Check if the file already exists
if os.path.exists(video_filename):
file_number += 1
continue # Skip this iteration and check the next file number
# Create a VideoWriter object to save the video as the constructed filename using the H.264 codec
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video = cv2.VideoWriter(video_filename, fourcc, 30, (width, height))
# Recording the video from the image frame
while keepRecording:
video.write(frame_read.frame)
time.sleep(1 / 30)
# release the video writer
video.release()
file_number += 1 # Increment the global file number
# Start a new thread for recording video
recorder = Thread(target=videoRecorder)
recorder.start()
# Takeoff
tello.takeoff()
# Any Drone Action
tello.rotate_counter_clockwise(360)
# Landing
tello.land()
# Stop recording
keepRecording = False
recorder.join()