threefive3 3.0.37__tar.gz → 3.0.41__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {threefive3-3.0.37 → threefive3-3.0.41}/PKG-INFO +23 -4
- {threefive3-3.0.37 → threefive3-3.0.41}/README.md +22 -3
- {threefive3-3.0.37 → threefive3-3.0.41}/bin/threefive3 +60 -26
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/bitn.py +2 -1
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/commands.py +1 -1
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/cue.py +5 -17
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/gums.py +5 -7
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/hlstags.py +2 -14
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/pmt.py +45 -28
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/section.py +1 -1
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/sixfix.py +28 -26
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/stream.py +31 -30
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/stuff.py +14 -24
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/superkabuki.py +37 -136
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/uxp.py +1 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/version.py +1 -1
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/xml.py +5 -6
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3.egg-info/PKG-INFO +23 -4
- {threefive3-3.0.37 → threefive3-3.0.41}/LICENSE +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/setup.cfg +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/setup.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/__init__.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/aac.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/base.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/crc.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/descriptors.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/encode.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/hls.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/iframes.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/new_reader.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/packetdata.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/segment.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/segmentation.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/streamtypes.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/upids.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3/words.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3.egg-info/SOURCES.txt +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3.egg-info/dependency_links.txt +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3.egg-info/requires.txt +0 -0
- {threefive3-3.0.37 → threefive3-3.0.41}/threefive3.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: threefive3
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.41
|
|
4
4
|
Summary: SCTE-35 decoder and encoder with MPEGTS and HLS and XML support.
|
|
5
5
|
Home-page: https://github.com/superkabuki/threefive3
|
|
6
6
|
Author: Adrian of Doom
|
|
@@ -32,10 +32,27 @@ License-File: LICENSE
|
|
|
32
32
|
* Automatic AES decryption for HLS.
|
|
33
33
|
* All HLS __SCTE-35__ Tags are Supported.
|
|
34
34
|
|
|
35
|
-
#
|
|
35
|
+
# Heads up.
|
|
36
|
+
<pre>
|
|
37
|
+
The Super Kabuki MPEGTS SCTE-35 Packet Injection Engine is working really really well.
|
|
38
|
+
I've tested the SuperKabuki output with ffmpeg and tsduck and everything works.
|
|
39
|
+
I was going to wait until I finished The Sideways HLS tag Injector,
|
|
40
|
+
but I'm thinking I'm going to go ahead and do a new build with
|
|
41
|
+
Super Kabuki, probably tomorrow.
|
|
42
|
+
|
|
43
|
+
It's workinng perfectly for me,
|
|
44
|
+
so I want to get it out there and see if y'all break it. :)
|
|
45
|
+
</pre>
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Latest release is v3.0.39
|
|
36
49
|
_Released Thursday April 18th, 2025
|
|
50
|
+
* just 4300 lines of code.
|
|
51
|
+
* cyclomatic complexity __2.05__
|
|
37
52
|
> Stay up to date, only the latest release is supported.
|
|
38
53
|
|
|
54
|
+
|
|
55
|
+
|
|
39
56
|
## MPEGTS streams can be parsed for SCTE-35 with three lines of code.
|
|
40
57
|
|
|
41
58
|
```py3
|
|
@@ -49,16 +66,18 @@ a@fu:~/build5/scte35/scte35$ pypy3
|
|
|
49
66
|
# Checkout the Super Cool SCTE-35 [__Examples__](https://github.com/superkabuki/threefive3/tree/main/examples)
|
|
50
67
|
<br>
|
|
51
68
|
|
|
52
|
-
# threefive3 v3.0.
|
|
69
|
+
# threefive3 v3.0.39 is ready
|
|
53
70
|
|
|
54
71
|
* Xml is back and better than ever. __The new Ultra Xml Parser Supreme__ replaces the Super Xml Parser.
|
|
55
72
|
|
|
56
|
-
# [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md)
|
|
57
73
|
|
|
58
74
|
# `Documentation`
|
|
59
75
|
|
|
60
76
|
* [Install](#install)
|
|
61
77
|
|
|
78
|
+
* [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md) __New__!
|
|
79
|
+
|
|
80
|
+
|
|
62
81
|
### Cli
|
|
63
82
|
|
|
64
83
|
* [SCTE-35 Cli Super Tool](#the-cli-tool) Encodes, Decodes, and Recodes. This is pretty cool, it does SCTE-35 seven different ways.
|
|
@@ -11,10 +11,27 @@
|
|
|
11
11
|
* Automatic AES decryption for HLS.
|
|
12
12
|
* All HLS __SCTE-35__ Tags are Supported.
|
|
13
13
|
|
|
14
|
-
#
|
|
14
|
+
# Heads up.
|
|
15
|
+
<pre>
|
|
16
|
+
The Super Kabuki MPEGTS SCTE-35 Packet Injection Engine is working really really well.
|
|
17
|
+
I've tested the SuperKabuki output with ffmpeg and tsduck and everything works.
|
|
18
|
+
I was going to wait until I finished The Sideways HLS tag Injector,
|
|
19
|
+
but I'm thinking I'm going to go ahead and do a new build with
|
|
20
|
+
Super Kabuki, probably tomorrow.
|
|
21
|
+
|
|
22
|
+
It's workinng perfectly for me,
|
|
23
|
+
so I want to get it out there and see if y'all break it. :)
|
|
24
|
+
</pre>
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# Latest release is v3.0.39
|
|
15
28
|
_Released Thursday April 18th, 2025
|
|
29
|
+
* just 4300 lines of code.
|
|
30
|
+
* cyclomatic complexity __2.05__
|
|
16
31
|
> Stay up to date, only the latest release is supported.
|
|
17
32
|
|
|
33
|
+
|
|
34
|
+
|
|
18
35
|
## MPEGTS streams can be parsed for SCTE-35 with three lines of code.
|
|
19
36
|
|
|
20
37
|
```py3
|
|
@@ -28,16 +45,18 @@ a@fu:~/build5/scte35/scte35$ pypy3
|
|
|
28
45
|
# Checkout the Super Cool SCTE-35 [__Examples__](https://github.com/superkabuki/threefive3/tree/main/examples)
|
|
29
46
|
<br>
|
|
30
47
|
|
|
31
|
-
# threefive3 v3.0.
|
|
48
|
+
# threefive3 v3.0.39 is ready
|
|
32
49
|
|
|
33
50
|
* Xml is back and better than ever. __The new Ultra Xml Parser Supreme__ replaces the Super Xml Parser.
|
|
34
51
|
|
|
35
|
-
# [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md)
|
|
36
52
|
|
|
37
53
|
# `Documentation`
|
|
38
54
|
|
|
39
55
|
* [Install](#install)
|
|
40
56
|
|
|
57
|
+
* [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md) __New__!
|
|
58
|
+
|
|
59
|
+
|
|
41
60
|
### Cli
|
|
42
61
|
|
|
43
62
|
* [SCTE-35 Cli Super Tool](#the-cli-tool) Encodes, Decodes, and Recodes. This is pretty cool, it does SCTE-35 seven different ways.
|
|
@@ -9,12 +9,12 @@ scte35 command line SCTE35 decoder.
|
|
|
9
9
|
import select
|
|
10
10
|
import sys
|
|
11
11
|
from threefive3.gums import cli as gumscli
|
|
12
|
+
from threefive3.hls import cli as hlscli
|
|
13
|
+
from threefive3.sixfix import cli as sixcli
|
|
12
14
|
from threefive3.superkabuki import cli as skcli
|
|
13
15
|
from threefive3.iframes import IFramer
|
|
14
16
|
from threefive3.new_reader import reader
|
|
15
17
|
from threefive3 import Cue, Stream, print2, blue, version, red
|
|
16
|
-
from threefive3.hls import cli as hlscli
|
|
17
|
-
from threefive3.sixfix import sixfix
|
|
18
18
|
from threefive3.stuff import ERR
|
|
19
19
|
|
|
20
20
|
# import cProfile
|
|
@@ -61,7 +61,7 @@ HELP = f"""
|
|
|
61
61
|
|
|
62
62
|
{B} Default {U} {BLUE}The default action is to read a input and write a SCTE-35 output.{U}
|
|
63
63
|
|
|
64
|
-
{BLUE}Inputs {U} mpegts, base64, hex, json,and xmlbin{U}.
|
|
64
|
+
{BLUE}Inputs {U} mpegts, base64, hex, json,and xml, and xmlbin{U}.
|
|
65
65
|
|
|
66
66
|
{BLUE}Outputs{U} base64, bytes, hex, int, json, xml, and xmlbin.{U}
|
|
67
67
|
|
|
@@ -70,37 +70,58 @@ HELP = f"""
|
|
|
70
70
|
Input {U} Output {U}
|
|
71
71
|
{U}{BLUE} mpegts {U} {U}{BLUE} base64 {NORM} threefive3 https://example.com/video.ts base64
|
|
72
72
|
{U}{BLUE} base64 {U} {U}{BLUE} hex {NORM} threefive3 '/DAWAAAAAAAAAP/wBQb+AKmKxwAACzuu2Q==' hex
|
|
73
|
-
{U}{BLUE} xmlbin
|
|
74
|
-
{U}{BLUE}
|
|
75
|
-
{U}{BLUE} mpegts {U} {
|
|
76
|
-
{U}{BLUE} json
|
|
77
|
-
|
|
73
|
+
{U}{BLUE} xmlbin {U} {BLUE} int {NORM} threefive3 < xmlbin.xml int
|
|
74
|
+
{U}{BLUE} xml {U} {BLUE} json {NORM} threefive3 < xml.xml
|
|
75
|
+
{U}{BLUE} mpegts {U} {BLUE} json {NORM} threefive3 video.ts
|
|
76
|
+
{U}{BLUE} json{U} {BLUE} xml {NORM} threefive3 < json.json xml
|
|
77
|
+
|
|
78
|
+
{B} hls {U}{NORM}{BLUE} SCTE-35 HLS decode{U}
|
|
79
|
+
|
|
80
|
+
threefive3 hls help | threefive3 hls https://example.com/master.m3u8{U}
|
|
81
|
+
|
|
82
|
+
{B} iframes {U}{BLUE} Show MPEGTS iframes{NORM}
|
|
83
|
+
|
|
84
|
+
threefive3 iframes video.ts
|
|
85
|
+
|
|
86
|
+
{B} inject {U}{NORM}{BLUE} SuperKabuki SCTE-35 MPEGTS Packet Injection Engine{U}
|
|
87
|
+
|
|
88
|
+
threefive3 inject help
|
|
89
|
+
|
|
90
|
+
{B} mcast {U}{NORM}{BLUE} Multicast sender(server){U}
|
|
78
91
|
|
|
79
|
-
|
|
92
|
+
threefive3 mcast help | threefive3 mcast video.ts
|
|
80
93
|
|
|
81
|
-
|
|
94
|
+
{B} packets {U}{NORM}{BLUE} Print raw SCTE-35 packets{NORM}
|
|
82
95
|
|
|
83
|
-
|
|
96
|
+
threefive3 packets udp://@235.35.3.5:3535
|
|
84
97
|
|
|
85
|
-
{B}
|
|
98
|
+
{B} proxy {U}{NORM}{BLUE} Parse a MPEGTS stream and copy it to stdout{NORM}
|
|
86
99
|
|
|
87
|
-
threefive3
|
|
100
|
+
threefive3 proxy video.ts
|
|
88
101
|
|
|
89
|
-
{B}
|
|
102
|
+
{B} pts {U}{NORM}{BLUE} Print PTS from MPEGTS video{NORM}
|
|
90
103
|
|
|
91
|
-
|
|
104
|
+
threefive3 pts video.ts
|
|
92
105
|
|
|
93
|
-
{B}
|
|
106
|
+
{B} sidecar {U}{NORM}{BLUE} Create a SCTE-35 sidecar file{NORM}
|
|
94
107
|
|
|
95
|
-
|
|
108
|
+
threefive3 sidecar video.ts
|
|
96
109
|
|
|
97
|
-
{B} sixfix {U}{NORM}{BLUE} Fix SCTE-35 data mangled by ffmpeg
|
|
110
|
+
{B} sixfix {U}{NORM}{BLUE} Fix SCTE-35 data mangled by ffmpeg{NORM}
|
|
98
111
|
|
|
99
|
-
|
|
112
|
+
threefive3 sixfix video.ts
|
|
100
113
|
|
|
101
|
-
{B}
|
|
114
|
+
{B} show {U}{NORM}{BLUE} Probe MPEGTS video{NORM}
|
|
102
115
|
|
|
103
|
-
|
|
116
|
+
threefive3 show video.ts
|
|
117
|
+
|
|
118
|
+
{B} version {U}{NORM}{BLUE} Show version{NORM}
|
|
119
|
+
|
|
120
|
+
threefive3 version
|
|
121
|
+
|
|
122
|
+
{B} help {U}{NORM} {BLUE}Help{NORM}
|
|
123
|
+
|
|
124
|
+
threefive3 help
|
|
104
125
|
|
|
105
126
|
"""
|
|
106
127
|
|
|
@@ -170,6 +191,14 @@ def iframe_chk(this):
|
|
|
170
191
|
iframer.do(this)
|
|
171
192
|
|
|
172
193
|
|
|
194
|
+
def inject_chk(this):
|
|
195
|
+
"""
|
|
196
|
+
inject_chk use the superkabuki
|
|
197
|
+
packet injection engine.
|
|
198
|
+
"""
|
|
199
|
+
skcli()
|
|
200
|
+
|
|
201
|
+
|
|
173
202
|
def packet_chk(this):
|
|
174
203
|
"""
|
|
175
204
|
packet_chk checks for the packet keyword
|
|
@@ -221,7 +250,6 @@ mpegts_map = {
|
|
|
221
250
|
"pts": pts_chk,
|
|
222
251
|
"show": show_chk,
|
|
223
252
|
"sidecar": sidecar_chk,
|
|
224
|
-
"sixfix": sixfix,
|
|
225
253
|
"iframes": iframe_chk,
|
|
226
254
|
}
|
|
227
255
|
|
|
@@ -323,13 +351,13 @@ def to_funk(this):
|
|
|
323
351
|
cue = None
|
|
324
352
|
if this in ["", b""]:
|
|
325
353
|
return
|
|
326
|
-
#if not this.strip().startswith('<'):
|
|
354
|
+
# if not this.strip().startswith('<'):
|
|
327
355
|
try:
|
|
328
|
-
|
|
356
|
+
# mpegts streams handled here.
|
|
329
357
|
strm = Stream(this)
|
|
330
358
|
strm.decode(func=funk()) # funk() works here
|
|
331
359
|
except:
|
|
332
|
-
cue = Cue(this) # This is the
|
|
360
|
+
cue = Cue(this) # This is the
|
|
333
361
|
if cue:
|
|
334
362
|
funk()(cue) # funk works here too.
|
|
335
363
|
|
|
@@ -368,7 +396,13 @@ def chk_funk_map():
|
|
|
368
396
|
|
|
369
397
|
# cli map
|
|
370
398
|
|
|
371
|
-
cli_map = {
|
|
399
|
+
cli_map = {
|
|
400
|
+
"mcast": gumscli,
|
|
401
|
+
"superkabuki": skcli,
|
|
402
|
+
"inject": skcli,
|
|
403
|
+
"sixfix": sixcli,
|
|
404
|
+
"sk": skcli,
|
|
405
|
+
}
|
|
372
406
|
|
|
373
407
|
|
|
374
408
|
def dashdashhelp():
|
|
@@ -17,6 +17,7 @@ class Bitn:
|
|
|
17
17
|
self.bitsize = self.idx = len(bites) << 3
|
|
18
18
|
self.bits = int.from_bytes(bites, byteorder="big")
|
|
19
19
|
|
|
20
|
+
|
|
20
21
|
def __repr__(self):
|
|
21
22
|
return str(vars(self))
|
|
22
23
|
|
|
@@ -159,7 +160,7 @@ class NBin:
|
|
|
159
160
|
else:
|
|
160
161
|
dehexed = hex_str
|
|
161
162
|
self.add_int(dehexed, bit_len)
|
|
162
|
-
|
|
163
|
+
|
|
163
164
|
def add_flag(self, flg, bit_len=1):
|
|
164
165
|
"""
|
|
165
166
|
add_flag takes a boolean
|
|
@@ -164,7 +164,7 @@ class TimeSignal(SpliceCommand):
|
|
|
164
164
|
nbin.reserve(6)
|
|
165
165
|
if not isinstance(self.pts_time, float):
|
|
166
166
|
blue("converting pts_time from ticks")
|
|
167
|
-
self.pts_time
|
|
167
|
+
self.pts_time= self.as_90k(self.pts_time)
|
|
168
168
|
self.pts_time = round(self.pts_time, 6)
|
|
169
169
|
nbin.add_int(int(self.as_ticks(self.pts_time)), 33)
|
|
170
170
|
else:
|
|
@@ -12,19 +12,7 @@ from .commands import command_map
|
|
|
12
12
|
from .descriptors import splice_descriptor, descriptor_map
|
|
13
13
|
from .crc import crc32
|
|
14
14
|
from .segmentation import table22
|
|
15
|
-
from .words import
|
|
16
|
-
minusone,
|
|
17
|
-
zero,
|
|
18
|
-
one,
|
|
19
|
-
two,
|
|
20
|
-
three,
|
|
21
|
-
four,
|
|
22
|
-
eight,
|
|
23
|
-
eleven,
|
|
24
|
-
fourteen,
|
|
25
|
-
sixteen,
|
|
26
|
-
equalsign,
|
|
27
|
-
)
|
|
15
|
+
from .words import minusone,zero,one,two,three,four,eight,eleven,fourteen, sixteen,equalsign
|
|
28
16
|
from .uxp import xml2cue
|
|
29
17
|
|
|
30
18
|
|
|
@@ -174,7 +162,7 @@ class Cue(SCTE35Base):
|
|
|
174
162
|
if isxml(data) or isjson(data):
|
|
175
163
|
self.load(data)
|
|
176
164
|
return self.bites
|
|
177
|
-
data
|
|
165
|
+
data=data.strip()
|
|
178
166
|
if data.isdigit():
|
|
179
167
|
return self._int_bits(int(data))
|
|
180
168
|
return self._b64_bits(data)
|
|
@@ -187,7 +175,7 @@ class Cue(SCTE35Base):
|
|
|
187
175
|
return data.split(b"\x00\x00\x01\xfc", one)[minusone]
|
|
188
176
|
return data
|
|
189
177
|
|
|
190
|
-
def _byte_bits(self,
|
|
178
|
+
def _byte_bits(self,data):
|
|
191
179
|
data = self._pkt_bits(data)
|
|
192
180
|
self.bites = self.idxsplit(data, b"\xfc")
|
|
193
181
|
return self.bites
|
|
@@ -402,7 +390,7 @@ class Cue(SCTE35Base):
|
|
|
402
390
|
if isinstance(gonzo, bytes):
|
|
403
391
|
gonzo = clean(gonzo)
|
|
404
392
|
if isinstance(gonzo, str):
|
|
405
|
-
if isxml(gonzo):
|
|
393
|
+
if isxml(gonzo) :
|
|
406
394
|
self._from_xml(gonzo)
|
|
407
395
|
return self.bites
|
|
408
396
|
gonzo = json.loads(gonzo)
|
|
@@ -417,7 +405,7 @@ class Cue(SCTE35Base):
|
|
|
417
405
|
_from_xml converts xml to data that can
|
|
418
406
|
be loaded by a Cue instance.
|
|
419
407
|
"""
|
|
420
|
-
gonzo
|
|
408
|
+
gonzo=clean(gonzo)
|
|
421
409
|
if "<scte35:Binary>" in gonzo:
|
|
422
410
|
dat = gonzo.split("<scte35:Binary>")[1].split("</scte35:Binary>")[0]
|
|
423
411
|
self.bites = self._mk_bits(dat)
|
|
@@ -13,7 +13,7 @@ import sys
|
|
|
13
13
|
import time
|
|
14
14
|
from functools import partial
|
|
15
15
|
from .new_reader import reader
|
|
16
|
-
from .stuff import blue, reblue,
|
|
16
|
+
from .stuff import blue, reblue,print2
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
DGRAM_SIZE = 1316
|
|
@@ -58,7 +58,7 @@ class GumS:
|
|
|
58
58
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
|
|
59
59
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
60
60
|
if hasattr(socket, "SO_REUSEPORT"):
|
|
61
|
-
blue(
|
|
61
|
+
blue('setting SO_REUSEPORT')
|
|
62
62
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
|
63
63
|
return sock
|
|
64
64
|
|
|
@@ -78,10 +78,8 @@ class GumS:
|
|
|
78
78
|
total_bytes += len(dgram)
|
|
79
79
|
elapsed = now() - start_time
|
|
80
80
|
rate = (total_bytes / million) / elapsed
|
|
81
|
-
mb
|
|
82
|
-
reblue(
|
|
83
|
-
f"\t{mb:0.2f} MB sent in {elapsed:5.2f} seconds. {rate:3.2f} MB/Sec"
|
|
84
|
-
)
|
|
81
|
+
mb=total_bytes/million
|
|
82
|
+
reblue(f"\t{mb:0.2f} MB sent in {elapsed:5.2f} seconds. {rate:3.2f} MB/Sec")
|
|
85
83
|
print("\n", file=sys.stderr)
|
|
86
84
|
|
|
87
85
|
def send_stream(self, vid):
|
|
@@ -185,7 +183,7 @@ def cli():
|
|
|
185
183
|
"""
|
|
186
184
|
|
|
187
185
|
args = parse_args()
|
|
188
|
-
#
|
|
186
|
+
#daemonize()
|
|
189
187
|
ttl = int(args.ttl).to_bytes(1, byteorder="big")
|
|
190
188
|
dest_addr = args.addr
|
|
191
189
|
gummie = GumS(dest_addr, ttl, args.bind_addr)
|
|
@@ -4,19 +4,7 @@ hlstags.py
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
from .stuff import atohif, ERR
|
|
7
|
-
from .words import
|
|
8
|
-
minusone,
|
|
9
|
-
zero,
|
|
10
|
-
one,
|
|
11
|
-
two,
|
|
12
|
-
colon,
|
|
13
|
-
comma,
|
|
14
|
-
equalsign,
|
|
15
|
-
dblquote,
|
|
16
|
-
octothorpe,
|
|
17
|
-
space,
|
|
18
|
-
nothing,
|
|
19
|
-
)
|
|
7
|
+
from .words import minusone, zero, one, two, colon, comma, equalsign, dblquote, octothorpe, space, nothing
|
|
20
8
|
|
|
21
9
|
BASIC_TAGS = (
|
|
22
10
|
"#EXTM3U",
|
|
@@ -98,7 +86,7 @@ class TagParser:
|
|
|
98
86
|
def _colon_in_line(line):
|
|
99
87
|
return colon in line
|
|
100
88
|
|
|
101
|
-
def precheck(self,
|
|
89
|
+
def precheck(self,line):
|
|
102
90
|
"""
|
|
103
91
|
precheck precheck that a line has tags
|
|
104
92
|
"""
|
|
@@ -27,29 +27,38 @@ class Dscptr:
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
class PmtStream:
|
|
30
|
-
def __init__(self, bitn, conv_pids):
|
|
30
|
+
def __init__(self, bitn=None, conv_pids=None):
|
|
31
|
+
|
|
31
32
|
self.descriptors = []
|
|
32
|
-
self.stream_type =
|
|
33
|
-
|
|
34
|
-
self.
|
|
35
|
-
bitn
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
self.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
self.descriptors = [cuei] + self.descriptors
|
|
50
|
-
self.ES_info_length += cuei.total_size
|
|
33
|
+
self.stream_type =None
|
|
34
|
+
self.elementary_PID = None
|
|
35
|
+
self.ES_info_length = 0
|
|
36
|
+
if bitn:
|
|
37
|
+
self.stream_type = bitn.as_int(8)
|
|
38
|
+
bitn.forward(3)
|
|
39
|
+
self.elementary_PID = bitn.as_int(13)
|
|
40
|
+
bitn.forward(4)
|
|
41
|
+
self.ES_info_length = bitn.as_int(12)
|
|
42
|
+
eil = self.ES_info_length << 3
|
|
43
|
+
while eil > 0:
|
|
44
|
+
dscptr = Dscptr(bitn)
|
|
45
|
+
eil -= dscptr.total_size << 3
|
|
46
|
+
self.descriptors.append(dscptr)
|
|
47
|
+
#if conv_pids:
|
|
48
|
+
#if self.elementary_PID in conv_pids:
|
|
49
|
+
# self.add_CUEI()
|
|
51
50
|
self.total_size = 5 + self.ES_info_length
|
|
52
51
|
|
|
52
|
+
def add_CUEI(self):
|
|
53
|
+
self.stream_type = 134
|
|
54
|
+
cuei = Dscptr()
|
|
55
|
+
cuei.type = 5
|
|
56
|
+
cuei.length = 4
|
|
57
|
+
cuei.value = b"CUEI"
|
|
58
|
+
cuei.total_size = 6
|
|
59
|
+
self.descriptors = [cuei] + self.descriptors
|
|
60
|
+
self.ES_info_length += cuei.total_size
|
|
61
|
+
|
|
53
62
|
def __repr__(self):
|
|
54
63
|
return str(vars(self))
|
|
55
64
|
|
|
@@ -109,21 +118,29 @@ class PMT:
|
|
|
109
118
|
while self.bitn.idx > 32:
|
|
110
119
|
pms = PmtStream(self.bitn, self.conv_pids)
|
|
111
120
|
streams.append(pms)
|
|
112
|
-
|
|
121
|
+
# pprint.pprint(streams)
|
|
113
122
|
return streams
|
|
114
123
|
|
|
124
|
+
def add_SCTE35stream(self,pid):
|
|
125
|
+
pms = PmtStream()
|
|
126
|
+
pms.elementary_PID=pid
|
|
127
|
+
pms.stream_type=0x86
|
|
128
|
+
#pms.add_CUEI()
|
|
129
|
+
pms.total_size=5
|
|
130
|
+
self.streams.append(pms)
|
|
131
|
+
|
|
115
132
|
def mk(self):
|
|
116
133
|
vals = [dscptr.value for dscptr in self.descriptors]
|
|
117
134
|
if b"CUEI" not in vals:
|
|
118
|
-
|
|
135
|
+
# blue("Adding SCTE-35 Descriptor")
|
|
119
136
|
cuei = Dscptr()
|
|
120
137
|
cuei.type = 5
|
|
121
138
|
cuei.length = 4
|
|
122
139
|
cuei.value = b"CUEI"
|
|
123
140
|
cuei.total_size = 6
|
|
124
141
|
self.descriptors.append(cuei)
|
|
125
|
-
|
|
126
|
-
|
|
142
|
+
# else:
|
|
143
|
+
# blue("SCTE-35 Descriptor already present.")
|
|
127
144
|
self.program_info_length = sum(
|
|
128
145
|
[dscptr.total_size for dscptr in self.descriptors]
|
|
129
146
|
)
|
|
@@ -132,8 +149,8 @@ class PMT:
|
|
|
132
149
|
nbin.add_int(self.table_id, 8) # 0x02
|
|
133
150
|
nbin.add_int(self.section_syntax_indicator, 1) # 9
|
|
134
151
|
nbin.add_int(self.zero, 1) # 10
|
|
135
|
-
nbin.
|
|
136
|
-
self.section_length =
|
|
152
|
+
nbin.add_int(3,2) # 12
|
|
153
|
+
self.section_length = 13 + self.program_info_length + stream_len
|
|
137
154
|
nbin.add_int(self.section_length, 12) # 24
|
|
138
155
|
nbin.add_int(self.program_number, 16) # 40
|
|
139
156
|
nbin.reserve(2) # 42
|
|
@@ -151,8 +168,8 @@ class PMT:
|
|
|
151
168
|
stream.add(nbin)
|
|
152
169
|
self.crc32 = crc32(nbin.bites)
|
|
153
170
|
nbin.add_int(self.crc32, 32)
|
|
154
|
-
|
|
155
|
-
return nbin.bites
|
|
171
|
+
# nbin.add_int(0, 8)
|
|
172
|
+
return b'\x00'+nbin.bites
|
|
156
173
|
|
|
157
174
|
self.program_info_length = None
|
|
158
175
|
self.descriptors = []
|
|
@@ -188,7 +188,7 @@ class SpliceInfoSection(SCTE35Base):
|
|
|
188
188
|
"pts_adjustment": self.as_ticks(self.pts_adjustment),
|
|
189
189
|
"protocol_version": self.protocol_version,
|
|
190
190
|
"sap_type": self.sap_type,
|
|
191
|
-
"tier": int(self.tier,
|
|
191
|
+
"tier": int(self.tier,base=16),
|
|
192
192
|
}
|
|
193
193
|
sis = Node("SpliceInfoSection", attrs=sis_attrs, ns=ns)
|
|
194
194
|
return sis
|
|
@@ -4,10 +4,11 @@ sixfix.py
|
|
|
4
4
|
|
|
5
5
|
import io
|
|
6
6
|
import sys
|
|
7
|
+
from collections import deque
|
|
7
8
|
from functools import partial
|
|
8
9
|
from .crc import crc32
|
|
9
10
|
from .bitn import NBin
|
|
10
|
-
from .stuff import print2
|
|
11
|
+
from .stuff import print2, ERR
|
|
11
12
|
from .stream import Stream, ProgramInfo
|
|
12
13
|
from .pmt import PMT
|
|
13
14
|
|
|
@@ -48,11 +49,14 @@ class SixFix(Stream):
|
|
|
48
49
|
def __init__(self, tsdata=None):
|
|
49
50
|
super().__init__(tsdata)
|
|
50
51
|
self.pmt_payloads = {}
|
|
51
|
-
self.pmt_headers =
|
|
52
|
+
self.pmt_headers = deque() # popleft()
|
|
52
53
|
self.pmt_inputs = []
|
|
53
54
|
self.pid_prog = {}
|
|
54
55
|
self.con_pids = set()
|
|
55
|
-
|
|
56
|
+
try:
|
|
57
|
+
self.out_file = "sixfixed-" + tsdata.rsplit("/")[-1]
|
|
58
|
+
except ERR:
|
|
59
|
+
pass
|
|
56
60
|
self.in_file = sys.stdin.buffer
|
|
57
61
|
|
|
58
62
|
def iter_pkts(self, num_pkts=1):
|
|
@@ -62,12 +66,8 @@ class SixFix(Stream):
|
|
|
62
66
|
return iter(partial(self._tsdata.read, self.PACKET_SIZE * num_pkts), b"")
|
|
63
67
|
|
|
64
68
|
def _parse_by_pid(self, pkt, pid):
|
|
65
|
-
## if b'\x00\x00\x01' in pkt:
|
|
66
|
-
## if b'\x00\x00\x01\xc0' not in pkt:
|
|
67
|
-
## print("pid", pid, ' : ', pkt)
|
|
68
|
-
|
|
69
69
|
if pid in self.pids.pmt:
|
|
70
|
-
self.pmt_headers.
|
|
70
|
+
self.pmt_headers.append(pkt[:4])
|
|
71
71
|
self._parse_pmt(pkt[4:], pid)
|
|
72
72
|
prgm = self.pid2prgm(pid)
|
|
73
73
|
if prgm in self.pmt_payloads:
|
|
@@ -80,7 +80,7 @@ class SixFix(Stream):
|
|
|
80
80
|
def _parse_pkts(self, out_file):
|
|
81
81
|
active = io.BytesIO()
|
|
82
82
|
pkt_count = 0
|
|
83
|
-
chunk_size =
|
|
83
|
+
chunk_size = 1442
|
|
84
84
|
for pkt in self.iter_pkts():
|
|
85
85
|
pid = self._parse_pid(pkt[1], pkt[2])
|
|
86
86
|
pkt = self._parse_by_pid(pkt, pid)
|
|
@@ -97,15 +97,11 @@ class SixFix(Stream):
|
|
|
97
97
|
changes the stream type to 0x86 and replaces
|
|
98
98
|
the existing PMT as it writes packets to the outfile
|
|
99
99
|
"""
|
|
100
|
-
# if isinstance(self.out_file, str):
|
|
101
|
-
# self.out_file = open(self.out_file, "wb")
|
|
102
100
|
with open(self.out_file, "wb") as out_file:
|
|
103
101
|
self._parse_pkts(out_file)
|
|
104
102
|
|
|
105
103
|
def _chk_payload(self, pay, pid):
|
|
106
104
|
pay = self._chk_partial(pay, pid, self._PMT_TID)
|
|
107
|
-
## if not pay:
|
|
108
|
-
## return False
|
|
109
105
|
return pay
|
|
110
106
|
|
|
111
107
|
def _unpad_pmt(self, pay):
|
|
@@ -117,7 +113,7 @@ class SixFix(Stream):
|
|
|
117
113
|
"""
|
|
118
114
|
pmt2packets split the new pmt table into 188 byte packets
|
|
119
115
|
"""
|
|
120
|
-
pmt =
|
|
116
|
+
pmt = self.pmt_headers.popleft() + pmt.mk()
|
|
121
117
|
if len(pmt) < 188:
|
|
122
118
|
pad = (188 - len(pmt)) * b"\xff"
|
|
123
119
|
self.pmt_payloads[program_number] = pmt + pad
|
|
@@ -128,14 +124,12 @@ class SixFix(Stream):
|
|
|
128
124
|
three = b""
|
|
129
125
|
pad2 = b""
|
|
130
126
|
pad3 = b""
|
|
131
|
-
|
|
132
|
-
if len(self.pmt_headers) >
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if len(three) < 188:
|
|
138
|
-
pad3 = (188 - len(three)) * b"\xff"
|
|
127
|
+
two = self.pmt_headers.popleft() + pmt[188:]
|
|
128
|
+
if len(self.pmt_headers) > 2:
|
|
129
|
+
three = self.pmt_headers.popleft()+ two[188:]
|
|
130
|
+
two = two[:188]
|
|
131
|
+
if len(three) < 188:
|
|
132
|
+
pad3 = (188 - len(three)) * b"\xff"
|
|
139
133
|
elif len(two) < 188:
|
|
140
134
|
pad2 = (188 - len(two)) * b"\xff"
|
|
141
135
|
|
|
@@ -147,11 +141,15 @@ class SixFix(Stream):
|
|
|
147
141
|
pay = self._chk_payload(pay, pid)
|
|
148
142
|
if not pay:
|
|
149
143
|
return False
|
|
150
|
-
if pay in self.pmt_inputs:
|
|
151
|
-
return False
|
|
144
|
+
## if pay in self.pmt_inputs: <<---- this breaks continuity counters
|
|
145
|
+
## return False
|
|
152
146
|
self.pmt_inputs.append(pay)
|
|
153
147
|
return pay
|
|
154
148
|
|
|
149
|
+
def mk_pmt(self,pay):
|
|
150
|
+
pmt = PMT(pay, self.con_pids)
|
|
151
|
+
return pmt
|
|
152
|
+
|
|
155
153
|
def _parse_pmt(self, pay, pid):
|
|
156
154
|
"""
|
|
157
155
|
parse program maps for streams
|
|
@@ -159,7 +157,7 @@ class SixFix(Stream):
|
|
|
159
157
|
pay = self._pmt_precheck(pay, pid)
|
|
160
158
|
if not pay:
|
|
161
159
|
return False
|
|
162
|
-
pmt =
|
|
160
|
+
pmt = self.mk_pmt(pay)
|
|
163
161
|
seclen = self._parse_length(pay[1], pay[2])
|
|
164
162
|
n_seclen = seclen + 6
|
|
165
163
|
if self._section_incomplete(pay, pid, seclen):
|
|
@@ -240,6 +238,10 @@ def sixfix(arg):
|
|
|
240
238
|
print2(f'Wrote: sixfixed-{arg.rsplit("/")[-1]}\n')
|
|
241
239
|
return
|
|
242
240
|
|
|
241
|
+
def cli():
|
|
242
|
+
args = sys.argv[1:]
|
|
243
|
+
_= [ sixfix(arg) for arg in args]
|
|
244
|
+
|
|
243
245
|
|
|
244
246
|
if __name__ == "__main__":
|
|
245
|
-
|
|
247
|
+
cli()
|
|
@@ -6,7 +6,7 @@ import sys
|
|
|
6
6
|
|
|
7
7
|
from functools import partial
|
|
8
8
|
from .new_reader import reader
|
|
9
|
-
from .stuff import print2,
|
|
9
|
+
from .stuff import print2,blue,ERR
|
|
10
10
|
from .cue import Cue
|
|
11
11
|
from .packetdata import PacketData
|
|
12
12
|
from .streamtypes import streamtype_map
|
|
@@ -160,9 +160,9 @@ class Stream:
|
|
|
160
160
|
self.the_scte35_pids = []
|
|
161
161
|
self.pids = Pids()
|
|
162
162
|
self.maps = Maps()
|
|
163
|
-
|
|
164
|
-
self.pmt_payloads
|
|
165
|
-
self.pmt_count
|
|
163
|
+
# self.iframer = IFramer(shush=True)
|
|
164
|
+
self.pmt_payloads=set()
|
|
165
|
+
self.pmt_count=0
|
|
166
166
|
|
|
167
167
|
def __repr__(self):
|
|
168
168
|
return str(self.__dict__)
|
|
@@ -318,7 +318,7 @@ class Stream:
|
|
|
318
318
|
self.info = True
|
|
319
319
|
for pkt in self.iter_pkts():
|
|
320
320
|
self._parse(pkt)
|
|
321
|
-
if self.pmt_count > len(self.pmt_payloads) <<
|
|
321
|
+
if self.pmt_count > len(self.pmt_payloads) <<1:
|
|
322
322
|
blue(f"PMT Count: {self.pmt_count}")
|
|
323
323
|
break
|
|
324
324
|
if self.maps.prgm.keys():
|
|
@@ -380,26 +380,26 @@ class Stream:
|
|
|
380
380
|
return False
|
|
381
381
|
|
|
382
382
|
def _unpad_afc(self, pkt):
|
|
383
|
-
|
|
384
|
-
return
|
|
383
|
+
# if self._afc_flag(pkt[3]):
|
|
384
|
+
return pkt[:4] + self._unpad(pkt[4:])
|
|
385
385
|
|
|
386
386
|
def _unpad(self, bites=b""):
|
|
387
387
|
return bites.strip(b"\xff")
|
|
388
388
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
389
|
+
## def _unpad(self, bites):
|
|
390
|
+
## pad = 255
|
|
391
|
+
## one = 1
|
|
392
|
+
## if not bites:
|
|
393
|
+
## return b""
|
|
394
|
+
## while bites[0] == pad:
|
|
395
|
+
## bites = bites[1:]
|
|
396
|
+
## return self._unpad2(bites)
|
|
397
|
+
##
|
|
398
|
+
## def _unpad2(self, bites):
|
|
399
|
+
## pad = 255
|
|
400
|
+
## while bites[-1] == pad:
|
|
401
|
+
## bites = bites[:-1]
|
|
402
|
+
## return bites
|
|
403
403
|
|
|
404
404
|
def _mk_packet_data(self, pid):
|
|
405
405
|
prgm = self.maps.pid_prgm[pid]
|
|
@@ -450,6 +450,7 @@ class Stream:
|
|
|
450
450
|
def _afc_flag(pkt):
|
|
451
451
|
return pkt[3] & 32
|
|
452
452
|
|
|
453
|
+
|
|
453
454
|
def _parse_payload(self, pkt):
|
|
454
455
|
"""
|
|
455
456
|
_parse_payload returns the packet payload
|
|
@@ -461,14 +462,14 @@ class Stream:
|
|
|
461
462
|
head_size += afl + 1 # +one for afl byte
|
|
462
463
|
return pkt[head_size:]
|
|
463
464
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
465
|
+
## def _pmt_pid(self, pay, pid):
|
|
466
|
+
## if pid in self.pids.pmt:
|
|
467
|
+
## self.pmt_count+=1
|
|
468
|
+
## if self.pmt_count > 10:
|
|
469
|
+
## if pay in self.pmt_payloads:
|
|
470
|
+
## return
|
|
471
|
+
## self.pmt_payloads.add(pay)
|
|
472
|
+
## self._parse_pmt(pay, pid)
|
|
472
473
|
|
|
473
474
|
def _pmt_pid(self, pay, pid):
|
|
474
475
|
self.pmt_count += 1
|
|
@@ -482,7 +483,7 @@ class Stream:
|
|
|
482
483
|
if pid == self.pids.PAT_PID:
|
|
483
484
|
self._parse_pat(pay)
|
|
484
485
|
|
|
485
|
-
def _sdt_pid(self,
|
|
486
|
+
def _sdt_pid(self,pay,pid):
|
|
486
487
|
if pid == self.pids.SDT_PID:
|
|
487
488
|
self._parse_sdt(pay)
|
|
488
489
|
|
|
@@ -7,16 +7,8 @@ print2, atohif, iso8601, red, blue
|
|
|
7
7
|
import datetime
|
|
8
8
|
from sys import stderr
|
|
9
9
|
|
|
10
|
-
ERR = (
|
|
11
|
-
|
|
12
|
-
ValueError,
|
|
13
|
-
OSError,
|
|
14
|
-
TypeError,
|
|
15
|
-
IndexError,
|
|
16
|
-
NameError,
|
|
17
|
-
AttributeError,
|
|
18
|
-
KeyError,
|
|
19
|
-
)
|
|
10
|
+
ERR = (LookupError,ValueError,OSError,TypeError,IndexError,
|
|
11
|
+
NameError,AttributeError,KeyError)
|
|
20
12
|
|
|
21
13
|
write2 = True
|
|
22
14
|
|
|
@@ -56,22 +48,22 @@ def clean(data):
|
|
|
56
48
|
clean strip and if it's a byte string
|
|
57
49
|
convert to a string
|
|
58
50
|
"""
|
|
59
|
-
if not isinstance(data,
|
|
51
|
+
if not isinstance(data,(str,bytes)):
|
|
60
52
|
return data
|
|
61
|
-
data
|
|
62
|
-
if isinstance(data,
|
|
53
|
+
data=data.strip()
|
|
54
|
+
if isinstance(data,bytes):
|
|
63
55
|
try:
|
|
64
|
-
data
|
|
56
|
+
data=data.decode()
|
|
65
57
|
except ERR:
|
|
66
58
|
pass
|
|
67
|
-
return
|
|
59
|
+
return data
|
|
68
60
|
|
|
69
61
|
|
|
70
62
|
def ishex(data):
|
|
71
63
|
"""
|
|
72
64
|
ishex determine if a string is a hex value.
|
|
73
65
|
"""
|
|
74
|
-
if isinstance(data,
|
|
66
|
+
if isinstance(data,str):
|
|
75
67
|
hexed = "0123456789abcdef"
|
|
76
68
|
data = data.lower().strip("0x")
|
|
77
69
|
return all([c in hexed for c in data])
|
|
@@ -84,11 +76,10 @@ def isjson(data):
|
|
|
84
76
|
is json.
|
|
85
77
|
"""
|
|
86
78
|
data = clean(data)
|
|
87
|
-
if data[0] in [
|
|
88
|
-
if data[-1] in [
|
|
79
|
+
if data[0] in ['{' , b'{']:
|
|
80
|
+
if data[-1] in ['}',b'}']:
|
|
89
81
|
return True
|
|
90
|
-
return
|
|
91
|
-
|
|
82
|
+
return False
|
|
92
83
|
|
|
93
84
|
def isxml(data):
|
|
94
85
|
"""
|
|
@@ -96,11 +87,10 @@ def isxml(data):
|
|
|
96
87
|
is xml.
|
|
97
88
|
"""
|
|
98
89
|
data = clean(data)
|
|
99
|
-
if data[0] in [
|
|
100
|
-
if data[-1] in [
|
|
90
|
+
if data[0] in ['<',b'<']:
|
|
91
|
+
if data[-1] in ['>',b'>']:
|
|
101
92
|
return True
|
|
102
|
-
return
|
|
103
|
-
|
|
93
|
+
return False
|
|
104
94
|
|
|
105
95
|
def iso8601():
|
|
106
96
|
"""
|
|
@@ -4,6 +4,7 @@ Super Kabuki - SCTE-35 Packet injection
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
import argparse
|
|
7
|
+
import io
|
|
7
8
|
import sys
|
|
8
9
|
from collections import deque
|
|
9
10
|
from operator import itemgetter
|
|
@@ -15,13 +16,14 @@ from .stuff import print2, ERR
|
|
|
15
16
|
from .crc import crc32
|
|
16
17
|
from .bitn import NBin
|
|
17
18
|
from .commands import TimeSignal
|
|
18
|
-
|
|
19
|
+
from .sixfix import SixFix
|
|
20
|
+
from .pmt import PMT
|
|
19
21
|
|
|
20
22
|
REV = "\033[7m"
|
|
21
23
|
NORM = "\033[27m"
|
|
22
24
|
|
|
23
25
|
|
|
24
|
-
class SuperKabuki(
|
|
26
|
+
class SuperKabuki(SixFix):
|
|
25
27
|
"""
|
|
26
28
|
Super Kabuki - SCTE-35 Packet injection
|
|
27
29
|
|
|
@@ -40,8 +42,6 @@ class SuperKabuki(Stream):
|
|
|
40
42
|
if isinstance(tsdata, str):
|
|
41
43
|
self.outfile = f'superkabuki-{tsdata.rsplit("/",1)[1]}'
|
|
42
44
|
super().__init__(tsdata)
|
|
43
|
-
self.pmt_payload = None
|
|
44
|
-
self.pmt_header = None
|
|
45
45
|
self.scte35_pid = None
|
|
46
46
|
self.scte35_cc = 0
|
|
47
47
|
self.iframer = IFramer(shush=True)
|
|
@@ -134,36 +134,6 @@ class SuperKabuki(Stream):
|
|
|
134
134
|
def _bump_cc(self):
|
|
135
135
|
self.scte35_cc = (self.scte35_cc + 1) % 16
|
|
136
136
|
|
|
137
|
-
def _pmt_scte35_stream(self):
|
|
138
|
-
if self.scte35_pid:
|
|
139
|
-
nbin = NBin()
|
|
140
|
-
stream_type = 0x86
|
|
141
|
-
nbin.add_int(stream_type, 8)
|
|
142
|
-
nbin.add_int(7, 3) # reserved 0b111
|
|
143
|
-
nbin.add_int(self.scte35_pid, 13)
|
|
144
|
-
nbin.add_int(15, 4) # reserved 0b1111
|
|
145
|
-
es_info_length = 0
|
|
146
|
-
nbin.add_int(es_info_length, 12)
|
|
147
|
-
scte35_stream = nbin.bites
|
|
148
|
-
print2("\nAdded Stream:")
|
|
149
|
-
print2(
|
|
150
|
-
f"\tStream Type: {stream_type} PID: {self.scte35_pid} EI Len: {es_info_length}"
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
return scte35_stream
|
|
154
|
-
|
|
155
|
-
def _parse_pmt_header(self, pkt):
|
|
156
|
-
"""
|
|
157
|
-
_parse_pmt_header sets self.pmt_header
|
|
158
|
-
to header + afc for pmt packets
|
|
159
|
-
"""
|
|
160
|
-
head_size = 4
|
|
161
|
-
if self._afc_flag(pkt[3]):
|
|
162
|
-
afl = pkt[4]
|
|
163
|
-
pkt = pkt[:5] + self._unpad(pkt[5:])
|
|
164
|
-
head_size += afl + 1 # +1 for afl byte
|
|
165
|
-
self.pmt_header = pkt[:head_size]
|
|
166
|
-
|
|
167
137
|
def open_output(self):
|
|
168
138
|
"""
|
|
169
139
|
open_output open output file
|
|
@@ -192,13 +162,13 @@ class SuperKabuki(Stream):
|
|
|
192
162
|
if self.time_signals:
|
|
193
163
|
outfile.write(self._gen_time_signal(pts))
|
|
194
164
|
|
|
195
|
-
def add_scte35_pkt(self, pts,
|
|
165
|
+
def add_scte35_pkt(self, pts, active):
|
|
196
166
|
"""
|
|
197
167
|
add_scte35_pkt
|
|
198
168
|
"""
|
|
199
169
|
scte35_pkt = self.chk_sidecar_cues(pts)
|
|
200
170
|
if scte35_pkt:
|
|
201
|
-
|
|
171
|
+
active.write(scte35_pkt)
|
|
202
172
|
|
|
203
173
|
def parse_pkt(self, pkt):
|
|
204
174
|
"""
|
|
@@ -211,6 +181,25 @@ class SuperKabuki(Stream):
|
|
|
211
181
|
pkt = self.pad_pkt(pkt)
|
|
212
182
|
return pkt
|
|
213
183
|
|
|
184
|
+
def iframe_action(self,pkt,active):
|
|
185
|
+
"""
|
|
186
|
+
iframe_action this is what we do when we find an iframe.
|
|
187
|
+
"""
|
|
188
|
+
pts = self.iframer.parse(pkt) # insert on iframe
|
|
189
|
+
if pts:
|
|
190
|
+
self.auto_time_signals(pts, active)
|
|
191
|
+
self.load_sidecar(pts)
|
|
192
|
+
self.add_scte35_pkt(pts, active)
|
|
193
|
+
|
|
194
|
+
def mk_pmt(self,pay):
|
|
195
|
+
"""
|
|
196
|
+
mk_pmt generate PMT with the new SCTE-35 stream.
|
|
197
|
+
"""
|
|
198
|
+
pmt = PMT(pay, self.con_pids)
|
|
199
|
+
pmt.add_SCTE35stream(self.scte35_pid)
|
|
200
|
+
return pmt
|
|
201
|
+
|
|
202
|
+
|
|
214
203
|
def encode(self):
|
|
215
204
|
"""
|
|
216
205
|
encode parses the video input,
|
|
@@ -220,14 +209,20 @@ class SuperKabuki(Stream):
|
|
|
220
209
|
|
|
221
210
|
"""
|
|
222
211
|
self.open_output()
|
|
212
|
+
active = io.BytesIO()
|
|
213
|
+
pkt_count = 0
|
|
214
|
+
chunk_size = 1442
|
|
223
215
|
with self.outfile as outfile:
|
|
224
216
|
for pkt in self.iter_pkts():
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
self.
|
|
229
|
-
|
|
230
|
-
|
|
217
|
+
pid = self._parse_pid(pkt[1], pkt[2])
|
|
218
|
+
pkt = self._parse_by_pid(pkt, pid)
|
|
219
|
+
if pkt:
|
|
220
|
+
self.iframe_action(pkt,active)
|
|
221
|
+
active.write(pkt)
|
|
222
|
+
pkt_count = (pkt_count + 1) % chunk_size
|
|
223
|
+
if not pkt_count:
|
|
224
|
+
outfile.write(active.getbuffer())
|
|
225
|
+
active = io.BytesIO()
|
|
231
226
|
|
|
232
227
|
def _gen_time_signal(self, pts):
|
|
233
228
|
cue = Cue()
|
|
@@ -315,100 +310,6 @@ class SuperKabuki(Stream):
|
|
|
315
310
|
self._bump_cc()
|
|
316
311
|
return nbin.bites
|
|
317
312
|
|
|
318
|
-
def _regen_pmt(self, pcr_pid, n_info_bites, n_streams):
|
|
319
|
-
nbin = NBin()
|
|
320
|
-
nbin.add_int(2, 8) # 0x02
|
|
321
|
-
nbin.add_int(1, 1) # section Syntax indicator
|
|
322
|
-
nbin.add_int(0, 1) # 0
|
|
323
|
-
nbin.add_int(3, 2) # reserved
|
|
324
|
-
seclen = 9 + len(n_info_bites) + len(n_streams) + 4
|
|
325
|
-
nbin.add_int(seclen, 12) # section length
|
|
326
|
-
nbin.add_int(1, 16) # program number 16
|
|
327
|
-
nbin.add_int(3, 2) # reserved 18
|
|
328
|
-
nbin.add_int(0, 5) # version 23
|
|
329
|
-
nbin.add_int(1, 1) # current_next_indicator 24
|
|
330
|
-
nbin.add_int(0, 8) # section number 32
|
|
331
|
-
nbin.add_int(0, 8) # last section number 40
|
|
332
|
-
nbin.add_int(7, 3) # res 43
|
|
333
|
-
nbin.add_int(pcr_pid, 13) # 56
|
|
334
|
-
nbin.add_int(15, 4) # res 60
|
|
335
|
-
nbin.add_int(len(n_info_bites), 12) # 72 bits
|
|
336
|
-
nbin.add_bites(n_info_bites)
|
|
337
|
-
nbin.add_bites(n_streams)
|
|
338
|
-
a_crc = crc32(nbin.bites)
|
|
339
|
-
nbin.add_int(a_crc, 32)
|
|
340
|
-
n_payload = nbin.bites
|
|
341
|
-
pointer_field = b"\x00"
|
|
342
|
-
self.pmt_payload = pointer_field + n_payload
|
|
343
|
-
|
|
344
|
-
def _parse_pmt(self, pay, pid):
|
|
345
|
-
"""
|
|
346
|
-
parse program maps for streams
|
|
347
|
-
"""
|
|
348
|
-
pay = self._chk_partial(pay, pid, self.PMT_TID)
|
|
349
|
-
if not pay:
|
|
350
|
-
return False
|
|
351
|
-
seclen = self._parse_length(pay[1], pay[2])
|
|
352
|
-
print2(f"PMT Section Length: {seclen}")
|
|
353
|
-
n_seclen = seclen
|
|
354
|
-
if self._section_incomplete(pay, pid, seclen):
|
|
355
|
-
return False
|
|
356
|
-
program_number = self._parse_program(pay[3], pay[4])
|
|
357
|
-
print2(f"Program Number: {program_number}")
|
|
358
|
-
pcr_pid = self._parse_pid(pay[8], pay[9])
|
|
359
|
-
print2(f"PCR PID: {pcr_pid}")
|
|
360
|
-
self.pids.pcr.add(pcr_pid)
|
|
361
|
-
self.maps.pid_prgm[pcr_pid] = program_number
|
|
362
|
-
proginfolen = self._parse_length(pay[10], pay[11])
|
|
363
|
-
print2(f"Program Info Length: {proginfolen}")
|
|
364
|
-
idx = 12
|
|
365
|
-
end = idx + proginfolen
|
|
366
|
-
info_bites = pay[idx:end]
|
|
367
|
-
n_info_bites = info_bites + self.CUEI_DESCRIPTOR
|
|
368
|
-
print2(f"\nAdded Registration Descriptor:\n\t{self.CUEI_DESCRIPTOR}")
|
|
369
|
-
while idx < end:
|
|
370
|
-
# d_type = pay[idx]
|
|
371
|
-
idx += 1
|
|
372
|
-
d_len = pay[idx]
|
|
373
|
-
idx += 1
|
|
374
|
-
# d_bytes = pay[idx - 2 : idx + d_len]
|
|
375
|
-
idx += d_len
|
|
376
|
-
si_len = n_seclen - 9
|
|
377
|
-
si_len -= proginfolen
|
|
378
|
-
streams = self._parse_program_streams(si_len, pay, idx, program_number)
|
|
379
|
-
n_streams = streams + self._pmt_scte35_stream()
|
|
380
|
-
self._regen_pmt(pcr_pid, n_info_bites, n_streams)
|
|
381
|
-
return True
|
|
382
|
-
|
|
383
|
-
def _parse_program_streams(self, si_len, pay, idx, program_number):
|
|
384
|
-
"""
|
|
385
|
-
parse the elementary streams
|
|
386
|
-
from a program
|
|
387
|
-
"""
|
|
388
|
-
# 5 bytes for stream_type info
|
|
389
|
-
chunk_size = 5
|
|
390
|
-
end_idx = (idx + si_len) - 4
|
|
391
|
-
start = idx
|
|
392
|
-
print2("\nFound Streams:")
|
|
393
|
-
while idx < end_idx:
|
|
394
|
-
stream_type, pid, ei_len = self._parse_stream_type(pay, idx)
|
|
395
|
-
print2(f"\tStream Type: {stream_type} PID: { pid} EI Len: {ei_len}")
|
|
396
|
-
idx += chunk_size
|
|
397
|
-
idx += ei_len
|
|
398
|
-
self.maps.pid_prgm[pid] = program_number
|
|
399
|
-
self._chk_pid_stream_type(pid, stream_type)
|
|
400
|
-
streams = pay[start:end_idx]
|
|
401
|
-
return streams
|
|
402
|
-
|
|
403
|
-
def _chk_pid_stream_type(self, pid, stream_type):
|
|
404
|
-
"""
|
|
405
|
-
if stream_type is 0x06 or 0x86
|
|
406
|
-
add it to self._scte35_pids.
|
|
407
|
-
"""
|
|
408
|
-
if stream_type in ["0x6", "0x86"]:
|
|
409
|
-
self.pids.scte35.add(pid)
|
|
410
|
-
|
|
411
|
-
|
|
412
313
|
def cli():
|
|
413
314
|
"""
|
|
414
315
|
cli handles all the command line args
|
|
@@ -5,11 +5,10 @@ xml.py The Node class for converting to xml,
|
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
from xml.sax.saxutils import escape, unescape
|
|
8
|
-
from .stuff import red
|
|
9
|
-
|
|
10
|
-
MAXCHILDREN = 128
|
|
11
|
-
MAXDEPTH = 64
|
|
8
|
+
from .stuff import red
|
|
12
9
|
|
|
10
|
+
MAXCHILDREN=128
|
|
11
|
+
MAXDEPTH= 64
|
|
13
12
|
|
|
14
13
|
def t2s(v):
|
|
15
14
|
"""
|
|
@@ -226,7 +225,7 @@ class Node:
|
|
|
226
225
|
"""
|
|
227
226
|
for child in self.children:
|
|
228
227
|
while self.depth > MAXDEPTH:
|
|
229
|
-
red(f
|
|
228
|
+
red(f'{self.depth} is too deep for SCTE-35 nodes.')
|
|
230
229
|
return False
|
|
231
230
|
child.depth = self.depth + 1
|
|
232
231
|
|
|
@@ -304,7 +303,7 @@ class Node:
|
|
|
304
303
|
set slot to insert at index slot.
|
|
305
304
|
"""
|
|
306
305
|
while len(self.children) > MAXCHILDREN:
|
|
307
|
-
red(f
|
|
306
|
+
red(f'{len(self.children)} is too many children')
|
|
308
307
|
return False
|
|
309
308
|
if not slot:
|
|
310
309
|
slot = len(self.children)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: threefive3
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.41
|
|
4
4
|
Summary: SCTE-35 decoder and encoder with MPEGTS and HLS and XML support.
|
|
5
5
|
Home-page: https://github.com/superkabuki/threefive3
|
|
6
6
|
Author: Adrian of Doom
|
|
@@ -32,10 +32,27 @@ License-File: LICENSE
|
|
|
32
32
|
* Automatic AES decryption for HLS.
|
|
33
33
|
* All HLS __SCTE-35__ Tags are Supported.
|
|
34
34
|
|
|
35
|
-
#
|
|
35
|
+
# Heads up.
|
|
36
|
+
<pre>
|
|
37
|
+
The Super Kabuki MPEGTS SCTE-35 Packet Injection Engine is working really really well.
|
|
38
|
+
I've tested the SuperKabuki output with ffmpeg and tsduck and everything works.
|
|
39
|
+
I was going to wait until I finished The Sideways HLS tag Injector,
|
|
40
|
+
but I'm thinking I'm going to go ahead and do a new build with
|
|
41
|
+
Super Kabuki, probably tomorrow.
|
|
42
|
+
|
|
43
|
+
It's workinng perfectly for me,
|
|
44
|
+
so I want to get it out there and see if y'all break it. :)
|
|
45
|
+
</pre>
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Latest release is v3.0.39
|
|
36
49
|
_Released Thursday April 18th, 2025
|
|
50
|
+
* just 4300 lines of code.
|
|
51
|
+
* cyclomatic complexity __2.05__
|
|
37
52
|
> Stay up to date, only the latest release is supported.
|
|
38
53
|
|
|
54
|
+
|
|
55
|
+
|
|
39
56
|
## MPEGTS streams can be parsed for SCTE-35 with three lines of code.
|
|
40
57
|
|
|
41
58
|
```py3
|
|
@@ -49,16 +66,18 @@ a@fu:~/build5/scte35/scte35$ pypy3
|
|
|
49
66
|
# Checkout the Super Cool SCTE-35 [__Examples__](https://github.com/superkabuki/threefive3/tree/main/examples)
|
|
50
67
|
<br>
|
|
51
68
|
|
|
52
|
-
# threefive3 v3.0.
|
|
69
|
+
# threefive3 v3.0.39 is ready
|
|
53
70
|
|
|
54
71
|
* Xml is back and better than ever. __The new Ultra Xml Parser Supreme__ replaces the Super Xml Parser.
|
|
55
72
|
|
|
56
|
-
# [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md)
|
|
57
73
|
|
|
58
74
|
# `Documentation`
|
|
59
75
|
|
|
60
76
|
* [Install](#install)
|
|
61
77
|
|
|
78
|
+
* [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md) __New__!
|
|
79
|
+
|
|
80
|
+
|
|
62
81
|
### Cli
|
|
63
82
|
|
|
64
83
|
* [SCTE-35 Cli Super Tool](#the-cli-tool) Encodes, Decodes, and Recodes. This is pretty cool, it does SCTE-35 seven different ways.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|