forked from luxonis/depthai-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13_encoding_max_limit.py
executable file
·74 lines (58 loc) · 2.49 KB
/
13_encoding_max_limit.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
69
70
71
72
73
74
#!/usr/bin/env python3
import depthai as dai
pipeline = dai.Pipeline()
# Nodes
colorCam = pipeline.createColorCamera()
colorCam.setResolution(dai.ColorCameraProperties.SensorResolution.THE_4_K)
monoCam = pipeline.createMonoCamera()
monoCam2 = pipeline.createMonoCamera()
ve1 = pipeline.createVideoEncoder()
ve2 = pipeline.createVideoEncoder()
ve3 = pipeline.createVideoEncoder()
ve1Out = pipeline.createXLinkOut()
ve2Out = pipeline.createXLinkOut()
ve3Out = pipeline.createXLinkOut()
# Properties
monoCam.setBoardSocket(dai.CameraBoardSocket.LEFT)
monoCam2.setBoardSocket(dai.CameraBoardSocket.RIGHT)
ve1Out.setStreamName('ve1Out')
ve2Out.setStreamName('ve2Out')
ve3Out.setStreamName('ve3Out')
#setting to 26fps will trigger error
ve1.setDefaultProfilePreset(1280, 720, 25, dai.VideoEncoderProperties.Profile.H264_MAIN)
ve2.setDefaultProfilePreset(3840, 2160, 25, dai.VideoEncoderProperties.Profile.H265_MAIN)
ve3.setDefaultProfilePreset(1280, 720, 25, dai.VideoEncoderProperties.Profile.H264_MAIN)
# Link nodes
monoCam.out.link(ve1.input)
colorCam.video.link(ve2.input)
monoCam2.out.link(ve3.input)
ve1.bitstream.link(ve1Out.input)
ve2.bitstream.link(ve2Out.input)
ve3.bitstream.link(ve3Out.input)
# Pipeline defined, now the device is connected to
with dai.Device(pipeline) as dev:
# Prepare data queues
outQ1 = dev.getOutputQueue('ve1Out', maxSize=30, blocking=True)
outQ2 = dev.getOutputQueue('ve2Out', maxSize=30, blocking=True)
outQ3 = dev.getOutputQueue('ve3Out', maxSize=30, blocking=True)
# Start the pipeline
dev.startPipeline()
# Processing loop
with open('mono1.h264', 'wb') as file_mono1_h264, open('color.h265', 'wb') as file_color_h265, open('mono2.h264', 'wb') as file_mono2_h264:
print("Press Ctrl+C to stop encoding...")
while True:
try:
# Empty each queue
while outQ1.has():
outQ1.get().getData().tofile(file_mono1_h264)
while outQ2.has():
outQ2.get().getData().tofile(file_color_h265)
while outQ3.has():
outQ3.get().getData().tofile(file_mono2_h264)
except KeyboardInterrupt:
break
print("To view the encoded data, convert the stream file (.h264/.h265) into a video file (.mp4), using commands below:")
cmd = "ffmpeg -framerate 25 -i {} -c copy {}"
print(cmd.format("mono1.h264", "mono1.mp4"))
print(cmd.format("mono2.h264", "mono2.mp4"))
print(cmd.format("color.h265", "color.mp4"))