threefive3 3.0.37__tar.gz → 3.0.43__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.43}/PKG-INFO +47 -6
- {threefive3-3.0.37 → threefive3-3.0.43}/README.md +46 -5
- {threefive3-3.0.37 → threefive3-3.0.43}/bin/threefive3 +60 -26
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/crc.py +6 -6
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/cue.py +2 -2
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/hls.py +1 -1
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/pmt.py +45 -36
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/sixfix.py +37 -44
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/stream.py +2 -26
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/superkabuki.py +36 -151
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/uxp.py +1 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/version.py +1 -1
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/xml.py +3 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3.egg-info/PKG-INFO +47 -6
- {threefive3-3.0.37 → threefive3-3.0.43}/LICENSE +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/setup.cfg +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/setup.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/__init__.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/aac.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/base.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/bitn.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/commands.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/descriptors.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/encode.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/gums.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/hlstags.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/iframes.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/new_reader.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/packetdata.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/section.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/segment.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/segmentation.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/streamtypes.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/stuff.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/upids.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3/words.py +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3.egg-info/SOURCES.txt +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3.egg-info/dependency_links.txt +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/threefive3.egg-info/requires.txt +0 -0
- {threefive3-3.0.37 → threefive3-3.0.43}/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.43
|
|
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
|
|
@@ -20,9 +20,11 @@ Description-Content-Type: text/markdown
|
|
|
20
20
|
License-File: LICENSE
|
|
21
21
|
|
|
22
22
|
[__Install__](#install) |[__SCTE-35 Cli__](#the-cli-tool) | [__SCTE-35 HLS__](https://github.com/superkabuki/threefive3/blob/main/hls.md) | [__Cue__ Class](https://github.com/superkabuki/threefive3/blob/main/cue.md) | [__Stream__ Class](https://github.com/superkabuki/threefive3/blob/main/stream.md) | [__Online SCTE-35 Parser__](https://iodisco.com/scte35) | [__Encode SCTE-35__](https://github.com/superkabuki/threefive3/blob/main/encode.md) | [__SCTE-35 Examples__](https://github.com/superkabuki/threefive3/tree/main/examples)
|
|
23
|
-
| [__SCTE-35 XML__](https://github.com/superkabuki/SCTE-35/blob/main/xml.md)
|
|
23
|
+
| [__SCTE-35 XML__](https://github.com/superkabuki/SCTE-35/blob/main/xml.md)
|
|
24
|
+
|
|
25
|
+
|
|
24
26
|
|
|
25
|
-
# threefive3 is
|
|
27
|
+
# threefive3 is ready.
|
|
26
28
|
✅ SCTE-35 __Parser__ ✅ SCTE-35 __Encoder__ ✅ SCTE-35 __HLS__ ✅ SCTE-35 __Xml+binary__ ✅ SCTE-35 __Cli__ ✅ SCTE-35 __library__
|
|
27
29
|
|
|
28
30
|
|
|
@@ -32,10 +34,47 @@ License-File: LICENSE
|
|
|
32
34
|
* Automatic AES decryption for HLS.
|
|
33
35
|
* All HLS __SCTE-35__ Tags are Supported.
|
|
34
36
|
|
|
35
|
-
#
|
|
37
|
+
# Heads up, I'm about to push v3.0.43
|
|
38
|
+
<pre>
|
|
39
|
+
Q.
|
|
40
|
+
Why the release?
|
|
41
|
+
|
|
42
|
+
A.
|
|
43
|
+
I made a mistake with the xml method in the Cue class. I intended it to return a node instance,
|
|
44
|
+
but instead I had it return just the xml output of a Node instance, not a big deal really,
|
|
45
|
+
but everything else returns a node instance from their xml() method, Cue should too..
|
|
46
|
+
I don't want people getting used to it not return a Node instance.
|
|
47
|
+
v3.0.43 fixes Cue.xml() to return a Node instance.
|
|
48
|
+
I also added more autodetection of SCTE-35 Formats to the Cue class,
|
|
49
|
+
no other SCTE-35 software can do even half of these.
|
|
50
|
+
Base64,
|
|
51
|
+
Bytes,
|
|
52
|
+
Dicts,
|
|
53
|
+
MPEGTS SCTE-35 packets,
|
|
54
|
+
Hex (literal and string),
|
|
55
|
+
Integers (literal, bytestring,and string),
|
|
56
|
+
JSON(strings and bytestrings),
|
|
57
|
+
XML(string and bytestring)
|
|
58
|
+
XML+Binary(string and bytestring)
|
|
59
|
+
|
|
60
|
+
I brought in the PMT module,that really cleans SixFix and SuperKabuki up a lot.
|
|
61
|
+
SuperKabuki is now a subclass of SixFix instead of the Stream class, that gets rid of a lot
|
|
62
|
+
of redundant code.
|
|
63
|
+
|
|
64
|
+
The Super Kabuki MPEGTS SCTE-35 Packet Injection Engine is working really really well.
|
|
65
|
+
I've tested the SuperKabuki output with ffmpeg and tsduck and everything works.
|
|
66
|
+
It's workinng perfectly for me, so I want to get it out there and see if y'all break it. :)
|
|
67
|
+
</pre>
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# Latest release is v3.0.43
|
|
36
71
|
_Released Thursday April 18th, 2025
|
|
72
|
+
* just 4300 lines of code.
|
|
73
|
+
* cyclomatic complexity __2.05__
|
|
37
74
|
> Stay up to date, only the latest release is supported.
|
|
38
75
|
|
|
76
|
+
|
|
77
|
+
|
|
39
78
|
## MPEGTS streams can be parsed for SCTE-35 with three lines of code.
|
|
40
79
|
|
|
41
80
|
```py3
|
|
@@ -49,16 +88,18 @@ a@fu:~/build5/scte35/scte35$ pypy3
|
|
|
49
88
|
# Checkout the Super Cool SCTE-35 [__Examples__](https://github.com/superkabuki/threefive3/tree/main/examples)
|
|
50
89
|
<br>
|
|
51
90
|
|
|
52
|
-
# threefive3 v3.0.
|
|
91
|
+
# threefive3 v3.0.39 is ready
|
|
53
92
|
|
|
54
93
|
* Xml is back and better than ever. __The new Ultra Xml Parser Supreme__ replaces the Super Xml Parser.
|
|
55
94
|
|
|
56
|
-
# [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md)
|
|
57
95
|
|
|
58
96
|
# `Documentation`
|
|
59
97
|
|
|
60
98
|
* [Install](#install)
|
|
61
99
|
|
|
100
|
+
* [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md) __New__!
|
|
101
|
+
|
|
102
|
+
|
|
62
103
|
### Cli
|
|
63
104
|
|
|
64
105
|
* [SCTE-35 Cli Super Tool](#the-cli-tool) Encodes, Decodes, and Recodes. This is pretty cool, it does SCTE-35 seven different ways.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
[__Install__](#install) |[__SCTE-35 Cli__](#the-cli-tool) | [__SCTE-35 HLS__](https://github.com/superkabuki/threefive3/blob/main/hls.md) | [__Cue__ Class](https://github.com/superkabuki/threefive3/blob/main/cue.md) | [__Stream__ Class](https://github.com/superkabuki/threefive3/blob/main/stream.md) | [__Online SCTE-35 Parser__](https://iodisco.com/scte35) | [__Encode SCTE-35__](https://github.com/superkabuki/threefive3/blob/main/encode.md) | [__SCTE-35 Examples__](https://github.com/superkabuki/threefive3/tree/main/examples)
|
|
2
|
-
| [__SCTE-35 XML__](https://github.com/superkabuki/SCTE-35/blob/main/xml.md)
|
|
2
|
+
| [__SCTE-35 XML__](https://github.com/superkabuki/SCTE-35/blob/main/xml.md)
|
|
3
|
+
|
|
4
|
+
|
|
3
5
|
|
|
4
|
-
# threefive3 is
|
|
6
|
+
# threefive3 is ready.
|
|
5
7
|
✅ SCTE-35 __Parser__ ✅ SCTE-35 __Encoder__ ✅ SCTE-35 __HLS__ ✅ SCTE-35 __Xml+binary__ ✅ SCTE-35 __Cli__ ✅ SCTE-35 __library__
|
|
6
8
|
|
|
7
9
|
|
|
@@ -11,10 +13,47 @@
|
|
|
11
13
|
* Automatic AES decryption for HLS.
|
|
12
14
|
* All HLS __SCTE-35__ Tags are Supported.
|
|
13
15
|
|
|
14
|
-
#
|
|
16
|
+
# Heads up, I'm about to push v3.0.43
|
|
17
|
+
<pre>
|
|
18
|
+
Q.
|
|
19
|
+
Why the release?
|
|
20
|
+
|
|
21
|
+
A.
|
|
22
|
+
I made a mistake with the xml method in the Cue class. I intended it to return a node instance,
|
|
23
|
+
but instead I had it return just the xml output of a Node instance, not a big deal really,
|
|
24
|
+
but everything else returns a node instance from their xml() method, Cue should too..
|
|
25
|
+
I don't want people getting used to it not return a Node instance.
|
|
26
|
+
v3.0.43 fixes Cue.xml() to return a Node instance.
|
|
27
|
+
I also added more autodetection of SCTE-35 Formats to the Cue class,
|
|
28
|
+
no other SCTE-35 software can do even half of these.
|
|
29
|
+
Base64,
|
|
30
|
+
Bytes,
|
|
31
|
+
Dicts,
|
|
32
|
+
MPEGTS SCTE-35 packets,
|
|
33
|
+
Hex (literal and string),
|
|
34
|
+
Integers (literal, bytestring,and string),
|
|
35
|
+
JSON(strings and bytestrings),
|
|
36
|
+
XML(string and bytestring)
|
|
37
|
+
XML+Binary(string and bytestring)
|
|
38
|
+
|
|
39
|
+
I brought in the PMT module,that really cleans SixFix and SuperKabuki up a lot.
|
|
40
|
+
SuperKabuki is now a subclass of SixFix instead of the Stream class, that gets rid of a lot
|
|
41
|
+
of redundant code.
|
|
42
|
+
|
|
43
|
+
The Super Kabuki MPEGTS SCTE-35 Packet Injection Engine is working really really well.
|
|
44
|
+
I've tested the SuperKabuki output with ffmpeg and tsduck and everything works.
|
|
45
|
+
It's workinng perfectly for me, so I want to get it out there and see if y'all break it. :)
|
|
46
|
+
</pre>
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Latest release is v3.0.43
|
|
15
50
|
_Released Thursday April 18th, 2025
|
|
51
|
+
* just 4300 lines of code.
|
|
52
|
+
* cyclomatic complexity __2.05__
|
|
16
53
|
> Stay up to date, only the latest release is supported.
|
|
17
54
|
|
|
55
|
+
|
|
56
|
+
|
|
18
57
|
## MPEGTS streams can be parsed for SCTE-35 with three lines of code.
|
|
19
58
|
|
|
20
59
|
```py3
|
|
@@ -28,16 +67,18 @@ a@fu:~/build5/scte35/scte35$ pypy3
|
|
|
28
67
|
# Checkout the Super Cool SCTE-35 [__Examples__](https://github.com/superkabuki/threefive3/tree/main/examples)
|
|
29
68
|
<br>
|
|
30
69
|
|
|
31
|
-
# threefive3 v3.0.
|
|
70
|
+
# threefive3 v3.0.39 is ready
|
|
32
71
|
|
|
33
72
|
* Xml is back and better than ever. __The new Ultra Xml Parser Supreme__ replaces the Super Xml Parser.
|
|
34
73
|
|
|
35
|
-
# [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md)
|
|
36
74
|
|
|
37
75
|
# `Documentation`
|
|
38
76
|
|
|
39
77
|
* [Install](#install)
|
|
40
78
|
|
|
79
|
+
* [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md) __New__!
|
|
80
|
+
|
|
81
|
+
|
|
41
82
|
### Cli
|
|
42
83
|
|
|
43
84
|
* [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():
|
|
@@ -2,24 +2,24 @@
|
|
|
2
2
|
crc.py crc32 function for encoding.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
from .words import zero, one, eight, twentyfour,
|
|
5
|
+
from .words import zero, one, eight, twentyfour, twofiftyfive, twofiftysix
|
|
6
6
|
|
|
7
|
+
BC_MASK = 0x80000000
|
|
7
8
|
POLY = 0x104C11DB7
|
|
8
9
|
INIT_VALUE = 0xFFFFFFFF
|
|
10
|
+
GONZO = INIT_VALUE - 0xFF
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
def _bytecrc(crc, poly):
|
|
12
|
-
mask = one << (thirtytwo - one)
|
|
13
14
|
i = eight
|
|
14
15
|
while i:
|
|
15
|
-
crc = (crc << one, crc << one ^ poly)[crc &
|
|
16
|
+
crc = (crc << one, crc << one ^ poly)[crc & BC_MASK != zero]
|
|
16
17
|
i -= one
|
|
17
18
|
return crc & INIT_VALUE
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
def _mk_table():
|
|
21
|
-
|
|
22
|
-
poly = POLY & mask
|
|
22
|
+
poly = POLY & INIT_VALUE
|
|
23
23
|
return [_bytecrc((i << twentyfour), poly) for i in range(twofiftysix)]
|
|
24
24
|
|
|
25
25
|
|
|
@@ -32,7 +32,7 @@ def crc32(data):
|
|
|
32
32
|
crc = INIT_VALUE
|
|
33
33
|
for bite in data:
|
|
34
34
|
crc = table[bite ^ ((crc >> twentyfour) & twofiftyfive)] ^ (
|
|
35
|
-
(crc << eight) & (
|
|
35
|
+
(crc << eight) & (GONZO)
|
|
36
36
|
)
|
|
37
37
|
return crc
|
|
38
38
|
|
|
@@ -76,7 +76,7 @@ class Cue(SCTE35Base):
|
|
|
76
76
|
"""
|
|
77
77
|
Cue.decode() parses for SCTE35 data
|
|
78
78
|
|
|
79
|
-
*
|
|
79
|
+
*decode doesn't need to be called directly
|
|
80
80
|
unless you initialize a Cue without data.
|
|
81
81
|
"""
|
|
82
82
|
bites = self.bites
|
|
@@ -457,7 +457,7 @@ class Cue(SCTE35Base):
|
|
|
457
457
|
cmd = self.command.xml(ns=ns)
|
|
458
458
|
sis.add_child(cmd)
|
|
459
459
|
sis = self._xml_mk_descriptor(sis, ns)
|
|
460
|
-
return sis
|
|
460
|
+
return sis # xml retuns a Node instance. now
|
|
461
461
|
|
|
462
462
|
def xmlbin(self, ns="scte35"):
|
|
463
463
|
"""
|
|
@@ -639,7 +639,7 @@ class HlsParser:
|
|
|
639
639
|
if pts and new_line:
|
|
640
640
|
if abs(pts - self.pts) > 5: # Handle Cues out of sync with video PTS
|
|
641
641
|
pts = self.pts
|
|
642
|
-
|
|
642
|
+
return self.set_cue_state(tags["#EXT-OATCLS-SCTE35"], new_line)
|
|
643
643
|
# return self.invalid(line)
|
|
644
644
|
return line
|
|
645
645
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
from .bitn import Bitn, NBin
|
|
2
2
|
from .crc import crc32
|
|
3
|
-
import pprint
|
|
4
|
-
from .stuff import blue
|
|
5
3
|
|
|
6
4
|
|
|
7
5
|
class Dscptr:
|
|
@@ -27,29 +25,38 @@ class Dscptr:
|
|
|
27
25
|
|
|
28
26
|
|
|
29
27
|
class PmtStream:
|
|
30
|
-
def __init__(self, bitn, conv_pids):
|
|
28
|
+
def __init__(self, bitn=None, conv_pids=None):
|
|
29
|
+
|
|
31
30
|
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
|
|
31
|
+
self.stream_type = None
|
|
32
|
+
self.elementary_PID = None
|
|
33
|
+
self.ES_info_length = 0
|
|
34
|
+
if bitn:
|
|
35
|
+
self.stream_type = bitn.as_int(8)
|
|
36
|
+
bitn.forward(3)
|
|
37
|
+
self.elementary_PID = bitn.as_int(13)
|
|
38
|
+
bitn.forward(4)
|
|
39
|
+
self.ES_info_length = bitn.as_int(12)
|
|
40
|
+
eil = self.ES_info_length << 3
|
|
41
|
+
while eil > 0:
|
|
42
|
+
dscptr = Dscptr(bitn)
|
|
43
|
+
eil -= dscptr.total_size << 3
|
|
44
|
+
self.descriptors.append(dscptr)
|
|
45
|
+
# if conv_pids:
|
|
46
|
+
# if self.elementary_PID in conv_pids:
|
|
47
|
+
# self.add_CUEI()
|
|
51
48
|
self.total_size = 5 + self.ES_info_length
|
|
52
49
|
|
|
50
|
+
def add_CUEI(self):
|
|
51
|
+
self.stream_type = 134
|
|
52
|
+
cuei = Dscptr()
|
|
53
|
+
cuei.type = 5
|
|
54
|
+
cuei.length = 4
|
|
55
|
+
cuei.value = b"CUEI"
|
|
56
|
+
cuei.total_size = 6
|
|
57
|
+
self.descriptors = [cuei] + self.descriptors
|
|
58
|
+
self.ES_info_length += cuei.total_size
|
|
59
|
+
|
|
53
60
|
def __repr__(self):
|
|
54
61
|
return str(vars(self))
|
|
55
62
|
|
|
@@ -65,7 +72,7 @@ class PmtStream:
|
|
|
65
72
|
|
|
66
73
|
class PMT:
|
|
67
74
|
|
|
68
|
-
def __init__(self, payload, conv_pids):
|
|
75
|
+
def __init__(self, payload, conv_pids=None):
|
|
69
76
|
self.conv_pids = conv_pids
|
|
70
77
|
bitn = Bitn(payload)
|
|
71
78
|
self.table_id = bitn.as_int(8)
|
|
@@ -109,21 +116,28 @@ class PMT:
|
|
|
109
116
|
while self.bitn.idx > 32:
|
|
110
117
|
pms = PmtStream(self.bitn, self.conv_pids)
|
|
111
118
|
streams.append(pms)
|
|
112
|
-
pprint.pprint(streams)
|
|
113
119
|
return streams
|
|
114
120
|
|
|
121
|
+
def add_SCTE35stream(self, pid):
|
|
122
|
+
pms = PmtStream()
|
|
123
|
+
pms.elementary_PID = pid
|
|
124
|
+
pms.stream_type = 0x86
|
|
125
|
+
# pms.add_CUEI()
|
|
126
|
+
pms.total_size = 5
|
|
127
|
+
self.streams.append(pms)
|
|
128
|
+
|
|
115
129
|
def mk(self):
|
|
116
130
|
vals = [dscptr.value for dscptr in self.descriptors]
|
|
117
131
|
if b"CUEI" not in vals:
|
|
118
|
-
blue("Adding SCTE-35 Descriptor")
|
|
132
|
+
# blue("Adding SCTE-35 Descriptor")
|
|
119
133
|
cuei = Dscptr()
|
|
120
134
|
cuei.type = 5
|
|
121
135
|
cuei.length = 4
|
|
122
136
|
cuei.value = b"CUEI"
|
|
123
137
|
cuei.total_size = 6
|
|
124
138
|
self.descriptors.append(cuei)
|
|
125
|
-
else:
|
|
126
|
-
|
|
139
|
+
# else:
|
|
140
|
+
# blue("SCTE-35 Descriptor already present.")
|
|
127
141
|
self.program_info_length = sum(
|
|
128
142
|
[dscptr.total_size for dscptr in self.descriptors]
|
|
129
143
|
)
|
|
@@ -132,8 +146,8 @@ class PMT:
|
|
|
132
146
|
nbin.add_int(self.table_id, 8) # 0x02
|
|
133
147
|
nbin.add_int(self.section_syntax_indicator, 1) # 9
|
|
134
148
|
nbin.add_int(self.zero, 1) # 10
|
|
135
|
-
nbin.
|
|
136
|
-
self.section_length =
|
|
149
|
+
nbin.add_int(3, 2) # 12
|
|
150
|
+
self.section_length = 13 + self.program_info_length + stream_len
|
|
137
151
|
nbin.add_int(self.section_length, 12) # 24
|
|
138
152
|
nbin.add_int(self.program_number, 16) # 40
|
|
139
153
|
nbin.reserve(2) # 42
|
|
@@ -151,10 +165,5 @@ class PMT:
|
|
|
151
165
|
stream.add(nbin)
|
|
152
166
|
self.crc32 = crc32(nbin.bites)
|
|
153
167
|
nbin.add_int(self.crc32, 32)
|
|
154
|
-
nbin.add_int(0, 8)
|
|
155
|
-
return nbin.bites
|
|
156
|
-
|
|
157
|
-
self.program_info_length = None
|
|
158
|
-
self.descriptors = []
|
|
159
|
-
self.streams = []
|
|
160
|
-
self.crc32 = None
|
|
168
|
+
# nbin.add_int(0, 8)
|
|
169
|
+
return b"\x00" + nbin.bites
|
|
@@ -4,10 +4,9 @@ sixfix.py
|
|
|
4
4
|
|
|
5
5
|
import io
|
|
6
6
|
import sys
|
|
7
|
+
from collections import deque
|
|
7
8
|
from functools import partial
|
|
8
|
-
from .
|
|
9
|
-
from .bitn import NBin
|
|
10
|
-
from .stuff import print2
|
|
9
|
+
from .stuff import print2, ERR
|
|
11
10
|
from .stream import Stream, ProgramInfo
|
|
12
11
|
from .pmt import PMT
|
|
13
12
|
|
|
@@ -48,11 +47,14 @@ class SixFix(Stream):
|
|
|
48
47
|
def __init__(self, tsdata=None):
|
|
49
48
|
super().__init__(tsdata)
|
|
50
49
|
self.pmt_payloads = {}
|
|
51
|
-
self.pmt_headers =
|
|
50
|
+
self.pmt_headers = deque() # popleft()
|
|
52
51
|
self.pmt_inputs = []
|
|
53
52
|
self.pid_prog = {}
|
|
54
53
|
self.con_pids = set()
|
|
55
|
-
|
|
54
|
+
try:
|
|
55
|
+
self.out_file = "sixfixed-" + tsdata.rsplit("/")[-1]
|
|
56
|
+
except ERR:
|
|
57
|
+
pass
|
|
56
58
|
self.in_file = sys.stdin.buffer
|
|
57
59
|
|
|
58
60
|
def iter_pkts(self, num_pkts=1):
|
|
@@ -62,12 +64,8 @@ class SixFix(Stream):
|
|
|
62
64
|
return iter(partial(self._tsdata.read, self.PACKET_SIZE * num_pkts), b"")
|
|
63
65
|
|
|
64
66
|
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
67
|
if pid in self.pids.pmt:
|
|
70
|
-
self.pmt_headers.
|
|
68
|
+
self.pmt_headers.append(pkt[:4])
|
|
71
69
|
self._parse_pmt(pkt[4:], pid)
|
|
72
70
|
prgm = self.pid2prgm(pid)
|
|
73
71
|
if prgm in self.pmt_payloads:
|
|
@@ -80,7 +78,7 @@ class SixFix(Stream):
|
|
|
80
78
|
def _parse_pkts(self, out_file):
|
|
81
79
|
active = io.BytesIO()
|
|
82
80
|
pkt_count = 0
|
|
83
|
-
chunk_size =
|
|
81
|
+
chunk_size = 2884
|
|
84
82
|
for pkt in self.iter_pkts():
|
|
85
83
|
pid = self._parse_pid(pkt[1], pkt[2])
|
|
86
84
|
pkt = self._parse_by_pid(pkt, pid)
|
|
@@ -97,15 +95,11 @@ class SixFix(Stream):
|
|
|
97
95
|
changes the stream type to 0x86 and replaces
|
|
98
96
|
the existing PMT as it writes packets to the outfile
|
|
99
97
|
"""
|
|
100
|
-
# if isinstance(self.out_file, str):
|
|
101
|
-
# self.out_file = open(self.out_file, "wb")
|
|
102
98
|
with open(self.out_file, "wb") as out_file:
|
|
103
99
|
self._parse_pkts(out_file)
|
|
104
100
|
|
|
105
101
|
def _chk_payload(self, pay, pid):
|
|
106
102
|
pay = self._chk_partial(pay, pid, self._PMT_TID)
|
|
107
|
-
## if not pay:
|
|
108
|
-
## return False
|
|
109
103
|
return pay
|
|
110
104
|
|
|
111
105
|
def _unpad_pmt(self, pay):
|
|
@@ -117,29 +111,24 @@ class SixFix(Stream):
|
|
|
117
111
|
"""
|
|
118
112
|
pmt2packets split the new pmt table into 188 byte packets
|
|
119
113
|
"""
|
|
120
|
-
|
|
114
|
+
pmt_parts = []
|
|
115
|
+
pmt = self.pmt_headers.popleft() + pmt.mk()
|
|
121
116
|
if len(pmt) < 188:
|
|
122
117
|
pad = (188 - len(pmt)) * b"\xff"
|
|
123
|
-
|
|
118
|
+
pmt_parts.append(pmt + pad)
|
|
124
119
|
else:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if len(three) < 188:
|
|
138
|
-
pad3 = (188 - len(three)) * b"\xff"
|
|
139
|
-
elif len(two) < 188:
|
|
140
|
-
pad2 = (188 - len(two)) * b"\xff"
|
|
141
|
-
|
|
142
|
-
self.pmt_payloads[program_number] = one + two + pad2 + three + pad3
|
|
120
|
+
pmt_parts.append(pmt[:188])
|
|
121
|
+
pmt = pmt[188:]
|
|
122
|
+
while pmt:
|
|
123
|
+
pmtpkt = self.pmt_headers.popleft() + pmt
|
|
124
|
+
if len(pmtpkt) < 188:
|
|
125
|
+
pad = 188 - len(pmtpkt) * b"\xff"
|
|
126
|
+
pmtpkt = pmtpkt + pad
|
|
127
|
+
else:
|
|
128
|
+
pmt = pmtpkt[188:]
|
|
129
|
+
pmtpkt = pmtpkt[:188]
|
|
130
|
+
pmt_parts.append(pmtpkt)
|
|
131
|
+
self.pmt_payloads[program_number] = b"".join(pmt_parts)
|
|
143
132
|
return True
|
|
144
133
|
|
|
145
134
|
def _pmt_precheck(self, pay, pid):
|
|
@@ -147,11 +136,15 @@ class SixFix(Stream):
|
|
|
147
136
|
pay = self._chk_payload(pay, pid)
|
|
148
137
|
if not pay:
|
|
149
138
|
return False
|
|
150
|
-
if pay in self.pmt_inputs:
|
|
151
|
-
return False
|
|
139
|
+
## if pay in self.pmt_inputs: <<---- this breaks continuity counters
|
|
140
|
+
## return False
|
|
152
141
|
self.pmt_inputs.append(pay)
|
|
153
142
|
return pay
|
|
154
143
|
|
|
144
|
+
def mk_pmt(self, pay):
|
|
145
|
+
pmt = PMT(pay, self.con_pids)
|
|
146
|
+
return pmt
|
|
147
|
+
|
|
155
148
|
def _parse_pmt(self, pay, pid):
|
|
156
149
|
"""
|
|
157
150
|
parse program maps for streams
|
|
@@ -159,9 +152,8 @@ class SixFix(Stream):
|
|
|
159
152
|
pay = self._pmt_precheck(pay, pid)
|
|
160
153
|
if not pay:
|
|
161
154
|
return False
|
|
162
|
-
pmt =
|
|
155
|
+
pmt = self.mk_pmt(pay)
|
|
163
156
|
seclen = self._parse_length(pay[1], pay[2])
|
|
164
|
-
n_seclen = seclen + 6
|
|
165
157
|
if self._section_incomplete(pay, pid, seclen):
|
|
166
158
|
return False
|
|
167
159
|
program_number = self._parse_program(pay[3], pay[4])
|
|
@@ -178,14 +170,10 @@ class SixFix(Stream):
|
|
|
178
170
|
self.maps.pid_prgm[pid] = program_number
|
|
179
171
|
proginfolen = self._parse_length(pay[10], pay[11])
|
|
180
172
|
idx = 12
|
|
181
|
-
n_proginfolen = proginfolen + len(self.CUEI_DESCRIPTOR)
|
|
182
173
|
end = idx + proginfolen
|
|
183
174
|
info_bites = pay[idx:end]
|
|
184
|
-
n_info_bites = self.CUEI_DESCRIPTOR + info_bites
|
|
185
175
|
idx = 12 + proginfolen
|
|
186
176
|
si_len = seclen - (9 + proginfolen) # ???
|
|
187
|
-
n_streams = self._parse_program_streams(si_len, pay, idx, program_number)
|
|
188
|
-
# self._regen_pmt(program_number,n_seclen, pcr_pid, n_proginfolen, n_info_bites, n_streams)
|
|
189
177
|
return self.pmt2packets(pmt, program_number)
|
|
190
178
|
|
|
191
179
|
def _parse_program_streams(self, si_len, pay, idx, program_number):
|
|
@@ -241,5 +229,10 @@ def sixfix(arg):
|
|
|
241
229
|
return
|
|
242
230
|
|
|
243
231
|
|
|
232
|
+
def cli():
|
|
233
|
+
args = sys.argv[1:]
|
|
234
|
+
_ = [sixfix(arg) for arg in args]
|
|
235
|
+
|
|
236
|
+
|
|
244
237
|
if __name__ == "__main__":
|
|
245
|
-
|
|
238
|
+
cli()
|
|
@@ -161,7 +161,7 @@ class Stream:
|
|
|
161
161
|
self.pids = Pids()
|
|
162
162
|
self.maps = Maps()
|
|
163
163
|
# self.iframer = IFramer(shush=True)
|
|
164
|
-
self.pmt_payloads =
|
|
164
|
+
self.pmt_payloads = {}
|
|
165
165
|
self.pmt_count = 0
|
|
166
166
|
|
|
167
167
|
def __repr__(self):
|
|
@@ -386,21 +386,6 @@ class Stream:
|
|
|
386
386
|
def _unpad(self, bites=b""):
|
|
387
387
|
return bites.strip(b"\xff")
|
|
388
388
|
|
|
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
|
-
|
|
404
389
|
def _mk_packet_data(self, pid):
|
|
405
390
|
prgm = self.maps.pid_prgm[pid]
|
|
406
391
|
pdata = PacketData(pid, prgm)
|
|
@@ -461,21 +446,12 @@ class Stream:
|
|
|
461
446
|
head_size += afl + 1 # +one for afl byte
|
|
462
447
|
return pkt[head_size:]
|
|
463
448
|
|
|
464
|
-
## def _pmt_pid(self, pay, pid):
|
|
465
|
-
## if pid in self.pids.pmt:
|
|
466
|
-
## self.pmt_count+=1
|
|
467
|
-
## if self.pmt_count > 10:
|
|
468
|
-
## if pay in self.pmt_payloads:
|
|
469
|
-
## return
|
|
470
|
-
## self.pmt_payloads.add(pay)
|
|
471
|
-
## self._parse_pmt(pay, pid)
|
|
472
|
-
|
|
473
449
|
def _pmt_pid(self, pay, pid):
|
|
474
450
|
self.pmt_count += 1
|
|
475
451
|
if pay in self.pmt_payloads:
|
|
476
452
|
if self.pmt_count > len(self.pmt_payloads) << 1:
|
|
477
453
|
return
|
|
478
|
-
self.pmt_payloads.
|
|
454
|
+
self.pmt_payloads[self.pid2prgm(pid)] = pay
|
|
479
455
|
self._parse_pmt(pay, pid)
|
|
480
456
|
|
|
481
457
|
def _pat_pid(self, pay, pid):
|
|
@@ -4,24 +4,24 @@ 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
|
|
10
11
|
from .new_reader import reader
|
|
11
12
|
from .iframes import IFramer
|
|
12
|
-
from .stream import Stream
|
|
13
13
|
from .cue import Cue
|
|
14
14
|
from .stuff import print2, ERR
|
|
15
|
-
from .crc import crc32
|
|
16
15
|
from .bitn import NBin
|
|
17
16
|
from .commands import TimeSignal
|
|
18
|
-
|
|
17
|
+
from .sixfix import SixFix
|
|
18
|
+
from .pmt import PMT
|
|
19
19
|
|
|
20
20
|
REV = "\033[7m"
|
|
21
21
|
NORM = "\033[27m"
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
class SuperKabuki(
|
|
24
|
+
class SuperKabuki(SixFix):
|
|
25
25
|
"""
|
|
26
26
|
Super Kabuki - SCTE-35 Packet injection
|
|
27
27
|
|
|
@@ -40,8 +40,6 @@ class SuperKabuki(Stream):
|
|
|
40
40
|
if isinstance(tsdata, str):
|
|
41
41
|
self.outfile = f'superkabuki-{tsdata.rsplit("/",1)[1]}'
|
|
42
42
|
super().__init__(tsdata)
|
|
43
|
-
self.pmt_payload = None
|
|
44
|
-
self.pmt_header = None
|
|
45
43
|
self.scte35_pid = None
|
|
46
44
|
self.scte35_cc = 0
|
|
47
45
|
self.iframer = IFramer(shush=True)
|
|
@@ -134,36 +132,6 @@ class SuperKabuki(Stream):
|
|
|
134
132
|
def _bump_cc(self):
|
|
135
133
|
self.scte35_cc = (self.scte35_cc + 1) % 16
|
|
136
134
|
|
|
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
135
|
def open_output(self):
|
|
168
136
|
"""
|
|
169
137
|
open_output open output file
|
|
@@ -172,18 +140,6 @@ class SuperKabuki(Stream):
|
|
|
172
140
|
if isinstance(self.outfile, str):
|
|
173
141
|
self.outfile = open(self.outfile, "wb")
|
|
174
142
|
|
|
175
|
-
def pad_pkt(self, pkt):
|
|
176
|
-
"""
|
|
177
|
-
pad_pkt add padding to packets
|
|
178
|
-
"""
|
|
179
|
-
pad = b"\xff"
|
|
180
|
-
self._parse_pmt_header(pkt)
|
|
181
|
-
if self.pmt_payload is not None:
|
|
182
|
-
pkt = self.pmt_header + self.pmt_payload
|
|
183
|
-
pad_size = 188 - len(pkt)
|
|
184
|
-
pkt = pkt + (pad * pad_size)
|
|
185
|
-
return pkt
|
|
186
|
-
|
|
187
143
|
def auto_time_signals(self, pts, outfile):
|
|
188
144
|
"""
|
|
189
145
|
auto_time_signals auto add
|
|
@@ -192,13 +148,13 @@ class SuperKabuki(Stream):
|
|
|
192
148
|
if self.time_signals:
|
|
193
149
|
outfile.write(self._gen_time_signal(pts))
|
|
194
150
|
|
|
195
|
-
def add_scte35_pkt(self, pts,
|
|
151
|
+
def add_scte35_pkt(self, pts, active):
|
|
196
152
|
"""
|
|
197
153
|
add_scte35_pkt
|
|
198
154
|
"""
|
|
199
155
|
scte35_pkt = self.chk_sidecar_cues(pts)
|
|
200
156
|
if scte35_pkt:
|
|
201
|
-
|
|
157
|
+
active.write(scte35_pkt)
|
|
202
158
|
|
|
203
159
|
def parse_pkt(self, pkt):
|
|
204
160
|
"""
|
|
@@ -207,10 +163,26 @@ class SuperKabuki(Stream):
|
|
|
207
163
|
pid = self._parse_info(pkt)
|
|
208
164
|
if self._pusi_flag(pkt):
|
|
209
165
|
self._parse_pts(pkt, pid)
|
|
210
|
-
if pid in self.pids.pmt:
|
|
211
|
-
pkt = self.pad_pkt(pkt)
|
|
212
166
|
return pkt
|
|
213
167
|
|
|
168
|
+
def iframe_action(self, pkt, active):
|
|
169
|
+
"""
|
|
170
|
+
iframe_action this is what we do when we find an iframe.
|
|
171
|
+
"""
|
|
172
|
+
pts = self.iframer.parse(pkt) # insert on iframe
|
|
173
|
+
if pts:
|
|
174
|
+
self.auto_time_signals(pts, active)
|
|
175
|
+
self.load_sidecar(pts)
|
|
176
|
+
self.add_scte35_pkt(pts, active)
|
|
177
|
+
|
|
178
|
+
def mk_pmt(self, pay):
|
|
179
|
+
"""
|
|
180
|
+
mk_pmt generate PMT with the new SCTE-35 stream.
|
|
181
|
+
"""
|
|
182
|
+
pmt = PMT(pay)
|
|
183
|
+
pmt.add_SCTE35stream(self.scte35_pid)
|
|
184
|
+
return pmt
|
|
185
|
+
|
|
214
186
|
def encode(self):
|
|
215
187
|
"""
|
|
216
188
|
encode parses the video input,
|
|
@@ -220,14 +192,20 @@ class SuperKabuki(Stream):
|
|
|
220
192
|
|
|
221
193
|
"""
|
|
222
194
|
self.open_output()
|
|
195
|
+
active = io.BytesIO()
|
|
196
|
+
pkt_count = 0
|
|
197
|
+
chunk_size = 131
|
|
223
198
|
with self.outfile as outfile:
|
|
224
199
|
for pkt in self.iter_pkts():
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
self.
|
|
229
|
-
|
|
230
|
-
|
|
200
|
+
pid = self._parse_pid(pkt[1], pkt[2])
|
|
201
|
+
pkt = self._parse_by_pid(pkt, pid)
|
|
202
|
+
if pkt:
|
|
203
|
+
self.iframe_action(pkt, active)
|
|
204
|
+
active.write(pkt)
|
|
205
|
+
pkt_count = (pkt_count + 1) % chunk_size
|
|
206
|
+
if not pkt_count:
|
|
207
|
+
outfile.write(active.getbuffer())
|
|
208
|
+
active = io.BytesIO()
|
|
231
209
|
|
|
232
210
|
def _gen_time_signal(self, pts):
|
|
233
211
|
cue = Cue()
|
|
@@ -315,99 +293,6 @@ class SuperKabuki(Stream):
|
|
|
315
293
|
self._bump_cc()
|
|
316
294
|
return nbin.bites
|
|
317
295
|
|
|
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
296
|
|
|
412
297
|
def cli():
|
|
413
298
|
"""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: threefive3
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.43
|
|
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
|
|
@@ -20,9 +20,11 @@ Description-Content-Type: text/markdown
|
|
|
20
20
|
License-File: LICENSE
|
|
21
21
|
|
|
22
22
|
[__Install__](#install) |[__SCTE-35 Cli__](#the-cli-tool) | [__SCTE-35 HLS__](https://github.com/superkabuki/threefive3/blob/main/hls.md) | [__Cue__ Class](https://github.com/superkabuki/threefive3/blob/main/cue.md) | [__Stream__ Class](https://github.com/superkabuki/threefive3/blob/main/stream.md) | [__Online SCTE-35 Parser__](https://iodisco.com/scte35) | [__Encode SCTE-35__](https://github.com/superkabuki/threefive3/blob/main/encode.md) | [__SCTE-35 Examples__](https://github.com/superkabuki/threefive3/tree/main/examples)
|
|
23
|
-
| [__SCTE-35 XML__](https://github.com/superkabuki/SCTE-35/blob/main/xml.md)
|
|
23
|
+
| [__SCTE-35 XML__](https://github.com/superkabuki/SCTE-35/blob/main/xml.md)
|
|
24
|
+
|
|
25
|
+
|
|
24
26
|
|
|
25
|
-
# threefive3 is
|
|
27
|
+
# threefive3 is ready.
|
|
26
28
|
✅ SCTE-35 __Parser__ ✅ SCTE-35 __Encoder__ ✅ SCTE-35 __HLS__ ✅ SCTE-35 __Xml+binary__ ✅ SCTE-35 __Cli__ ✅ SCTE-35 __library__
|
|
27
29
|
|
|
28
30
|
|
|
@@ -32,10 +34,47 @@ License-File: LICENSE
|
|
|
32
34
|
* Automatic AES decryption for HLS.
|
|
33
35
|
* All HLS __SCTE-35__ Tags are Supported.
|
|
34
36
|
|
|
35
|
-
#
|
|
37
|
+
# Heads up, I'm about to push v3.0.43
|
|
38
|
+
<pre>
|
|
39
|
+
Q.
|
|
40
|
+
Why the release?
|
|
41
|
+
|
|
42
|
+
A.
|
|
43
|
+
I made a mistake with the xml method in the Cue class. I intended it to return a node instance,
|
|
44
|
+
but instead I had it return just the xml output of a Node instance, not a big deal really,
|
|
45
|
+
but everything else returns a node instance from their xml() method, Cue should too..
|
|
46
|
+
I don't want people getting used to it not return a Node instance.
|
|
47
|
+
v3.0.43 fixes Cue.xml() to return a Node instance.
|
|
48
|
+
I also added more autodetection of SCTE-35 Formats to the Cue class,
|
|
49
|
+
no other SCTE-35 software can do even half of these.
|
|
50
|
+
Base64,
|
|
51
|
+
Bytes,
|
|
52
|
+
Dicts,
|
|
53
|
+
MPEGTS SCTE-35 packets,
|
|
54
|
+
Hex (literal and string),
|
|
55
|
+
Integers (literal, bytestring,and string),
|
|
56
|
+
JSON(strings and bytestrings),
|
|
57
|
+
XML(string and bytestring)
|
|
58
|
+
XML+Binary(string and bytestring)
|
|
59
|
+
|
|
60
|
+
I brought in the PMT module,that really cleans SixFix and SuperKabuki up a lot.
|
|
61
|
+
SuperKabuki is now a subclass of SixFix instead of the Stream class, that gets rid of a lot
|
|
62
|
+
of redundant code.
|
|
63
|
+
|
|
64
|
+
The Super Kabuki MPEGTS SCTE-35 Packet Injection Engine is working really really well.
|
|
65
|
+
I've tested the SuperKabuki output with ffmpeg and tsduck and everything works.
|
|
66
|
+
It's workinng perfectly for me, so I want to get it out there and see if y'all break it. :)
|
|
67
|
+
</pre>
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# Latest release is v3.0.43
|
|
36
71
|
_Released Thursday April 18th, 2025
|
|
72
|
+
* just 4300 lines of code.
|
|
73
|
+
* cyclomatic complexity __2.05__
|
|
37
74
|
> Stay up to date, only the latest release is supported.
|
|
38
75
|
|
|
76
|
+
|
|
77
|
+
|
|
39
78
|
## MPEGTS streams can be parsed for SCTE-35 with three lines of code.
|
|
40
79
|
|
|
41
80
|
```py3
|
|
@@ -49,16 +88,18 @@ a@fu:~/build5/scte35/scte35$ pypy3
|
|
|
49
88
|
# Checkout the Super Cool SCTE-35 [__Examples__](https://github.com/superkabuki/threefive3/tree/main/examples)
|
|
50
89
|
<br>
|
|
51
90
|
|
|
52
|
-
# threefive3 v3.0.
|
|
91
|
+
# threefive3 v3.0.39 is ready
|
|
53
92
|
|
|
54
93
|
* Xml is back and better than ever. __The new Ultra Xml Parser Supreme__ replaces the Super Xml Parser.
|
|
55
94
|
|
|
56
|
-
# [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md)
|
|
57
95
|
|
|
58
96
|
# `Documentation`
|
|
59
97
|
|
|
60
98
|
* [Install](#install)
|
|
61
99
|
|
|
100
|
+
* [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md) __New__!
|
|
101
|
+
|
|
102
|
+
|
|
62
103
|
### Cli
|
|
63
104
|
|
|
64
105
|
* [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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|