-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_videowriter.py
45 lines (39 loc) · 2.19 KB
/
func_videowriter.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
import cv2
from datetime import datetime
import time
class Writer:
def __init__(self, cam_num):
self.num = cam_num
self.size = (1920, 1080) # 保存视频分辨率的大小
if self.num == 2:
self.writer1 = cv2.VideoWriter('recording/{}_orig1.mov'.format(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M')), cv2.VideoWriter_fourcc('a', 'v', 'c', '1'), 45.0, self.size)
self.writer2 = cv2.VideoWriter('recording/{}_orig2.mov'.format(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M')), cv2.VideoWriter_fourcc('a', 'v', 'c', '1'), 45.0, self.size)
self.writer_1 = cv2.VideoWriter('recording/{}_proc1.mov'.format(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M')), cv2.VideoWriter_fourcc('a', 'v', 'c', '1'), 45.0, self.size)
self.writer_2 = cv2.VideoWriter('recording/{}_proc2.mov'.format(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M')), cv2.VideoWriter_fourcc('a', 'v', 'c', '1'), 45.0, self.size)
elif self.num == 1:
self.writer1 = cv2.VideoWriter('recording/{}_orig1.mov'.format(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M')), cv2.VideoWriter_fourcc('a', 'v', 'c', '1'), 45.0, self.size)
self.writer_1 = cv2.VideoWriter('recording/{}_porc1.mov'.format(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M')), cv2.VideoWriter_fourcc('a', 'v', 'c', '1'), 45.0, self.size)
def write_orig(self, frame1, frame2=None):
if self.num == 2:
self.writer1.write(frame1)
self.writer2.write(frame2)
else:
self.writer1.write(frame1)
def write_pros(self, frame1, frame2=None):
if self.num == 2:
self.writer_1.write(frame1)
self.writer_2.write(frame2)
else:
self.writer_1.write(frame1)
def clean(self):
print("CLASS WRITER FUNC CLEAN NOT IMPLEMENTED!")
pass
def __del__(self):
if self.num == 2:
self.writer1.release()
self.writer2.release()
self.writer_1.release()
self.writer_2.release()
else:
self.writer1.release()
self.writer_1.release()