-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
executable file
·65 lines (59 loc) · 1.88 KB
/
main.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
#!/usr/bin/env python
import cv2, numpy as np
import sys
import time
from player import Player, PlayerState, PlayerCmd
from decoder import FileFormat
def PrintUsage():
print \
"\nmain.py filename format\n" \
" format: 1-AUTO_DETECTED; 0-YUV420\n" \
"\n" \
"Click the video window, and control by:\n" \
" | key | action |\n" \
" | p | Play |\n" \
" | f | Freeze(pause) |\n" \
" | n | Next frame |\n" \
" | N | Prev frame |\n" \
" | s | Screenshot |\n"
def main():
player = Player(sys.argv[1], int(sys.argv[2]))
player.Start()
while True:
try:
cmd = 'none'
cmd = {ord('f'): 'freeze',
ord('p'): 'play',
ord('N'): 'prev_frame',
ord('n'): 'next_frame',
ord('s'): 'screenshot',
-1 : cmd,
27 : 'exit'}[cv2.waitKey(10)]
if cmd == 'play':
player.Play()
if cmd == 'freeze':
player.Pause()
if cmd == 'exit':
player.Stop()
break
if cmd == 'prev_frame':
player.SeekTo(player.GetCurPos() - 1)
player.Pause()
if cmd == 'next_frame':
player.SeekTo(player.GetCurPos() + 1)
player.Pause()
if cmd == 'screenshot':
player.SaveCurFrame()
player.Pause()
except KeyError:
print "Invalid Key was pressed"
except (KeyboardInterrupt):
print "KeyboardInterrupt in main()"
player.Stop()
sys.exit()
if __name__ == "__main__":
PrintUsage()
if len(sys.argv) < 3 :
print "Error input params"
sys.exit(-1)
main()