bdmvkit 0.6.0__tar.gz → 0.7.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.
- {bdmvkit-0.6.0/bdmvkit.egg-info → bdmvkit-0.7.1}/PKG-INFO +24 -4
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/README.md +23 -3
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/__init__.py +1 -1
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/__main__.py +7 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/clip.py +1 -1
- bdmvkit-0.7.1/bdmvkit/contract.py +44 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/disc.py +12 -8
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/formats.py +27 -1
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/igs.py +2 -22
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/m2ts.py +49 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/nav.py +30 -5
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/playlist.py +5 -4
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/program.py +10 -1
- {bdmvkit-0.6.0 → bdmvkit-0.7.1/bdmvkit.egg-info}/PKG-INFO +24 -4
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit.egg-info/SOURCES.txt +4 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/pyproject.toml +1 -1
- bdmvkit-0.7.1/tests/test_contract.py +32 -0
- bdmvkit-0.7.1/tests/test_contract_file.py +18 -0
- bdmvkit-0.7.1/tests/test_dts.py +130 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/COPYING +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/COPYING.LESSER +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/encode.py +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/errors.py +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/hdmv.py +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/pgs.py +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit/uops.py +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit.egg-info/dependency_links.txt +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit.egg-info/entry_points.txt +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/bdmvkit.egg-info/top_level.txt +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/setup.cfg +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/tests/test_disc.py +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/tests/test_files.py +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/tests/test_menus.py +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/tests/test_motion.py +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/tests/test_nav.py +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/tests/test_pgs.py +0 -0
- {bdmvkit-0.6.0 → bdmvkit-0.7.1}/tests/test_popup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bdmvkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.1
|
|
4
4
|
Summary: Blu-ray (BDMV) authoring in pure Python: playlists, clip information, HDMV navigation, PGS subtitles
|
|
5
5
|
Author: kajisho5
|
|
6
6
|
License-Expression: LGPL-3.0-or-later
|
|
@@ -35,14 +35,15 @@ only to encode.
|
|
|
35
35
|
|
|
36
36
|
日本語の説明は [README.ja.md](README.ja.md) にあります。
|
|
37
37
|
|
|
38
|
-
**Status: 0.
|
|
38
|
+
**Status: 0.7.** Titles with chapters, sound and subtitle tracks;
|
|
39
39
|
playlists (in order, at random or shuffled) and play all; menus whose
|
|
40
40
|
buttons start titles, chapters, playlists and other menus, switch sound and
|
|
41
41
|
subtitle tracks, or open a menu on a chosen button; loop counts, end-action
|
|
42
42
|
overrides, link transitions, remote keys a title turns off, and 720p. This
|
|
43
43
|
navigation is the one [oncemore](https://github.com/kajisho5/oncemore)
|
|
44
44
|
writes, byte for byte. 0.4 adds pop-up menus over a playing title, 0.5
|
|
45
|
-
menus with motion or music, 0.6 button streams for 720p menus.
|
|
45
|
+
menus with motion or music, 0.6 button streams for 720p menus, 0.7 DTS-HD
|
|
46
|
+
sound tracks.
|
|
46
47
|
|
|
47
48
|
## Why
|
|
48
49
|
|
|
@@ -95,6 +96,18 @@ disc.add_title("feature.m2ts", audio=[("ac3", 2, "en"), ("lpcm", 2, "en"), ("ac3
|
|
|
95
96
|
|
|
96
97
|
`Disc.write` checks that every track a title declares is in its clip.
|
|
97
98
|
|
|
99
|
+
DTS copied with its extensions is declared as what it is: `"dtshd"` (DTS-HD
|
|
100
|
+
High Resolution Audio) or `"dtshd_ma"` (DTS-HD Master Audio), with its
|
|
101
|
+
sampling rate when it is above 48 kHz (`("dtshd_ma", 8, "en", 96000)`;
|
|
102
|
+
LPCM may run at 96 or 192 kHz too). ffmpeg marks a DTS stream in the clip by
|
|
103
|
+
its channels, not by its extensions, so `Disc.write` marks each DTS track
|
|
104
|
+
with the type the title declares, in the copy it puts on the disc:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
encode_clip("feature.mkv", "feature.m2ts", audio=[AudioTrack("feature.mkv", "copy", 8)])
|
|
108
|
+
disc.add_title("feature.m2ts", audio=[("dtshd_ma", 8, "en")])
|
|
109
|
+
```
|
|
110
|
+
|
|
98
111
|
A menu is a picture and its buttons. Each button is a picture of how it
|
|
99
112
|
looks when selected (and, if given, when activated and before it is
|
|
100
113
|
selected), placed on the 1920 x 1080 menu, and a link:
|
|
@@ -163,8 +176,14 @@ menu's buttons run, for tools that make their own IG streams.
|
|
|
163
176
|
```sh
|
|
164
177
|
bdmvkit encode feature.mov feature.m2ts --chapters 0,300,600
|
|
165
178
|
bdmvkit build disc.json out
|
|
179
|
+
bdmvkit contract --json # machine-readable contract (AI Video Production OS registry)
|
|
166
180
|
```
|
|
167
181
|
|
|
182
|
+
`contract/contract.json` is that contract committed as a file (the `contract --json` output,
|
|
183
|
+
unchanged), so any release's contract is `git show vX.Y.Z:contract/contract.json`, with nothing
|
|
184
|
+
installed or run. Regenerate it with `python contract/generate.py` after a contract change or a
|
|
185
|
+
version bump; a unit test fails when it is stale.
|
|
186
|
+
|
|
168
187
|
`disc.json` looks like this:
|
|
169
188
|
|
|
170
189
|
```json
|
|
@@ -182,7 +201,8 @@ How the disc is laid out:
|
|
|
182
201
|
progressive frames in a 1080i stream, as the format asks. A program can
|
|
183
202
|
also be 720p (23.976, 50, 59.94; 25 and 29.97 go on at twice their rate);
|
|
184
203
|
`encode_clip` makes 1080 clips.
|
|
185
|
-
* Sound is AC-3, LPCM or DTS
|
|
204
|
+
* Sound is AC-3, LPCM, DTS, DTS-HD High Resolution Audio or DTS-HD Master
|
|
205
|
+
Audio (a DTS-HD track above 48 kHz is marked as such over its 48 kHz core).
|
|
186
206
|
* Subtitles are PGS streams muxed into the clip. `pgs.write_sup` makes them
|
|
187
207
|
from pictures, and `encode_clip(..., sups=[...])` muxes them in.
|
|
188
208
|
* First play and the Top Menu key open the first menu, or start title 1
|
|
@@ -18,14 +18,15 @@ only to encode.
|
|
|
18
18
|
|
|
19
19
|
日本語の説明は [README.ja.md](README.ja.md) にあります。
|
|
20
20
|
|
|
21
|
-
**Status: 0.
|
|
21
|
+
**Status: 0.7.** Titles with chapters, sound and subtitle tracks;
|
|
22
22
|
playlists (in order, at random or shuffled) and play all; menus whose
|
|
23
23
|
buttons start titles, chapters, playlists and other menus, switch sound and
|
|
24
24
|
subtitle tracks, or open a menu on a chosen button; loop counts, end-action
|
|
25
25
|
overrides, link transitions, remote keys a title turns off, and 720p. This
|
|
26
26
|
navigation is the one [oncemore](https://github.com/kajisho5/oncemore)
|
|
27
27
|
writes, byte for byte. 0.4 adds pop-up menus over a playing title, 0.5
|
|
28
|
-
menus with motion or music, 0.6 button streams for 720p menus.
|
|
28
|
+
menus with motion or music, 0.6 button streams for 720p menus, 0.7 DTS-HD
|
|
29
|
+
sound tracks.
|
|
29
30
|
|
|
30
31
|
## Why
|
|
31
32
|
|
|
@@ -78,6 +79,18 @@ disc.add_title("feature.m2ts", audio=[("ac3", 2, "en"), ("lpcm", 2, "en"), ("ac3
|
|
|
78
79
|
|
|
79
80
|
`Disc.write` checks that every track a title declares is in its clip.
|
|
80
81
|
|
|
82
|
+
DTS copied with its extensions is declared as what it is: `"dtshd"` (DTS-HD
|
|
83
|
+
High Resolution Audio) or `"dtshd_ma"` (DTS-HD Master Audio), with its
|
|
84
|
+
sampling rate when it is above 48 kHz (`("dtshd_ma", 8, "en", 96000)`;
|
|
85
|
+
LPCM may run at 96 or 192 kHz too). ffmpeg marks a DTS stream in the clip by
|
|
86
|
+
its channels, not by its extensions, so `Disc.write` marks each DTS track
|
|
87
|
+
with the type the title declares, in the copy it puts on the disc:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
encode_clip("feature.mkv", "feature.m2ts", audio=[AudioTrack("feature.mkv", "copy", 8)])
|
|
91
|
+
disc.add_title("feature.m2ts", audio=[("dtshd_ma", 8, "en")])
|
|
92
|
+
```
|
|
93
|
+
|
|
81
94
|
A menu is a picture and its buttons. Each button is a picture of how it
|
|
82
95
|
looks when selected (and, if given, when activated and before it is
|
|
83
96
|
selected), placed on the 1920 x 1080 menu, and a link:
|
|
@@ -146,8 +159,14 @@ menu's buttons run, for tools that make their own IG streams.
|
|
|
146
159
|
```sh
|
|
147
160
|
bdmvkit encode feature.mov feature.m2ts --chapters 0,300,600
|
|
148
161
|
bdmvkit build disc.json out
|
|
162
|
+
bdmvkit contract --json # machine-readable contract (AI Video Production OS registry)
|
|
149
163
|
```
|
|
150
164
|
|
|
165
|
+
`contract/contract.json` is that contract committed as a file (the `contract --json` output,
|
|
166
|
+
unchanged), so any release's contract is `git show vX.Y.Z:contract/contract.json`, with nothing
|
|
167
|
+
installed or run. Regenerate it with `python contract/generate.py` after a contract change or a
|
|
168
|
+
version bump; a unit test fails when it is stale.
|
|
169
|
+
|
|
151
170
|
`disc.json` looks like this:
|
|
152
171
|
|
|
153
172
|
```json
|
|
@@ -165,7 +184,8 @@ How the disc is laid out:
|
|
|
165
184
|
progressive frames in a 1080i stream, as the format asks. A program can
|
|
166
185
|
also be 720p (23.976, 50, 59.94; 25 and 29.97 go on at twice their rate);
|
|
167
186
|
`encode_clip` makes 1080 clips.
|
|
168
|
-
* Sound is AC-3, LPCM or DTS
|
|
187
|
+
* Sound is AC-3, LPCM, DTS, DTS-HD High Resolution Audio or DTS-HD Master
|
|
188
|
+
Audio (a DTS-HD track above 48 kHz is marked as such over its 48 kHz core).
|
|
169
189
|
* Subtitles are PGS streams muxed into the clip. `pgs.write_sup` makes them
|
|
170
190
|
from pictures, and `encode_clip(..., sups=[...])` muxes them in.
|
|
171
191
|
* First play and the Top Menu key open the first menu, or start title 1
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
bdmvkit encode SOURCE CLIP.m2ts [--fps 24000/1001] [--chapters 0,60,120] [--fast]
|
|
4
4
|
bdmvkit build DISC.json OUT_DIR
|
|
5
|
+
bdmvkit contract [--json]
|
|
5
6
|
|
|
6
7
|
DISC.json: {"titles": [{"clip": "a.m2ts", "fps": "24000/1001",
|
|
7
8
|
"chapters": [0, 60], "audio": [["ac3", 2, "en"]], "subtitles": ["ja"],
|
|
@@ -24,6 +25,7 @@ import os
|
|
|
24
25
|
import sys
|
|
25
26
|
|
|
26
27
|
from . import __version__
|
|
28
|
+
from .contract import contract
|
|
27
29
|
from .disc import Disc, MenuButton
|
|
28
30
|
from .encode import encode_clip
|
|
29
31
|
from .errors import BdmvError
|
|
@@ -52,7 +54,12 @@ def main(argv=None):
|
|
|
52
54
|
s.add_argument("disc", help="the disc description (JSON)")
|
|
53
55
|
s.add_argument("out", help="the folder to write BDMV into")
|
|
54
56
|
s.add_argument("--fast", action="store_true", help="quick encoding of the menus")
|
|
57
|
+
s = sub.add_parser("contract", help="print the machine-readable contract (JSON)")
|
|
58
|
+
s.add_argument("--json", action="store_true", help="accepted; the output is always JSON")
|
|
55
59
|
args = p.parse_args(argv)
|
|
60
|
+
if args.command == "contract":
|
|
61
|
+
print(json.dumps(contract(), indent=2))
|
|
62
|
+
return 0
|
|
56
63
|
try:
|
|
57
64
|
if args.command == "encode":
|
|
58
65
|
encode_clip(args.source, args.clip, fps=_fps(args.fps),
|
|
@@ -32,7 +32,7 @@ def ep_map(entries):
|
|
|
32
32
|
|
|
33
33
|
def clpi(scan, video_format, frame_rate, audio, pg=(), ig=False):
|
|
34
34
|
"""Clip information of one .m2ts: its streams, time span and EP map.
|
|
35
|
-
audio: [(coding, channels, lang3)]; pg: [lang3]; ig: menu buttons."""
|
|
35
|
+
audio: [(coding, channels, lang3[, rate])]; pg: [lang3]; ig: menu buttons."""
|
|
36
36
|
ts_type = bytes([0x80]) + b"HDMV" + bytes(9) + bytes(16)
|
|
37
37
|
info = _u16(0) + _u8(1) + _u8(1) + _u32(0) + _u32(TS_RATE) + _u32(scan.packets) + \
|
|
38
38
|
bytes(128) + _u16(len(ts_type)) + ts_type
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Machine-readable contract (`bdmvkit contract --json`), in the shape the AI Video
|
|
2
|
+
Production OS registry reads (skill_id, version, contract_version, provides,
|
|
3
|
+
dependencies, not_provided)."""
|
|
4
|
+
|
|
5
|
+
from . import __version__
|
|
6
|
+
|
|
7
|
+
SKILL_ID = "bdmvkit"
|
|
8
|
+
CONTRACT_VERSION = "1.0"
|
|
9
|
+
|
|
10
|
+
TOOLS = [
|
|
11
|
+
{"tool_id": "bdmvkit/encode", "kind": "cli", "writes_media": True, "mutates_input": False,
|
|
12
|
+
"description": "Encode a video into a Blu-ray clip (.m2ts) with ffmpeg + x264",
|
|
13
|
+
"argv": ["encode", "<source>", "<clip.m2ts>", "[--fps 24000/1001|25|30000/1001]", "[--chapters 0,60,120]", "[--fast]"]},
|
|
14
|
+
{"tool_id": "bdmvkit/build", "kind": "cli", "writes_media": True, "mutates_input": False,
|
|
15
|
+
"description": "Write a BDMV folder (playlists, clip information, HDMV navigation, menus, PGS subtitles) from encoded clips and a disc description",
|
|
16
|
+
"argv": ["build", "<disc.json>", "<out_dir>", "[--fast]"]},
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def contract():
|
|
21
|
+
return {
|
|
22
|
+
"skill_id": SKILL_ID,
|
|
23
|
+
"id": SKILL_ID,
|
|
24
|
+
"version": __version__,
|
|
25
|
+
"contract_version": CONTRACT_VERSION,
|
|
26
|
+
"provides": [
|
|
27
|
+
{"id": "bluray.encode_clip", "lifecycle": "EXPERIMENTAL", "tool_id": "bdmvkit/encode"},
|
|
28
|
+
{"id": "bluray.author", "lifecycle": "EXPERIMENTAL", "tool_id": "bdmvkit/build"},
|
|
29
|
+
],
|
|
30
|
+
# No Skill dependencies (ffmpeg-skill is not used).
|
|
31
|
+
"dependencies": [],
|
|
32
|
+
"external_tools": [{"id": "ffmpeg", "required": True, "detail": "with libx264; encodes clips and menus"}],
|
|
33
|
+
"not_provided": [
|
|
34
|
+
"disc images (udfkit)",
|
|
35
|
+
"burning a disc",
|
|
36
|
+
"DVD-Video (vtskit, oncemore)",
|
|
37
|
+
"copy protection of any kind",
|
|
38
|
+
"network access of any kind",
|
|
39
|
+
],
|
|
40
|
+
"tools": TOOLS,
|
|
41
|
+
"python_api": "bdmvkit.Disc",
|
|
42
|
+
"execution": {"canonical_invocation": ["bdmvkit", "contract", "--json"],
|
|
43
|
+
"network": False, "shell": False},
|
|
44
|
+
}
|
|
@@ -36,7 +36,7 @@ import tempfile
|
|
|
36
36
|
|
|
37
37
|
from . import encode, hdmv, igs, program
|
|
38
38
|
from .errors import BdmvError
|
|
39
|
-
from .formats import AUDIO_PID, CODECS, FORMATS, HEIGHT, PG_PID, WIDTH, lang3
|
|
39
|
+
from .formats import AUDIO_PID, CODECS, FORMATS, HEIGHT, PG_PID, WIDTH, lang3, rate_code
|
|
40
40
|
from .m2ts import stream_pids
|
|
41
41
|
from .program import parse_action
|
|
42
42
|
from .nav import DIRS, Navigation, _write, chapter_marks, write_program # noqa: F401
|
|
@@ -114,17 +114,21 @@ class Disc:
|
|
|
114
114
|
subtitles=(), end=None, default_audio=None, default_subtitle=None,
|
|
115
115
|
prohibit=()):
|
|
116
116
|
"""Add a title; returns its number (1-based), its id in actions
|
|
117
|
-
("title:2"). audio: (codec, channels, language) per track,
|
|
118
|
-
"ac3", "lpcm"
|
|
119
|
-
|
|
117
|
+
("title:2"). audio: (codec, channels, language[, rate]) per track,
|
|
118
|
+
codec "ac3", "lpcm", "dts", "dtshd" (DTS-HD High Resolution) or
|
|
119
|
+
"dtshd_ma" (DTS-HD Master Audio); languages are ISO 639-1 ("en") or
|
|
120
|
+
639-2 ("eng") codes; rate 48000 (the default), or 96000 or 192000
|
|
121
|
+
for LPCM and DTS-HD. end: the action when it ends (default: the next title
|
|
120
122
|
with play_all). default_audio: the sound track the disc starts with;
|
|
121
123
|
default_subtitle: the subtitle track shown from its start (else
|
|
122
124
|
none); prohibit: remote keys it does not allow (uops.KEYS)."""
|
|
123
125
|
if tuple(fps) not in FORMATS:
|
|
124
126
|
raise BdmvError(f"{fps[0]}/{fps[1]} fps has no Blu-ray format")
|
|
125
|
-
for codec, _, _ in audio:
|
|
127
|
+
for codec, _, _, *rate in audio:
|
|
126
128
|
if codec not in CODECS:
|
|
127
|
-
raise BdmvError(f"unknown audio codec {codec!r}
|
|
129
|
+
raise BdmvError(f"unknown audio codec {codec!r} "
|
|
130
|
+
f"({', '.join(CODECS)})")
|
|
131
|
+
rate_code(CODECS[codec], *rate)
|
|
128
132
|
if not audio:
|
|
129
133
|
raise BdmvError("a title needs at least one audio track")
|
|
130
134
|
for name, k, n in (("default_audio", default_audio, len(audio)),
|
|
@@ -194,8 +198,8 @@ class Disc:
|
|
|
194
198
|
end = t.end or (f"title:{n + 1}" if play_all and n < n_titles else None)
|
|
195
199
|
titles.append(program.Title(
|
|
196
200
|
str(n), t.clip, t.fps, list(t.chapters),
|
|
197
|
-
[program.Audio(CODECS[c], ch, _lang(lang), k == t.default_audio)
|
|
198
|
-
for k, (c, ch, lang) in enumerate(t.audio, 1)],
|
|
201
|
+
[program.Audio(CODECS[c], ch, _lang(lang), k == t.default_audio, *rate)
|
|
202
|
+
for k, (c, ch, lang, *rate) in enumerate(t.audio, 1)],
|
|
199
203
|
[program.Subtitle(_lang(lang), k == t.default_subtitle)
|
|
200
204
|
for k, lang in enumerate(t.subtitles, 1)], end, list(t.prohibit),
|
|
201
205
|
popup=n in self.popups,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"""Numbers of the BD-ROM format bdmvkit writes: stream PIDs, coding types,
|
|
2
2
|
video format and frame rate codes, languages."""
|
|
3
3
|
|
|
4
|
+
from .errors import BdmvError
|
|
5
|
+
|
|
4
6
|
VERSION = b"0200" # of the navigation files
|
|
5
7
|
WIDTH, HEIGHT = 1920, 1080
|
|
6
8
|
|
|
@@ -49,7 +51,16 @@ def video_codes(fps, video="1080"):
|
|
|
49
51
|
|
|
50
52
|
|
|
51
53
|
CODING_H264, CODING_LPCM, CODING_AC3, CODING_DTS = 0x1B, 0x80, 0x81, 0x82
|
|
54
|
+
# DTS-HD High Resolution Audio and DTS-HD Master Audio: a DTS core with its
|
|
55
|
+
# extensions (the stream types of libbluray's bluray.h)
|
|
56
|
+
CODING_DTSHD, CODING_DTSHD_MA = 0x85, 0x86
|
|
52
57
|
CODING_PG, CODING_IG = 0x90, 0x91
|
|
58
|
+
DTS_CODINGS = (CODING_DTS, CODING_DTSHD, CODING_DTSHD_MA)
|
|
59
|
+
|
|
60
|
+
# sampling_frequency of a sound track (bluray.h): 48, 96 and 192 kHz, and
|
|
61
|
+
# 96 or 192 kHz over a 48 kHz core (a DTS core runs at 48 kHz at most)
|
|
62
|
+
RATE_CODES = {48000: 1, 96000: 4, 192000: 5}
|
|
63
|
+
CORE_RATE_CODES = {96000: 14, 192000: 12}
|
|
53
64
|
|
|
54
65
|
# ISO 639-1 -> ISO 639-2/B (the disc's codes)
|
|
55
66
|
LANGS = {
|
|
@@ -67,4 +78,19 @@ def lang3(code):
|
|
|
67
78
|
return LANGS.get((code or "").lower(), "und")
|
|
68
79
|
|
|
69
80
|
|
|
70
|
-
CODECS = {"ac3": CODING_AC3, "lpcm": CODING_LPCM, "dts": CODING_DTS
|
|
81
|
+
CODECS = {"ac3": CODING_AC3, "lpcm": CODING_LPCM, "dts": CODING_DTS, "dtshd": CODING_DTSHD,
|
|
82
|
+
"dtshd_ma": CODING_DTSHD_MA}
|
|
83
|
+
# the codings a track may have above 48 kHz
|
|
84
|
+
HIGH_RATE_CODINGS = (CODING_LPCM, CODING_DTSHD, CODING_DTSHD_MA)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def rate_code(coding, rate=48000):
|
|
88
|
+
"""A sound track's sampling_frequency code; a DTS-HD track above 48 kHz
|
|
89
|
+
has its 48 kHz core's code."""
|
|
90
|
+
if rate != 48000 and coding not in HIGH_RATE_CODINGS:
|
|
91
|
+
raise BdmvError(f"{rate} Hz: only LPCM and DTS-HD tracks go above 48 kHz")
|
|
92
|
+
if coding in (CODING_DTSHD, CODING_DTSHD_MA) and rate in CORE_RATE_CODES:
|
|
93
|
+
return CORE_RATE_CODES[rate]
|
|
94
|
+
if rate not in RATE_CODES:
|
|
95
|
+
raise BdmvError(f"{rate} Hz: a sound track runs at 48, 96 or 192 kHz")
|
|
96
|
+
return RATE_CODES[rate]
|
|
@@ -209,28 +209,8 @@ def ig_stream(buttons, frame_rate, default=None, popup=False, button_offset=0,
|
|
|
209
209
|
def patch_ig_stream_type(path, pmt_pid=PMT_PID, pid=IG_PID):
|
|
210
210
|
"""ffmpeg muxes the IG stream as a PGS stream (stream type 0x90): mark it
|
|
211
211
|
0x91 in every PMT of the clip (and fix the section CRC)."""
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
for off in range(0, len(data), 192):
|
|
215
|
-
p = off + 4
|
|
216
|
-
if (data[p + 1] & 0x1F) << 8 | data[p + 2] != pmt_pid or not data[p + 1] & 0x40:
|
|
217
|
-
continue
|
|
218
|
-
q = p + 4
|
|
219
|
-
if data[p + 3] & 0x20:
|
|
220
|
-
q += 1 + data[q]
|
|
221
|
-
q += 1 + data[q] # pointer field
|
|
222
|
-
length = (data[q + 1] & 0x0F) << 8 | data[q + 2]
|
|
223
|
-
end = q + 3 + length - 4
|
|
224
|
-
info = (data[q + 10] & 0x0F) << 8 | data[q + 11]
|
|
225
|
-
e = q + 12 + info
|
|
226
|
-
while e < end:
|
|
227
|
-
es_pid = (data[e + 1] & 0x1F) << 8 | data[e + 2]
|
|
228
|
-
if es_pid == pid:
|
|
229
|
-
data[e] = CODING_IG
|
|
230
|
-
e += 5 + ((data[e + 3] & 0x0F) << 8 | data[e + 4])
|
|
231
|
-
data[end:end + 4] = crc32(bytes(data[q:end])).to_bytes(4, "big")
|
|
232
|
-
f.seek(0)
|
|
233
|
-
f.write(data)
|
|
212
|
+
from .m2ts import set_stream_types
|
|
213
|
+
set_stream_types(path, {pid: CODING_IG}, pmt_pid)
|
|
234
214
|
|
|
235
215
|
|
|
236
216
|
def crc32(data):
|
|
@@ -100,3 +100,52 @@ def stream_pids(path, pmt_pid=PMT_PID):
|
|
|
100
100
|
e += 5 + ((pkt[e + 3] & 0x0F) << 8 | pkt[e + 4])
|
|
101
101
|
return pids
|
|
102
102
|
raise BdmvError(f"{path}: no program map table (PID {pmt_pid:#06x})")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def set_stream_types(path, types, pmt_pid=PMT_PID, chunk=1 << 22):
|
|
106
|
+
"""Give the elementary streams their stream types `types` ({PID: type})
|
|
107
|
+
in every program map table of the clip, in place, with the section CRC
|
|
108
|
+
made again. The clip is read a piece at a time and only its PMT packets
|
|
109
|
+
are written, so a long clip costs no more memory than a short one."""
|
|
110
|
+
from .igs import crc32
|
|
111
|
+
head = bytes([0x47, 0x40 | pmt_pid >> 8, pmt_pid & 0xFF]) # (a section starts in it)
|
|
112
|
+
chunk -= chunk % 192
|
|
113
|
+
with open(path, "r+b") as f:
|
|
114
|
+
pos = 0
|
|
115
|
+
while (data := f.read(chunk)):
|
|
116
|
+
i = data.find(head)
|
|
117
|
+
while i >= 0:
|
|
118
|
+
start = i - 4 # (the 4-byte packet header)
|
|
119
|
+
if start >= 0 and start % 192 == 0 and start + 192 <= len(data):
|
|
120
|
+
pkt = bytearray(data[start:start + 192])
|
|
121
|
+
if _retype(pkt, types, crc32):
|
|
122
|
+
f.seek(pos + start)
|
|
123
|
+
f.write(pkt)
|
|
124
|
+
f.seek(pos + len(data))
|
|
125
|
+
i = data.find(head, i + 1)
|
|
126
|
+
pos += len(data)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _retype(pkt, types, crc32):
|
|
130
|
+
"""Set the stream types in one PMT packet; whether it changed."""
|
|
131
|
+
p = 4
|
|
132
|
+
q = p + 4
|
|
133
|
+
if pkt[p + 3] & 0x20:
|
|
134
|
+
q += 1 + pkt[q]
|
|
135
|
+
q += 1 + pkt[q] # pointer field
|
|
136
|
+
if pkt[q] != 2: # (not a PMT section)
|
|
137
|
+
return False
|
|
138
|
+
end = q + 3 + ((pkt[q + 1] & 0x0F) << 8 | pkt[q + 2]) - 4
|
|
139
|
+
if end + 4 > len(pkt):
|
|
140
|
+
raise BdmvError("a program map table runs over its packet")
|
|
141
|
+
e = q + 12 + ((pkt[q + 10] & 0x0F) << 8 | pkt[q + 11])
|
|
142
|
+
changed = False
|
|
143
|
+
while e < end:
|
|
144
|
+
pid = (pkt[e + 1] & 0x1F) << 8 | pkt[e + 2]
|
|
145
|
+
if pid in types and pkt[e] != types[pid]:
|
|
146
|
+
pkt[e] = types[pid]
|
|
147
|
+
changed = True
|
|
148
|
+
e += 5 + ((pkt[e + 3] & 0x0F) << 8 | pkt[e + 4])
|
|
149
|
+
if changed:
|
|
150
|
+
pkt[end:end + 4] = crc32(bytes(pkt[q:end])).to_bytes(4, "big")
|
|
151
|
+
return changed
|
|
@@ -17,11 +17,11 @@ import shutil
|
|
|
17
17
|
|
|
18
18
|
from .clip import clpi
|
|
19
19
|
from .errors import BdmvError
|
|
20
|
-
from .formats import CODING_AC3, video_codes
|
|
20
|
+
from .formats import AUDIO_PID, CODING_AC3, DTS_CODINGS, video_codes
|
|
21
21
|
from .hdmv import (add, goto, if_at_least, if_equal, if_not_equal, index_bdmv, jump_object,
|
|
22
22
|
jump_title, jump_title_reg, move, movie_objects, play_pl, play_pl_mark, resume,
|
|
23
23
|
rnd, set_button, set_streams, set_subtitles)
|
|
24
|
-
from .m2ts import scan_m2ts
|
|
24
|
+
from .m2ts import scan_m2ts, set_stream_types, stream_pids
|
|
25
25
|
from .playlist import mpls
|
|
26
26
|
from .program import parse_action, transition_key
|
|
27
27
|
from .uops import mask
|
|
@@ -67,7 +67,7 @@ class Piece:
|
|
|
67
67
|
clip: str # clip name, e.g. "00001"
|
|
68
68
|
video_format: int
|
|
69
69
|
frame_rate: int
|
|
70
|
-
audio: list # [(coding, channels, lang3)]
|
|
70
|
+
audio: list # [(coding, channels, lang3, rate)]
|
|
71
71
|
pg: list # subtitle tracks [lang3]
|
|
72
72
|
marks: list # chapter starts, 45 kHz on the clip's time line
|
|
73
73
|
end: int # end of the clip, 45 kHz
|
|
@@ -332,21 +332,26 @@ def write_program(program, out_dir, move=True):
|
|
|
332
332
|
dest = os.path.join(out_dir, "BDMV", "STREAM", f"{name}.m2ts")
|
|
333
333
|
if os.path.abspath(src) != os.path.abspath(dest):
|
|
334
334
|
place(src, dest)
|
|
335
|
+
return dest
|
|
335
336
|
|
|
336
337
|
pieces, chapters = {}, []
|
|
337
338
|
for n, t in enumerate(p.titles, 1):
|
|
338
339
|
name = f"{n:05d}"
|
|
339
340
|
scan = scan_m2ts(t.clip)
|
|
340
341
|
video_format, frame_rate = _codes(t.fps, p)
|
|
341
|
-
audio = [(a.coding, a.channels, a.lang) for a in t.audio]
|
|
342
|
+
audio = [(a.coding, a.channels, a.lang, a.rate) for a in t.audio]
|
|
342
343
|
pg = [s.lang for s in t.subtitles]
|
|
343
344
|
marks = chapter_marks(t.chapters, scan)
|
|
344
345
|
chapters.append(len(marks))
|
|
345
346
|
pieces[t.id] = Piece(name, video_format, frame_rate, audio, pg, marks,
|
|
346
347
|
scan.end_pts // 2, ig=t.popup, hold=t.hold, uo=mask(t.prohibit))
|
|
348
|
+
types = audio_stream_types(t)
|
|
347
349
|
_write(out_dir, os.path.join("CLIPINF", f"{name}.clpi"),
|
|
348
350
|
clpi(scan, video_format, frame_rate, audio, pg, ig=t.popup))
|
|
349
|
-
|
|
351
|
+
if types:
|
|
352
|
+
set_stream_types(clip(t.clip, name), types)
|
|
353
|
+
else:
|
|
354
|
+
clip(t.clip, name)
|
|
350
355
|
for a in p.actions():
|
|
351
356
|
kind, tid, c = parse_action(a)
|
|
352
357
|
if kind == "chapter" and c > chapters[p.titles.index(p.title(tid))]:
|
|
@@ -404,6 +409,26 @@ def write_program(program, out_dir, move=True):
|
|
|
404
409
|
"chapters": chapters}
|
|
405
410
|
|
|
406
411
|
|
|
412
|
+
def audio_stream_types(title):
|
|
413
|
+
"""{PID: stream type} the title's clip needs changed so that its sound
|
|
414
|
+
tracks are marked as the title declares them. ffmpeg marks DTS by its
|
|
415
|
+
channels (0x85 above 6, else 0x82), not by the extensions it carries, so
|
|
416
|
+
a DTS track takes the declared DTS, DTS-HD or DTS-HD Master Audio type; a
|
|
417
|
+
track of another kind than declared is an error."""
|
|
418
|
+
have = stream_pids(title.clip)
|
|
419
|
+
out = {}
|
|
420
|
+
for k, a in enumerate(title.audio):
|
|
421
|
+
got = have.get(AUDIO_PID + k)
|
|
422
|
+
if got is None or got == a.coding:
|
|
423
|
+
continue
|
|
424
|
+
if got in DTS_CODINGS and a.coding in DTS_CODINGS:
|
|
425
|
+
out[AUDIO_PID + k] = a.coding
|
|
426
|
+
else:
|
|
427
|
+
raise BdmvError(f"title {title.id!r}: sound track {k + 1} has stream type "
|
|
428
|
+
f"{got:#04x} in {title.clip}, not the declared {a.coding:#04x}")
|
|
429
|
+
return out
|
|
430
|
+
|
|
431
|
+
|
|
407
432
|
def _parts(p, nav, kind, ident, pieces):
|
|
408
433
|
"""(piece, first chapter, last chapter) of one Blu-ray title's playlist."""
|
|
409
434
|
if kind == "title":
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Playlists (.mpls): play items with their streams, and chapter marks."""
|
|
2
2
|
|
|
3
3
|
from .formats import (AUDIO_PID, CODING_H264, CODING_IG, CODING_PG, IG_PID, PG_PID, VERSION,
|
|
4
|
-
VIDEO_PID)
|
|
4
|
+
VIDEO_PID, rate_code)
|
|
5
5
|
from .hdmv import _u8, _u16, _u32
|
|
6
6
|
|
|
7
7
|
|
|
@@ -10,9 +10,10 @@ def _video_attr(video_format, frame_rate):
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def _audio_attr(track):
|
|
13
|
-
coding, channels,
|
|
13
|
+
"""(coding, channels, lang3[, rate]): the rate 48000 unless given."""
|
|
14
|
+
coding, channels, lang, *rate = track
|
|
14
15
|
fmt = 6 if channels > 2 else 3
|
|
15
|
-
return bytes([coding, fmt << 4 |
|
|
16
|
+
return bytes([coding, fmt << 4 | rate_code(coding, *rate)]) + lang.encode("ascii")
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
def _pg_attr(lang, coding=CODING_PG):
|
|
@@ -22,7 +23,7 @@ def _pg_attr(lang, coding=CODING_PG):
|
|
|
22
23
|
def mpls(items, marks, uo=0):
|
|
23
24
|
"""A playlist. items: [(clip name, in, out, video_format, frame_rate,
|
|
24
25
|
audio, pg, ig, still[, uo])] played one after the other, times in 45 kHz
|
|
25
|
-
on each clip's time line, audio [(coding, channels, lang3)], pg [lang3]
|
|
26
|
+
on each clip's time line, audio [(coding, channels, lang3, rate)], pg [lang3]
|
|
26
27
|
(subtitles), ig: the clip carries menu buttons, still: 2 holds the
|
|
27
28
|
last picture (a still menu), (1, s) holds it for s seconds, uo: the
|
|
28
29
|
item's UO mask; marks: chapter marks as (item index, time); uo: the
|
|
@@ -24,6 +24,7 @@ Actions are strings:
|
|
|
24
24
|
import dataclasses
|
|
25
25
|
|
|
26
26
|
from .errors import BdmvError
|
|
27
|
+
from .formats import rate_code
|
|
27
28
|
from .uops import KEYS
|
|
28
29
|
|
|
29
30
|
|
|
@@ -51,10 +52,12 @@ def parse_action(s):
|
|
|
51
52
|
class Audio:
|
|
52
53
|
"""A sound track as the playlist declares it (the clip carries it with
|
|
53
54
|
PID AUDIO_PID + its index, as encode.encode_clip muxes it)."""
|
|
54
|
-
coding: int # formats.CODING_AC3, CODING_LPCM
|
|
55
|
+
coding: int # formats.CODING_AC3, CODING_LPCM, CODING_DTS,
|
|
56
|
+
# CODING_DTSHD or CODING_DTSHD_MA
|
|
55
57
|
channels: int = 2
|
|
56
58
|
lang: str = "und" # ISO 639-2 ("eng")
|
|
57
59
|
default: bool = False # the disc starts with it (first play)
|
|
60
|
+
rate: int = 48000 # 96000 or 192000: LPCM and DTS-HD only
|
|
58
61
|
|
|
59
62
|
|
|
60
63
|
@dataclasses.dataclass
|
|
@@ -223,6 +226,12 @@ class Program:
|
|
|
223
226
|
for it in p.items:
|
|
224
227
|
if it.title not in titles:
|
|
225
228
|
raise BdmvError(f"playlist {p.id!r}: no title {it.title!r}")
|
|
229
|
+
for t in self.titles:
|
|
230
|
+
for k, a in enumerate(t.audio, 1):
|
|
231
|
+
try:
|
|
232
|
+
rate_code(a.coding, a.rate)
|
|
233
|
+
except BdmvError as e:
|
|
234
|
+
raise BdmvError(f"title {t.id!r}, sound track {k}: {e.message}") from e
|
|
226
235
|
for x in self.titles + self.menus:
|
|
227
236
|
for k in x.prohibit:
|
|
228
237
|
if k not in KEYS:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bdmvkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.1
|
|
4
4
|
Summary: Blu-ray (BDMV) authoring in pure Python: playlists, clip information, HDMV navigation, PGS subtitles
|
|
5
5
|
Author: kajisho5
|
|
6
6
|
License-Expression: LGPL-3.0-or-later
|
|
@@ -35,14 +35,15 @@ only to encode.
|
|
|
35
35
|
|
|
36
36
|
日本語の説明は [README.ja.md](README.ja.md) にあります。
|
|
37
37
|
|
|
38
|
-
**Status: 0.
|
|
38
|
+
**Status: 0.7.** Titles with chapters, sound and subtitle tracks;
|
|
39
39
|
playlists (in order, at random or shuffled) and play all; menus whose
|
|
40
40
|
buttons start titles, chapters, playlists and other menus, switch sound and
|
|
41
41
|
subtitle tracks, or open a menu on a chosen button; loop counts, end-action
|
|
42
42
|
overrides, link transitions, remote keys a title turns off, and 720p. This
|
|
43
43
|
navigation is the one [oncemore](https://github.com/kajisho5/oncemore)
|
|
44
44
|
writes, byte for byte. 0.4 adds pop-up menus over a playing title, 0.5
|
|
45
|
-
menus with motion or music, 0.6 button streams for 720p menus.
|
|
45
|
+
menus with motion or music, 0.6 button streams for 720p menus, 0.7 DTS-HD
|
|
46
|
+
sound tracks.
|
|
46
47
|
|
|
47
48
|
## Why
|
|
48
49
|
|
|
@@ -95,6 +96,18 @@ disc.add_title("feature.m2ts", audio=[("ac3", 2, "en"), ("lpcm", 2, "en"), ("ac3
|
|
|
95
96
|
|
|
96
97
|
`Disc.write` checks that every track a title declares is in its clip.
|
|
97
98
|
|
|
99
|
+
DTS copied with its extensions is declared as what it is: `"dtshd"` (DTS-HD
|
|
100
|
+
High Resolution Audio) or `"dtshd_ma"` (DTS-HD Master Audio), with its
|
|
101
|
+
sampling rate when it is above 48 kHz (`("dtshd_ma", 8, "en", 96000)`;
|
|
102
|
+
LPCM may run at 96 or 192 kHz too). ffmpeg marks a DTS stream in the clip by
|
|
103
|
+
its channels, not by its extensions, so `Disc.write` marks each DTS track
|
|
104
|
+
with the type the title declares, in the copy it puts on the disc:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
encode_clip("feature.mkv", "feature.m2ts", audio=[AudioTrack("feature.mkv", "copy", 8)])
|
|
108
|
+
disc.add_title("feature.m2ts", audio=[("dtshd_ma", 8, "en")])
|
|
109
|
+
```
|
|
110
|
+
|
|
98
111
|
A menu is a picture and its buttons. Each button is a picture of how it
|
|
99
112
|
looks when selected (and, if given, when activated and before it is
|
|
100
113
|
selected), placed on the 1920 x 1080 menu, and a link:
|
|
@@ -163,8 +176,14 @@ menu's buttons run, for tools that make their own IG streams.
|
|
|
163
176
|
```sh
|
|
164
177
|
bdmvkit encode feature.mov feature.m2ts --chapters 0,300,600
|
|
165
178
|
bdmvkit build disc.json out
|
|
179
|
+
bdmvkit contract --json # machine-readable contract (AI Video Production OS registry)
|
|
166
180
|
```
|
|
167
181
|
|
|
182
|
+
`contract/contract.json` is that contract committed as a file (the `contract --json` output,
|
|
183
|
+
unchanged), so any release's contract is `git show vX.Y.Z:contract/contract.json`, with nothing
|
|
184
|
+
installed or run. Regenerate it with `python contract/generate.py` after a contract change or a
|
|
185
|
+
version bump; a unit test fails when it is stale.
|
|
186
|
+
|
|
168
187
|
`disc.json` looks like this:
|
|
169
188
|
|
|
170
189
|
```json
|
|
@@ -182,7 +201,8 @@ How the disc is laid out:
|
|
|
182
201
|
progressive frames in a 1080i stream, as the format asks. A program can
|
|
183
202
|
also be 720p (23.976, 50, 59.94; 25 and 29.97 go on at twice their rate);
|
|
184
203
|
`encode_clip` makes 1080 clips.
|
|
185
|
-
* Sound is AC-3, LPCM or DTS
|
|
204
|
+
* Sound is AC-3, LPCM, DTS, DTS-HD High Resolution Audio or DTS-HD Master
|
|
205
|
+
Audio (a DTS-HD track above 48 kHz is marked as such over its 48 kHz core).
|
|
186
206
|
* Subtitles are PGS streams muxed into the clip. `pgs.write_sup` makes them
|
|
187
207
|
from pictures, and `encode_clip(..., sups=[...])` muxes them in.
|
|
188
208
|
* First play and the Top Menu key open the first menu, or start title 1
|
|
@@ -5,6 +5,7 @@ pyproject.toml
|
|
|
5
5
|
bdmvkit/__init__.py
|
|
6
6
|
bdmvkit/__main__.py
|
|
7
7
|
bdmvkit/clip.py
|
|
8
|
+
bdmvkit/contract.py
|
|
8
9
|
bdmvkit/disc.py
|
|
9
10
|
bdmvkit/encode.py
|
|
10
11
|
bdmvkit/errors.py
|
|
@@ -22,7 +23,10 @@ bdmvkit.egg-info/SOURCES.txt
|
|
|
22
23
|
bdmvkit.egg-info/dependency_links.txt
|
|
23
24
|
bdmvkit.egg-info/entry_points.txt
|
|
24
25
|
bdmvkit.egg-info/top_level.txt
|
|
26
|
+
tests/test_contract.py
|
|
27
|
+
tests/test_contract_file.py
|
|
25
28
|
tests/test_disc.py
|
|
29
|
+
tests/test_dts.py
|
|
26
30
|
tests/test_files.py
|
|
27
31
|
tests/test_menus.py
|
|
28
32
|
tests/test_motion.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bdmvkit"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.7.1"
|
|
8
8
|
description = "Blu-ray (BDMV) authoring in pure Python: playlists, clip information, HDMV navigation, PGS subtitles"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "LGPL-3.0-or-later"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""The contract: the AI Video Production OS registry shape."""
|
|
2
|
+
|
|
3
|
+
import io
|
|
4
|
+
import json
|
|
5
|
+
import unittest
|
|
6
|
+
from contextlib import redirect_stdout
|
|
7
|
+
|
|
8
|
+
from bdmvkit import __version__
|
|
9
|
+
from bdmvkit.__main__ import main
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TestContract(unittest.TestCase):
|
|
13
|
+
def test_contract_json(self):
|
|
14
|
+
out = io.StringIO()
|
|
15
|
+
with redirect_stdout(out):
|
|
16
|
+
self.assertEqual(main(["contract", "--json"]), 0)
|
|
17
|
+
c = json.loads(out.getvalue())
|
|
18
|
+
for k in ("skill_id", "version", "contract_version", "provides", "dependencies", "not_provided"):
|
|
19
|
+
self.assertIn(k, c)
|
|
20
|
+
self.assertEqual((c["skill_id"], c["version"]), ("bdmvkit", __version__))
|
|
21
|
+
tool_ids = [t["tool_id"] for t in c["tools"]]
|
|
22
|
+
ids = [p["id"] for p in c["provides"]]
|
|
23
|
+
self.assertEqual(len(ids), len(set(ids)))
|
|
24
|
+
for p in c["provides"]:
|
|
25
|
+
self.assertEqual(set(p), {"id", "lifecycle", "tool_id"})
|
|
26
|
+
self.assertIn(p["lifecycle"], ("PROPOSED", "EXPERIMENTAL", "STABLE", "DEPRECATED", "RETIRED"))
|
|
27
|
+
self.assertIn(p["tool_id"], tool_ids)
|
|
28
|
+
self.assertFalse(c["execution"]["network"])
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if __name__ == "__main__":
|
|
32
|
+
unittest.main()
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""contract/contract.json is the committed copy of the contract; it must match what the code prints."""
|
|
2
|
+
import subprocess
|
|
3
|
+
import sys
|
|
4
|
+
import unittest
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CommittedContractFileTest(unittest.TestCase):
|
|
11
|
+
def test_contract_file_is_up_to_date(self):
|
|
12
|
+
result = subprocess.run([sys.executable, str(ROOT / "contract" / "generate.py"), "--check"],
|
|
13
|
+
capture_output=True, text=True)
|
|
14
|
+
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
if __name__ == "__main__":
|
|
18
|
+
unittest.main()
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""DTS-HD sound tracks: a title declares DTS-HD High Resolution or Master
|
|
2
|
+
Audio (above 48 kHz too), the clip's PMT is marked so (ffmpeg marks DTS by
|
|
3
|
+
its channels), and libbluray reads the streams as declared."""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import tempfile
|
|
9
|
+
import unittest
|
|
10
|
+
|
|
11
|
+
from bdmvkit import BdmvError, Disc
|
|
12
|
+
from bdmvkit.encode import AudioTrack, encode_clip
|
|
13
|
+
from bdmvkit.formats import (AUDIO_PID, CODING_DTS, CODING_DTSHD, CODING_DTSHD_MA, PMT_PID,
|
|
14
|
+
rate_code)
|
|
15
|
+
from bdmvkit.igs import crc32
|
|
16
|
+
from bdmvkit.m2ts import set_stream_types, stream_pids
|
|
17
|
+
|
|
18
|
+
from .test_disc import ENCODE_OK, LIBBLURAY, bluray_sim, source
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def pmts(path):
|
|
22
|
+
"""[(stream type of the first sound track, section CRC good)] of every
|
|
23
|
+
PMT of a clip."""
|
|
24
|
+
out = []
|
|
25
|
+
with open(path, "rb") as f:
|
|
26
|
+
while len(pkt := f.read(192)) == 192:
|
|
27
|
+
if (pkt[5] & 0x1F) << 8 | pkt[6] != PMT_PID or not pkt[5] & 0x40:
|
|
28
|
+
continue
|
|
29
|
+
q = 8 + 1 + pkt[8]
|
|
30
|
+
end = q + 3 + ((pkt[q + 1] & 0x0F) << 8 | pkt[q + 2])
|
|
31
|
+
e = q + 12 + ((pkt[q + 10] & 0x0F) << 8 | pkt[q + 11])
|
|
32
|
+
while (pkt[e + 1] & 0x1F) << 8 | pkt[e + 2] != AUDIO_PID:
|
|
33
|
+
e += 5 + ((pkt[e + 3] & 0x0F) << 8 | pkt[e + 4])
|
|
34
|
+
out.append((pkt[e], crc32(pkt[q:end]) == 0))
|
|
35
|
+
return out
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class TestRates(unittest.TestCase):
|
|
39
|
+
def test_codes(self):
|
|
40
|
+
self.assertEqual(rate_code(CODING_DTS), 1)
|
|
41
|
+
self.assertEqual(rate_code(CODING_DTSHD_MA, 96000), 14) # (over a 48 kHz core)
|
|
42
|
+
self.assertEqual(rate_code(CODING_DTSHD, 192000), 12)
|
|
43
|
+
self.assertEqual(rate_code(0x80, 96000), 4) # LPCM
|
|
44
|
+
for coding, rate in ((0x81, 96000), (CODING_DTS, 96000), (CODING_DTSHD_MA, 44100)):
|
|
45
|
+
with self.assertRaises(BdmvError):
|
|
46
|
+
rate_code(coding, rate)
|
|
47
|
+
|
|
48
|
+
def test_add_title(self):
|
|
49
|
+
d = Disc()
|
|
50
|
+
d.add_title("a.m2ts", audio=[("dtshd_ma", 8, "en", 96000), ("dtshd", 6, "ja")])
|
|
51
|
+
a = d.program().titles[0].audio
|
|
52
|
+
self.assertEqual([(x.coding, x.rate) for x in a],
|
|
53
|
+
[(CODING_DTSHD_MA, 96000), (CODING_DTSHD, 48000)])
|
|
54
|
+
with self.assertRaises(BdmvError):
|
|
55
|
+
d.add_title("a.m2ts", audio=[("ac3", 2, "en", 96000)])
|
|
56
|
+
with self.assertRaises(BdmvError):
|
|
57
|
+
d.add_title("a.m2ts", audio=[("dts-hd", 6, "en")])
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@unittest.skipUnless(ENCODE_OK, "needs ffmpeg with libx264")
|
|
61
|
+
class TestDtsHd(unittest.TestCase):
|
|
62
|
+
@classmethod
|
|
63
|
+
def setUpClass(cls):
|
|
64
|
+
cls.tmp = d = tempfile.mkdtemp(prefix="bdmvkit-dts-")
|
|
65
|
+
# a 5.1 DTS stream (ffmpeg's encoder writes the core alone; what
|
|
66
|
+
# bdmvkit does is the same for a core with extensions)
|
|
67
|
+
dts = os.path.join(d, "sound.dts")
|
|
68
|
+
subprocess.run(["ffmpeg", "-hide_banner", "-v", "error", "-y", "-f", "lavfi", "-i",
|
|
69
|
+
"sine=d=3:r=48000", "-ac", "6", "-c:a", "dca", "-strict", "-2", dts],
|
|
70
|
+
check=True)
|
|
71
|
+
cls.clip = encode_clip(source(os.path.join(d, "v.mp4"), 3, tone=False),
|
|
72
|
+
os.path.join(d, "v.m2ts"), fast=True,
|
|
73
|
+
audio=[AudioTrack(dts, "copy", 6)])
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def tearDownClass(cls):
|
|
77
|
+
shutil.rmtree(cls.tmp, ignore_errors=True)
|
|
78
|
+
|
|
79
|
+
def write(self, *audio):
|
|
80
|
+
out = tempfile.mkdtemp(dir=self.tmp)
|
|
81
|
+
disc = Disc()
|
|
82
|
+
for a in audio:
|
|
83
|
+
disc.add_title(self.clip, audio=[a])
|
|
84
|
+
disc.write(out)
|
|
85
|
+
return out
|
|
86
|
+
|
|
87
|
+
def test_marked_as_declared(self):
|
|
88
|
+
self.assertEqual(stream_pids(self.clip)[AUDIO_PID], CODING_DTS) # (ffmpeg: 6 channels)
|
|
89
|
+
out = self.disc()
|
|
90
|
+
for name, want in (("00001", CODING_DTSHD_MA), ("00002", CODING_DTSHD),
|
|
91
|
+
("00003", CODING_DTS)):
|
|
92
|
+
got = pmts(os.path.join(out, "BDMV", "STREAM", f"{name}.m2ts"))
|
|
93
|
+
self.assertGreater(len(got), 1)
|
|
94
|
+
self.assertEqual(set(got), {(want, True)}, name) # every PMT, CRC made again
|
|
95
|
+
self.assertEqual(set(pmts(self.clip)), {(CODING_DTS, True)}) # (the source as it was)
|
|
96
|
+
|
|
97
|
+
@unittest.skipUnless(LIBBLURAY, "needs libbluray")
|
|
98
|
+
def test_read_by_libbluray(self):
|
|
99
|
+
with bluray_sim.Disc(LIBBLURAY, self.disc()) as d:
|
|
100
|
+
a, b, c = d.playlist(1), d.playlist(2), d.playlist(3)
|
|
101
|
+
self.assertEqual(a["audio"], [(CODING_DTSHD_MA, 6, "eng")])
|
|
102
|
+
self.assertEqual((b["audio"], b["audio_rate"]), ([(CODING_DTSHD, 6, "eng")], [14]))
|
|
103
|
+
self.assertEqual((c["audio"], c["audio_rate"]), ([(CODING_DTS, 6, "eng")], [1]))
|
|
104
|
+
|
|
105
|
+
def disc(self):
|
|
106
|
+
"""Three titles of the same clip: DTS-HD Master Audio, DTS-HD High
|
|
107
|
+
Resolution at 96 kHz (over its 48 kHz core) and DTS."""
|
|
108
|
+
return self.write(("dtshd_ma", 6, "en"), ("dtshd", 6, "en", 96000), ("dts", 6, "en"))
|
|
109
|
+
|
|
110
|
+
def test_not_dts(self):
|
|
111
|
+
with self.assertRaises(BdmvError) as e:
|
|
112
|
+
self.write(("ac3", 6, "en"))
|
|
113
|
+
self.assertIn("stream type 0x82", e.exception.message)
|
|
114
|
+
|
|
115
|
+
def test_retyped_a_piece_at_a_time(self):
|
|
116
|
+
copy = os.path.join(self.tmp, "copy.m2ts")
|
|
117
|
+
shutil.copyfile(self.clip, copy)
|
|
118
|
+
set_stream_types(copy, {AUDIO_PID: CODING_DTSHD_MA}, chunk=192 * 7)
|
|
119
|
+
got = pmts(copy)
|
|
120
|
+
self.assertEqual(set(got), {(CODING_DTSHD_MA, True)})
|
|
121
|
+
self.assertEqual(len(got), len(pmts(self.clip)))
|
|
122
|
+
with open(copy, "rb") as f, open(self.clip, "rb") as g:
|
|
123
|
+
a, b = f.read(), g.read()
|
|
124
|
+
self.assertEqual(len(a), len(b))
|
|
125
|
+
diff = {i // 192 for i in range(len(a)) if a[i] != b[i]}
|
|
126
|
+
self.assertEqual(len(diff), len(got)) # (only the PMTs)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
if __name__ == "__main__":
|
|
130
|
+
unittest.main()
|
|
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
|