-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexporter.py
81 lines (61 loc) · 2.68 KB
/
exporter.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
# =============================================================================
# Module: exporter.py
# Contacts: Edward Li ([email protected])
# =============================================================================
"""___DESC___
"""
# =============================================================================
# IMPORTS
# =============================================================================
import glob
import subprocess
# =============================================================================
# CLASSES
# =============================================================================
class Exporter(object):
# =========================================================================
def __init__(self, workDir=None, exportFile=None):
self._workDir = workDir
self._exportFile = exportFile
self._proc = None
# =========================================================================
def start(self):
self.makeFileList()
if not self._proc:
self._proc = subprocess.Popen(self.args, shell=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
self._proc.communicate()
else:
print('Error: An exporting process is already running.')
# =========================================================================
def stop(self):
if self._proc:
self._proc.communicate(input='q')
self._proc = None
else:
print('Error: There is no existing recording process to stop.')
# =========================================================================
def makeFileList(self):
segmentFiles = glob.glob('{d}recording.*.mov'.format(d=self._workDir))
segmentFiles.sort()
with open(self.fileList, 'w') as fileList:
for segmentFile in segmentFiles:
fileList.write("file '{f}'\n".format(f=segmentFile))
# =========================================================================
@property
def args(self):
return 'ffmpeg {option}'.format(option=self.optionArgs)
# =========================================================================
@property
def optionArgs(self):
return '-f concat ' + \
'-i {i} '.format(i=self.fileList) + \
'-codec copy ' + \
'-y ' + \
self._exportFile
# =========================================================================
@property
def fileList(self):
return '{d}recording.list'.format(d=self._workDir)
# =============================================================================