-
Notifications
You must be signed in to change notification settings - Fork 0
/
flv_helper.py
142 lines (105 loc) · 3.85 KB
/
flv_helper.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from flv import *
from ctypes import *
### Wrappers to create flv construct objects
def flvheader_create():
return flv_header.build(Container(Signature = "FLV", Version = 0,
TypeFlags = 0, DataOffset = 0))
def flvtag_create(prevTagSize, tag):
return Container(
TypeRes=Container(Reserved=0, Filter=0, TagType=18),
BodySize=Container(BodySize=0),
Timestamp=Container(Timestamp=0),
TimestampExtended=0,
StreamID=Container(StreamID=0),
Tag=tag
)
def scriptdata_create(name):
return Container(NameType=2, Name=name, ArrayType=8,
Length=0, ScriptdataProperty=[],
ObjectTerminator1=0,
ObjectTerminator2=0,
ObjectTerminator3=9)
def scriptdata_propstr(name, prop):
return Container(Name=name, Type=2, Body=prop)
def scriptdata_addpropstr(sd, name, str):
prop = scriptdata_propstr(name, str)
sd.Length += 1
sd.ScriptdataProperty += [prop]
return sd
def scriptdata_propnum(name, num):
return Container(Name=name, Type=0, Body=num)
def scriptdata_addpropnum(sd, name, num): # TODO collapse scriptdata_addprop to one function
prop = scriptdata_propnum(name, num)
sd.Length += 1
sd.ScriptdataProperty += [prop]
return sd
### Wrapper functions for recursive arrays
def scriptdata_addproparr(sd, name, arr):
sd.Length += 1
sd.ScriptdataProperty += [arr]
return sd
def scriptdata_proparr(name):
return Container(Name=name, Type=8,
Body=Container(Length=0,
ScriptdataProperty=[],
ObjectTerminator1=0,
ObjectTerminator2=0,
ObjectTerminator3=9))
def scriptdata_arradd(arr, prop):
arr.Body.Length += 1
arr.Body.ScriptdataProperty += [prop]
### Testing functions
def cue_gen():
sd = scriptdata_create("onCuePoint")
scriptdata_addpropstr(sd, "name", "Mysecondcuepoint")
scriptdata_addpropnum(sd, "time", 0)
scriptdata_addpropstr(sd, "type", "navigation")
par1 = scriptdata_propstr("lights", "beginning")
arr = scriptdata_proparr("parameters")
scriptdata_arradd(arr, par1)
scriptdata_addproparr(sd, "parameters", arr)
return sd
def so_fixsize(ft):
s = len(flv_tag.build(ft))
ft.BodySize.BodySize=s-11
return s
def read_cue(filename):
f = open(filename).read()
print flv.parse(f)
def cuecumber_insert():
sd = cue_gen()
ft = flvtag_create(0, sd)
prevsize = so_fixsize(ft)
ftt = flv_tag.build(ft)
f = open('cuepoint_gen.raw', 'w')
f.write(ftt)
libcuecumber = cdll.LoadLibrary("./libcuecumber.so")
libcuecumber.cuecumber_init()
libcuecumber.insert_cuepoint(prevsize, ftt)
libcuecumber.cuecumber_exit()
### Emcee function wrappers
def cuecumber_startstream():
global libcuecumber
libcuecumber = cdll.LoadLibrary("./libcuecumber.so")
libcuecumber.cuecumber_init()
def cuecumber_stopstream():
libcuecumber.cuecumber_exit()
def cuecumber_changeslide(slide_number):
sd = cuecumber_generate_slidecuepoint(slide_number)
ft = flvtag_create(0, sd)
prevsize = so_fixsize(ft)
ftt = flv_tag.build(ft)
libcuecumber.insert_cuepoint(prevsize, ftt)
def cuecumber_generate_slidecuepoint(slide_number):
sd = scriptdata_create("onCuePoint")
scriptdata_addpropstr(sd, "name", "Mysecondcuepoint")
scriptdata_addpropnum(sd, "time", 0)
scriptdata_addpropnum(sd, "slide", slide_number)
scriptdata_addpropstr(sd, "type", "navigation")
par1 = scriptdata_propstr("lights", "beginning")
arr = scriptdata_proparr("parameters")
scriptdata_arradd(arr, par1)
scriptdata_addproparr(sd, "parameters", arr)
return sd
#read_cue('cuepoints.flv')
#cuecumber_insert()