forked from geekscape/aiko_services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_example.py
executable file
·95 lines (85 loc) · 2.74 KB
/
video_example.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
#
# Usage
# ~~~~~
# LOG_LEVEL=DEBUG ./video_example.py
#
# To Do
# ~~~~~
# - timer_test() handler "alternate" state change, i.e implement state_action ?
# - Turn into an Aiko Service
# - CLI argument: --pause: Display first frame and pause
# - Interface: frame_rate(), run(), pause(), step(+/- frame_cout)
# - Video overlay: frame_id, statistics, etc
#
# - Put try...except around "import opencv" to provide simple error message
# - Split into video_opencv.py, video_scikit.py, video_gstreamer.py, etc
# - Ensure video_opencv.py uses asyncio and doesn't block !
from aiko_services import *
# FRAME_RATE = 0 # Process flat-out without delay
FRAME_RATE = 0.05 # 20 FPS
# VIDEO_INPUT_PATHNAME = "astra.mp4"
VIDEO_INPUT_PATHNAME = "astra_brief.mp4"
# VIDEO_INPUT_PATHNAME = "astra_short.mp4"
VIDEO_FRAME_RATE = 29.97
VIDEO_OUTPUT_PATHNAME = "z_output.mp4"
WINDOW_LOCATION = (50, 50)
WINDOW_TITLE = "Astra"
ELEMENTS_IMAGE = "aiko_services.elements.image_io"
ELEMENTS_VIDEO = "aiko_services.elements.video_io"
class StateMachineModel(object):
states = [
"start",
"alternate"
]
transitions = [
{"source": "start", "trigger": "alternate", "dest": "alternate"}
]
pipeline_definition = [
{ "name": "VideoReadFile", "module": ELEMENTS_VIDEO,
"parameters": {
# "state_action": (5, "alternate"),
"video_pathname": VIDEO_INPUT_PATHNAME
},
"successors": {
"default": ["ImageAnnotate1"],
"alternate": ["ImageAnnotate2"]
}
},
{ "name": "ImageAnnotate1", "module": ELEMENTS_IMAGE,
"successors": ["ImageOverlay"]
},
{ "name": "ImageAnnotate2", "module": ELEMENTS_IMAGE,
"successors": ["ImageOverlay"]
},
{ "name": "ImageOverlay", "module": ELEMENTS_IMAGE,
"successors": ["VideoShow"]
},
{ "name": "VideoShow", "module": ELEMENTS_VIDEO,
"parameters": {
"window_location": WINDOW_LOCATION,
"window_title": WINDOW_TITLE
},
"successors": ["ImageResize"]
},
{ "name": "ImageResize", "module": ELEMENTS_IMAGE,
"parameters": {
"new_width": 640,
"new_height": 360
},
"successors": ["VideoWriteFile"]
},
{ "name": "VideoWriteFile", "module": ELEMENTS_VIDEO,
"parameters": {
"video_frame_rate": VIDEO_FRAME_RATE,
"video_pathname": VIDEO_OUTPUT_PATHNAME
}
}
]
def timer_test():
aiko.logger(__name__).info("Timer test")
if __name__ == "__main__":
# event.add_timer_handler(timer_test, 0.1)
state_machine = StateMachine(StateMachineModel())
Pipeline_2020(
pipeline_definition, FRAME_RATE, state_machine=state_machine).run()