scte35part2 1.0.1__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.
- scte35part2-1.0.1/LICENSE +24 -0
- scte35part2-1.0.1/PKG-INFO +14 -0
- scte35part2-1.0.1/README.md +2 -0
- scte35part2-1.0.1/pyproject.toml +21 -0
- scte35part2-1.0.1/scte35part2/__init__.py +2 -0
- scte35part2-1.0.1/scte35part2/spsparser.py +157 -0
- scte35part2-1.0.1/scte35part2.egg-info/PKG-INFO +14 -0
- scte35part2-1.0.1/scte35part2.egg-info/SOURCES.txt +9 -0
- scte35part2-1.0.1/scte35part2.egg-info/dependency_links.txt +1 -0
- scte35part2-1.0.1/scte35part2.egg-info/top_level.txt +1 -0
- scte35part2-1.0.1/setup.cfg +4 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
BSD 2-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Adrian of Doom
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
16
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
17
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
19
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
20
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
21
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
22
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
23
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
24
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scte35part2
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: not yet.
|
|
5
|
+
Author-email: Adrian of Doom <spam@bigcorp.ltd>
|
|
6
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
7
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# scte35part2
|
|
14
|
+
Scte35 part 2
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
[project]
|
|
3
|
+
name = "scte35part2"
|
|
4
|
+
version = "1.0.1"
|
|
5
|
+
authors = [
|
|
6
|
+
{ name="Adrian of Doom", email="spam@bigcorp.ltd" },
|
|
7
|
+
]
|
|
8
|
+
description = "not yet."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
dependencies=[
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
17
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
18
|
+
]
|
|
19
|
+
license-files = ["LICEN[CS]E*"]
|
|
20
|
+
|
|
21
|
+
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from functools import partial
|
|
5
|
+
from threefive.bitn import Bitn
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Sps:
|
|
9
|
+
def __init_(self):
|
|
10
|
+
self.nal_ref_idc = None
|
|
11
|
+
self.nal_unit_type = None
|
|
12
|
+
self.profile = None
|
|
13
|
+
self.level = None
|
|
14
|
+
self.offset_for_ref_frame = []
|
|
15
|
+
self.seq_parameter_set_id = None
|
|
16
|
+
self.chroma_format_idc = None
|
|
17
|
+
self.separate_colour_plane_flag = None
|
|
18
|
+
self.bit_depth_luma_minus8 = None
|
|
19
|
+
self.bit_depth_chroma_minus8 = None
|
|
20
|
+
self.qpprime_y_zero_transform_bypass_flag = None
|
|
21
|
+
self.seq_scaling_matrix_present_flag = None
|
|
22
|
+
self.log2_max_frame_num_minus4 = None
|
|
23
|
+
self.pic_order_cnt_type = None
|
|
24
|
+
self.log2_max_pic_order_cnt_lsb_minus4 = None
|
|
25
|
+
self.delta_pic_order_always_zero_flag = None
|
|
26
|
+
self.offset_for_non_ref_pic = None # se
|
|
27
|
+
self.offset_for_top_to_bottom_filed = None # se
|
|
28
|
+
self.num_ref_frames_in_pic_order_cnt_cycle = None
|
|
29
|
+
self.num_ref_frames = None
|
|
30
|
+
self.gaps_in_frame_num_value_allowed_flag = None
|
|
31
|
+
self.pic_width_in_mbs_minus_1 = None
|
|
32
|
+
self.pic_height_in_map_units_minus_1 = None
|
|
33
|
+
self.frame_mbs_only_flag = None
|
|
34
|
+
self.mb_adaptive_frame_field_flag = None
|
|
35
|
+
self.direct_8x8_inference_flag = None
|
|
36
|
+
self.frame_cropping_flag = None
|
|
37
|
+
self.frame_crop_left_offset = 0
|
|
38
|
+
self.frame_crop_right_offset = 0
|
|
39
|
+
self.frame_crop_top_offset = 0
|
|
40
|
+
self.frame_crop_bottom_offset = 0
|
|
41
|
+
|
|
42
|
+
@staticmethod
|
|
43
|
+
def _read_ueg(bitn):
|
|
44
|
+
bitcount = 0
|
|
45
|
+
while True:
|
|
46
|
+
if not bitn.as_flag():
|
|
47
|
+
bitcount += 1
|
|
48
|
+
else:
|
|
49
|
+
val = bitn.as_int(bitcount)
|
|
50
|
+
result = (1 << bitcount) - 1 + val
|
|
51
|
+
return result
|
|
52
|
+
|
|
53
|
+
def _read_eg(self, bitn):
|
|
54
|
+
value = self._read_ueg(bitn)
|
|
55
|
+
if value & 0x01:
|
|
56
|
+
return (value + 1) / 2
|
|
57
|
+
else:
|
|
58
|
+
return -(value / 2)
|
|
59
|
+
|
|
60
|
+
@staticmethod
|
|
61
|
+
def _skip_scaling(bitn, count):
|
|
62
|
+
deltaScale = lastScale = nextScale = 8
|
|
63
|
+
for j in range(count):
|
|
64
|
+
if nextScale != 0:
|
|
65
|
+
deltaScale = self._read_eg(buffer)
|
|
66
|
+
nextScale = (lastScale + deltaScale + 256) % 256
|
|
67
|
+
if nextScale != 0:
|
|
68
|
+
lastScale = nextScale
|
|
69
|
+
|
|
70
|
+
def do(self, vid):
|
|
71
|
+
packet_size = 188
|
|
72
|
+
with open(vid, "rb") as video:
|
|
73
|
+
_ = [
|
|
74
|
+
self.is_sps(pkt) for pkt in iter(partial(video.read, packet_size), b"")
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
def _parse_chroma_stuff(self, bitn):
|
|
78
|
+
self.chroma_format_idc = self._read_ueg(bitn)
|
|
79
|
+
if self.chroma_format_idc == 3:
|
|
80
|
+
self.separate_colour_plane_flag = bitn.as_int(1)
|
|
81
|
+
self.bit_depth_luma_minus8 = self._read_ueg(bitn)
|
|
82
|
+
self.bit_depth_chroma_minus8 = self._read_ueg(bitn)
|
|
83
|
+
self.qpprime_y_zero_transform_bypass_flag = bitn.as_flag()
|
|
84
|
+
self.seq_scaling_matrix_present_flag = bitn.as_flag()
|
|
85
|
+
if self.seq_scaling_matrix_present_flag:
|
|
86
|
+
for i in range((8, 12)[self.chroma_format_idc != 3]):
|
|
87
|
+
if bitn.as_flag():
|
|
88
|
+
(self._skip_scaling(bitn, 64), self._skip_scaling(bitn, 16))[i < 6]
|
|
89
|
+
|
|
90
|
+
def _frame_cropping(self, bitn):
|
|
91
|
+
self.frame_cropping_flag = bitn.as_int(1)
|
|
92
|
+
if self.frame_cropping_flag:
|
|
93
|
+
self.frame_crop_left_offset = self._read_ueg(bitn)
|
|
94
|
+
self.frame_crop_right_offset = self._read_ueg(bitn)
|
|
95
|
+
self.frame_crop_top_offset = self._read_ueg(bitn)
|
|
96
|
+
self.frame_crop_bottom_offset = self._read_ueg(bitn)
|
|
97
|
+
|
|
98
|
+
def _pic_order_stuff(self, bitn):
|
|
99
|
+
self.pic_order_cnt_type = self._read_ueg(bitn)
|
|
100
|
+
if self.pic_order_cnt_type == 0:
|
|
101
|
+
self.log2_max_pic_order_cnt_lsb_minus4 = self._read_ueg(bitn)
|
|
102
|
+
elif self.pic_order_cnt_type == 1:
|
|
103
|
+
self.delta_pic_order_always_zero_flag = bitn.as_flag()
|
|
104
|
+
self.offset_for_non_ref_pic = frame_crop_left_offset # se
|
|
105
|
+
self.offset_for_top_to_bottom_filed = self._read_eg(bitn) # se
|
|
106
|
+
self.num_ref_frames_in_pic_order_cnt_cycle = self._read_ueg(bitn)
|
|
107
|
+
for i in range(self.num_ref_frames_in_pic_order_cnt_cycle):
|
|
108
|
+
self.offset_for_ref_frame.append(self._read_eg(bitn)) # se
|
|
109
|
+
self.self._read_ueg(bitn)
|
|
110
|
+
|
|
111
|
+
def is_sps(self, pkt):
|
|
112
|
+
"""
|
|
113
|
+
is_sps parses h264 nal for profile and level and height and width
|
|
114
|
+
"""
|
|
115
|
+
sps_start = b"\x00\x00\x01g"
|
|
116
|
+
if sps_start not in pkt:
|
|
117
|
+
sps_start = b"\x00\x00\x01'"
|
|
118
|
+
if sps_start not in pkt:
|
|
119
|
+
sps_start = b"\x00\x00\x01\x47'"
|
|
120
|
+
if sps_start in pkt:
|
|
121
|
+
sps_idx = pkt.index(sps_start) + len(sps_start)
|
|
122
|
+
self.nal_ref_idc = pkt[sps_idx - 1] >> 5 & 3
|
|
123
|
+
self.nal_unit_type = pkt[sps_idx - 1] & 31
|
|
124
|
+
if self.nal_unit_type != 7:
|
|
125
|
+
return
|
|
126
|
+
bitn = Bitn(pkt[sps_idx:])
|
|
127
|
+
self.profile = bitn.as_int(8)
|
|
128
|
+
bitn.forward(8)
|
|
129
|
+
self.level = bitn.as_int(8)
|
|
130
|
+
self.seq_parameter_set_id = self._read_ueg(bitn)
|
|
131
|
+
if self.profile in [100, 110, 122, 244, 44, 83, 86, 118, 128]:
|
|
132
|
+
self._parse_chroma_stuff(bitn)
|
|
133
|
+
self.log2_max_frame_num_minus4 = self._read_ueg(bitn)
|
|
134
|
+
self._pic_order_stuff(bitn)
|
|
135
|
+
self.num_ref_frames = self._read_ueg(bitn)
|
|
136
|
+
self.gaps_in_frame_num_value_allowed_flag = bitn.as_flag()
|
|
137
|
+
self.pic_width_in_mbs_minus_1 = self._read_ueg(bitn)
|
|
138
|
+
self.pic_height_in_map_units_minus_1 = self._read_ueg(bitn)
|
|
139
|
+
self.frame_mbs_only_flag = bitn.as_int(1)
|
|
140
|
+
if self.frame_mbs_only_flag:
|
|
141
|
+
self.mb_adaptive_frame_field_flag = bitn.as_int(1)
|
|
142
|
+
self.direct_8x8_inference_flag = bitn.as_int(1)
|
|
143
|
+
self._frame_cropping(bitn)
|
|
144
|
+
self.width = (self.pic_width_in_mbs_minus_1 + 1) * 16
|
|
145
|
+
self.height = (
|
|
146
|
+
(2 - self.frame_mbs_only_flag)
|
|
147
|
+
* (self.pic_height_in_map_units_minus_1 + 1)
|
|
148
|
+
* 16
|
|
149
|
+
)
|
|
150
|
+
for k, v in vars(self).items():
|
|
151
|
+
print(f"{k}: {v}")
|
|
152
|
+
sys.exit()
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
if __name__=="__main__":
|
|
156
|
+
sps = Sps()
|
|
157
|
+
sps.do(sys.argv[1])
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scte35part2
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: not yet.
|
|
5
|
+
Author-email: Adrian of Doom <spam@bigcorp.ltd>
|
|
6
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
7
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# scte35part2
|
|
14
|
+
Scte35 part 2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
scte35part2
|