motionkit2d 1.0.1__tar.gz → 1.0.2__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.
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/MANIFEST.in +5 -2
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/PKG-INFO +6 -6
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/README.md +5 -5
- motionkit2d-1.0.2/docs/gpu.md +133 -0
- motionkit2d-1.0.2/docs/guide.md +334 -0
- motionkit2d-1.0.2/docs/index.md +14 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/docs/publishing.md +5 -4
- motionkit2d-1.0.2/docs/verification.md +34 -0
- motionkit2d-1.0.2/examples/README.md +20 -0
- motionkit2d-1.0.1/examples/roadmap.py → motionkit2d-1.0.2/examples/animation.py +1 -1
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/pyproject.toml +1 -1
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/__init__.py +1 -1
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d.egg-info/PKG-INFO +6 -6
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d.egg-info/SOURCES.txt +11 -17
- motionkit2d-1.0.2/tools/acceptance.py +82 -0
- motionkit2d-1.0.2/tools/benchmark.py +67 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/tools/check_distribution.py +17 -7
- motionkit2d-1.0.2/tools/check_repository.py +32 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/tools/package_release.py +4 -3
- {motionkit2d-1.0.1/verification/v1.0.0 → motionkit2d-1.0.2/verification}/benchmark.json +10 -10
- motionkit2d-1.0.1/verification/v1.0.0/acceptance.json → motionkit2d-1.0.2/verification/report.json +76 -1
- motionkit2d-1.0.1/verification/v1.0.0/tests-source.txt → motionkit2d-1.0.2/verification/tests.txt +31 -31
- motionkit2d-1.0.1/benchmarks/v1.json +0 -35
- motionkit2d-1.0.1/docs/guide.md +0 -101
- motionkit2d-1.0.1/docs/index.md +0 -12
- motionkit2d-1.0.1/docs/verification.md +0 -31
- motionkit2d-1.0.1/tools/acceptance.py +0 -62
- motionkit2d-1.0.1/tools/acceptance_v04.py +0 -46
- motionkit2d-1.0.1/tools/acceptance_v1.py +0 -34
- motionkit2d-1.0.1/tools/benchmark_v03.py +0 -43
- motionkit2d-1.0.1/tools/benchmark_v1.py +0 -34
- motionkit2d-1.0.1/tools/release_milestone.py +0 -33
- motionkit2d-1.0.1/verification/v1.0.0/manifest.json +0 -15
- motionkit2d-1.0.1/verification/v1.0.0/tests-installed.txt +0 -67
- motionkit2d-1.0.1/verification/v1.0.1/manifest.json +0 -8
- motionkit2d-1.0.1/verification/v1.0.1/tests-installed.txt +0 -67
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/examples/classroom.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/examples/director.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/examples/episode.json +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/examples/gpu_showcase.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/examples/loi_hoi_tham.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/examples/make_demo_audio.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/examples/vao_lop.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/examples/vao_lop_doc.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/setup.cfg +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/__main__.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/acceleration.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/assets.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/audio.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/audio_analysis.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/camera.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/catalog.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/characters/__init__.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/characters/actions.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/characters/builder.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/characters/expressions.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/compiler.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/composition.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/constraints.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/cues.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/draw.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/dynamics.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/effects.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/environments.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/export.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/fonts/LICENSE.txt +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/fonts/LiberationSans-Regular.ttf +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/fonts/LiberationSerif-Bold.ttf +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/fonts/LiberationSerif-Regular.ttf +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/gpu.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/layout.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/manifest.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/mixer.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/preset_library.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/presets.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/props.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/qc.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/quality.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/rig.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/scene_graph.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/timeline.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/transitions.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/typography.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d/visual_effects.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d.egg-info/dependency_links.txt +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d.egg-info/entry_points.txt +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d.egg-info/requires.txt +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/src/motionkit2d.egg-info/top_level.txt +0 -0
- /motionkit2d-1.0.1/tests/test_v03.py → /motionkit2d-1.0.2/tests/test_acceleration.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/tests/test_director.py +0 -0
- /motionkit2d-1.0.1/tests/test_roadmap.py → /motionkit2d-1.0.2/tests/test_integration.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/tests/test_motionkit.py +0 -0
- /motionkit2d-1.0.1/tests/test_v02.py → /motionkit2d-1.0.2/tests/test_rig_timeline_audio.py +0 -0
- {motionkit2d-1.0.1 → motionkit2d-1.0.2}/tools/diagnose_playback.ps1 +0 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
include README.md pyproject.toml setup.cfg MANIFEST.in
|
|
2
2
|
recursive-include docs *.md
|
|
3
3
|
recursive-include verification *.md *.txt *.json
|
|
4
|
-
recursive-include examples *.py *.json
|
|
4
|
+
recursive-include examples *.py *.json *.md
|
|
5
5
|
recursive-include tools *.py *.ps1
|
|
6
6
|
recursive-include tests *.py
|
|
7
|
-
recursive-include benchmarks *.json
|
|
8
7
|
recursive-include src/motionkit2d *.py *.ttf LICENSE.txt
|
|
9
8
|
prune .git
|
|
10
9
|
prune .github
|
|
@@ -17,3 +16,7 @@ prune template
|
|
|
17
16
|
prune audio
|
|
18
17
|
prune output
|
|
19
18
|
global-exclude __pycache__ *.py[cod] .env .env.*
|
|
19
|
+
exclude tools/release_milestone.py tools/*_v*.py tests/test_v*.py
|
|
20
|
+
prune verification/v1.0.0
|
|
21
|
+
prune verification/v1.0.1
|
|
22
|
+
prune benchmarks
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: motionkit2d
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: Deterministic 2D motion graphics from Python scenes
|
|
5
5
|
Project-URL: Repository, https://github.com/dangminhtai/motionkit2d
|
|
6
6
|
Project-URL: Documentation, https://github.com/dangminhtai/motionkit2d/blob/main/docs/index.md
|
|
@@ -88,13 +88,13 @@ python -m motionkit2d demo.py --verify --output demo.mp4
|
|
|
88
88
|
|
|
89
89
|
The [API guide](https://github.com/dangminhtai/motionkit2d/blob/main/docs/guide.md)
|
|
90
90
|
describes the current API. Versioned historical reports are separate from it.
|
|
91
|
-
[Verification records](https://github.com/dangminhtai/motionkit2d/tree/main/verification
|
|
92
|
-
contain
|
|
93
|
-
|
|
91
|
+
[Verification records](https://github.com/dangminhtai/motionkit2d/tree/main/verification)
|
|
92
|
+
contain one current test log, acceptance report and benchmark, with scope and
|
|
93
|
+
limitations. These are local test evidence, not CI attestations. Prior records
|
|
94
|
+
remain in Git history rather than parallel files in the working tree.
|
|
94
95
|
|
|
95
96
|
The source distribution includes docs/, verification/, examples/ and tests/.
|
|
96
97
|
The installed wheel contains the runtime library and bundled fonts.
|
|
97
|
-
Version 1.0.1 changes documentation, packaging and metadata, not animation behavior.
|
|
98
98
|
See [publishing/provenance](https://github.com/dangminhtai/motionkit2d/blob/main/docs/publishing.md)
|
|
99
99
|
for the distinction between file hashes and publisher identity attestations.
|
|
100
100
|
|
|
@@ -104,7 +104,7 @@ for the distinction between file hashes and publisher identity attestations.
|
|
|
104
104
|
python -m pip install -e ".[gpu,quality]"
|
|
105
105
|
python -m unittest discover -s tests -v
|
|
106
106
|
python -m motionkit2d examples/episode.json --validate
|
|
107
|
-
python -m motionkit2d examples/
|
|
107
|
+
python -m motionkit2d examples/animation.py --quality
|
|
108
108
|
```
|
|
109
109
|
|
|
110
110
|
The examples/ and tests/ commands require the repository or source distribution.
|
|
@@ -71,13 +71,13 @@ python -m motionkit2d demo.py --verify --output demo.mp4
|
|
|
71
71
|
|
|
72
72
|
The [API guide](https://github.com/dangminhtai/motionkit2d/blob/main/docs/guide.md)
|
|
73
73
|
describes the current API. Versioned historical reports are separate from it.
|
|
74
|
-
[Verification records](https://github.com/dangminhtai/motionkit2d/tree/main/verification
|
|
75
|
-
contain
|
|
76
|
-
|
|
74
|
+
[Verification records](https://github.com/dangminhtai/motionkit2d/tree/main/verification)
|
|
75
|
+
contain one current test log, acceptance report and benchmark, with scope and
|
|
76
|
+
limitations. These are local test evidence, not CI attestations. Prior records
|
|
77
|
+
remain in Git history rather than parallel files in the working tree.
|
|
77
78
|
|
|
78
79
|
The source distribution includes docs/, verification/, examples/ and tests/.
|
|
79
80
|
The installed wheel contains the runtime library and bundled fonts.
|
|
80
|
-
Version 1.0.1 changes documentation, packaging and metadata, not animation behavior.
|
|
81
81
|
See [publishing/provenance](https://github.com/dangminhtai/motionkit2d/blob/main/docs/publishing.md)
|
|
82
82
|
for the distinction between file hashes and publisher identity attestations.
|
|
83
83
|
|
|
@@ -87,7 +87,7 @@ for the distinction between file hashes and publisher identity attestations.
|
|
|
87
87
|
python -m pip install -e ".[gpu,quality]"
|
|
88
88
|
python -m unittest discover -s tests -v
|
|
89
89
|
python -m motionkit2d examples/episode.json --validate
|
|
90
|
-
python -m motionkit2d examples/
|
|
90
|
+
python -m motionkit2d examples/animation.py --quality
|
|
91
91
|
```
|
|
92
92
|
|
|
93
93
|
The examples/ and tests/ commands require the repository or source distribution.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# MotionKit2D v0.3: tăng tốc GPU
|
|
2
|
+
|
|
3
|
+
## Cài và chạy
|
|
4
|
+
|
|
5
|
+
Python >=3.10, FFmpeg/ffprobe trong PATH. Pillow/numpy vẫn bắt buộc; ModernGL là
|
|
6
|
+
extra tùy chọn, cần OpenGL phần cứng >=3.3. Không cần CUDA Toolkit cho backend này
|
|
7
|
+
hoặc NVENC qua FFmpeg. Driver và build FFmpeg phải hỗ trợ encoder.
|
|
8
|
+
|
|
9
|
+
```powershell
|
|
10
|
+
python -m pip install ".[gpu]"
|
|
11
|
+
python -m motionkit2d --devices
|
|
12
|
+
python -m motionkit2d examples/gpu_showcase.py --backend gpu --encoder nvenc --speed fast
|
|
13
|
+
python -m motionkit2d examples/loi_hoi_tham.py --workers auto --speed fast
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Nếu dùng môi trường riêng đã cài package, thay `python` bằng
|
|
17
|
+
`.\.venv-accept\Scripts\python.exe`.
|
|
18
|
+
|
|
19
|
+
`--devices` tạo GL context thật và encode thử một frame 1024×576 với từng encoder.
|
|
20
|
+
Khi render, probe lại theo kích thước/fps/preset thực tế. Có tên trong danh sách
|
|
21
|
+
`ffmpeg -encoders` chưa đủ để coi hardware encode dùng được.
|
|
22
|
+
|
|
23
|
+
## Hai đường tạo hình
|
|
24
|
+
|
|
25
|
+
1. **Project cũ:** `paint(im,f)` tiếp tục nhận ảnh Pillow RGB 2×. Chữ, blur và
|
|
26
|
+
hình vẫn được Pillow vẽ trên CPU. Có thể chia frame qua nhiều CPU worker,
|
|
27
|
+
hoặc dùng GPU downsample, rồi hardware encode.
|
|
28
|
+
2. **Project GPU:** thêm `gpu_paint(canvas,f)` vào Scene. Geometry, gradient,
|
|
29
|
+
sprite, ghép layer và transition chạy bằng OpenGL. Frame ở GPU cho đến sau
|
|
30
|
+
downsample. Glyph/font được rasterize bằng Pillow lần đầu, lưu texture để
|
|
31
|
+
ghép trên GPU ở các frame sau.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from motionkit2d import Scene, Video, draw, effects
|
|
35
|
+
|
|
36
|
+
def paint(im, f):
|
|
37
|
+
draw.gradient(im, '#090D18', '#253C51')
|
|
38
|
+
d = draw.draw(im)
|
|
39
|
+
draw.oval(d, 512 + 80*f.t, 320, 110, 110, '#F12936')
|
|
40
|
+
draw.text(im, 512, 130, 'Xin chào, tiếng Việt!', 48, style='bold')
|
|
41
|
+
effects.wash(im, '#000000', max(0, (f.t-2.5)/.5))
|
|
42
|
+
|
|
43
|
+
# Cùng hàm dùng được khi chỉ gọi những thao tác hỗ trợ cả hai backend.
|
|
44
|
+
VIDEO = Video([Scene('GPU', 3, paint, gpu_paint=paint)])
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Chỉ đặt `gpu_paint=paint` sau khi kiểm tra painter tương thích. Có `.filter`,
|
|
48
|
+
`.crop`, `ImageDraw.Draw`, numpy đọc pixel hoặc thao tác Pillow trực tiếp thì
|
|
49
|
+
giữ painter CPU hoặc viết callback GPU riêng. Không tự chuyển callback khi gặp lỗi;
|
|
50
|
+
lỗi lập trình phải được báo, thay vì âm thầm xuất cảnh khác.
|
|
51
|
+
|
|
52
|
+
## API hỗ trợ GPU
|
|
53
|
+
|
|
54
|
+
- `draw.draw`, `polygon` (polygon đơn, có thể lõm), `oval`, `rect`, `line`, `cubic`.
|
|
55
|
+
- `draw.gradient`, `stage`, `particles`, `person`, `heart`, `text`, `say`, `halo`, `paste`.
|
|
56
|
+
Những asset tạo ảnh Pillow vẫn được CPU tạo rồi upload khi ghép.
|
|
57
|
+
- `effects.sprite`, `effects.wash`; sprite có scale/rotation/opacity/anchor.
|
|
58
|
+
- `canvas.clear(color)`, `canvas.layer(width,height)`, `canvas.sprite(...)`.
|
|
59
|
+
- `with canvas.layer(w,h) as layer:` tạo layer GPU và tự giải phóng sau sử dụng.
|
|
60
|
+
Vẽ layer trước rồi dùng `effects.sprite(canvas,layer,...)` trong khối `with`.
|
|
61
|
+
Không sample chính canvas đang làm đích. Layer phải thuộc cùng device.
|
|
62
|
+
- GPUCanvas dùng tọa độ design pixel; `size` là kích thước vật lý 2×, `width/height`
|
|
63
|
+
là kích thước design. `paste(color,box)` nhận box vật lý như Pillow.
|
|
64
|
+
|
|
65
|
+
Text glow/focus blur ban đầu vẫn dùng Pillow. Sprite GPU dùng nội suy linear;
|
|
66
|
+
downsample cuối dùng shader Lanczos hai pass. Gradient không có dither ngẫu nhiên
|
|
67
|
+
như Pillow; nét và biên có thể khác vài pixel. Không cam kết giống từng byte.
|
|
68
|
+
Cache texture giới hạn mặc định 64 MiB mỗi render (một texture đơn quá lớn có thể
|
|
69
|
+
vượt giới hạn này); ảnh Pillow mutable được upload lại, tránh cache sai ảnh.
|
|
70
|
+
|
|
71
|
+
## Chọn chế độ và hiệu năng
|
|
72
|
+
|
|
73
|
+
| Tham số | Hành vi |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `backend='auto'` | Ưu tiên native GPU scene. Legacy một worker: đo median 3 lần resize CPU và GPU upload/filter/readback sau warm-up, chỉ dùng GPU khi lợi >5%. Nhiều legacy worker: resize tại CPU worker. |
|
|
76
|
+
| `backend='gpu'` | Bắt buộc GL phần cứng; legacy scene vẫn vẽ bằng CPU rồi upload. Không fallback âm thầm nếu khởi tạo không được. |
|
|
77
|
+
| `backend='cpu'` | Pillow tạo hình/resize; encoder được chọn độc lập. |
|
|
78
|
+
| `encoder='auto'` | Probe NVENC → QSV → AMF → libx264, chọn encoder đầu tiên encode được. Đây là ưu tiên khả dụng, không benchmark mọi encoder. |
|
|
79
|
+
| `encoder='cpu'/'nvenc'/'qsv'/'amf'` | Chọn cụ thể; hardware không dùng được thì báo lỗi. |
|
|
80
|
+
| `speed='fast'/'balanced'/'quality'` | x264 veryfast/medium/slow; NVENC p1/p4/p7; QSV veryfast/medium/veryslow; AMF speed/balanced/quality. |
|
|
81
|
+
| `workers=1` | Mặc định Python API, phù hợp closure/video tạo trực tiếp trong chương trình. |
|
|
82
|
+
| `workers='auto'` | Mặc định CLI; tối đa 4 legacy worker, giới hạn theo kích thước và số frame; native GPU dùng một GL context. |
|
|
83
|
+
| `workers=N, project_path=...` | Reload project bằng spawn; cần VIDEO giống timeline truyền vào. Hàng đợi giới hạn theo số worker, trả frame đúng thứ tự. |
|
|
84
|
+
|
|
85
|
+
Worker chỉ chạy code project để tạo VIDEO, không chạy khối `if __name__=='__main__'`.
|
|
86
|
+
Đặt tác vụ ghi file/render trong khối main, tránh side effect khi import. Không sửa
|
|
87
|
+
VIDEO trong RAM rồi truyền cùng `project_path` khác nội dung; signature chỉ kiểm
|
|
88
|
+
kích thước, fps, timeline và tên scene, không kiểm closure. Nhiều worker yêu cầu
|
|
89
|
+
project deterministic và độc lập thứ tự lấy frame.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from motionkit2d import render
|
|
93
|
+
report = {}
|
|
94
|
+
render(VIDEO, 'output/film.mp4', backend='auto', encoder='auto', speed='fast',
|
|
95
|
+
workers='auto', project_path=__file__, report=report)
|
|
96
|
+
print(report)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`report` chứa backend, vendor/renderer GL, encoder thực, kết quả probe, lựa chọn
|
|
100
|
+
resize, workers, tổng giây và fps. Tổng thời gian gồm khởi tạo driver/probe/worker
|
|
101
|
+
và encode; không phải thời gian shader riêng.
|
|
102
|
+
|
|
103
|
+
`crf` giữ tương thích chữ ký cũ, là quality 0–51: x264 dùng CRF, NVENC VBR-CQ
|
|
104
|
+
(0 chuyển thành CQ 1 để tránh chế độ auto), QSV global_quality, AMF CQP.
|
|
105
|
+
Cùng một số không có nghĩa cùng bitrate hoặc chất lượng giữa encoder.
|
|
106
|
+
|
|
107
|
+
## Thiết bị và giới hạn
|
|
108
|
+
|
|
109
|
+
GL renderer do driver/OS chọn; trên máy hybrid có thể là Intel trong khi NVENC
|
|
110
|
+
dùng NVIDIA. Kiểm tra `--devices` và report thay vì suy luận từ `nvidia-smi`.
|
|
111
|
+
Trên Windows, có thể chọn GPU hiệu năng cao cho Python trong Graphics settings,
|
|
112
|
+
khởi động lại Python rồi kiểm tra renderer; thư viện không tự sửa cấu hình hệ thống.
|
|
113
|
+
|
|
114
|
+
Đường FFmpeg vẫn nhận RGB từ RAM: đây không phải zero-copy GPU→NVENC. Nhiều lớp
|
|
115
|
+
Pillow, blur và đọc pixel vẫn có thể là nút thắt. Upload/readback có thể chậm hơn
|
|
116
|
+
CPU resize, nhất là iGPU hoặc frame nhỏ. Tùy workload, CPU song song + NVENC có
|
|
117
|
+
thể nhanh hơn GPUCanvas.
|
|
118
|
+
|
|
119
|
+
Benchmark tái lập:
|
|
120
|
+
|
|
121
|
+
```powershell
|
|
122
|
+
python tools/benchmark.py --mode export
|
|
123
|
+
python -m unittest discover -s tests -v
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Chế độ export so CPU một worker với CPU nhiều worker, rồi thêm GPU upload và
|
|
127
|
+
GPU native khi có thiết bị. Encoder dùng chế độ auto và được ghi trong report.
|
|
128
|
+
Kết quả ở `output/benchmark.json`; MP4 trong `output/benchmark-media/` được kiểm
|
|
129
|
+
metadata/full decode. Dùng `--project` để chọn workload, `--mode frames` để chỉ
|
|
130
|
+
đo frame pipeline mà không encode. Đây không phải tốc độ bảo đảm cho mọi project.
|
|
131
|
+
|
|
132
|
+
Nguồn API: [ModernGL](https://moderngl.readthedocs.io/en/stable/reference/context.html),
|
|
133
|
+
[NVENC/FFmpeg](https://docs.nvidia.com/video-technologies/video-codec-sdk/13.1/ffmpeg-with-nvidia-gpu/index.html).
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# MotionKit2D 1.x API guide
|
|
2
|
+
|
|
3
|
+
## Public API contract
|
|
4
|
+
|
|
5
|
+
- Import từ `motionkit2d` hoặc module cụ thể. Giữ các đường import cũ của v0.3/v0.4.
|
|
6
|
+
- Design pixels, gốc trái trên, giây, rotation CCW, scale >0. Raster API dùng `draw.S=2`.
|
|
7
|
+
- Tất cả motion/particle/physics sampling là hàm của t; đọc frame ngược/ngẫu nhiên
|
|
8
|
+
không được làm đổi kết quả. Physics bounce replay bước cố định từ trạng thái đầu.
|
|
9
|
+
- Scene callbacks vẫn là escape hatch. SceneGraph là optional, không yêu cầu chuyển
|
|
10
|
+
project cũ. Painter/text local raster bị cắt tại viewport trước transform;
|
|
11
|
+
Character/Prop/Attachment được vẽ trực tiếp bằng transform cuối.
|
|
12
|
+
- Manifest runtime giữ schema_version **1** (integer); engine v1 không đổi schema lên 1.0.
|
|
13
|
+
API JSON version độc lập package version. Unknown field/cycle/NaN bị reject.
|
|
14
|
+
- Trong series 1.x giữ tên và positional arguments hiện hữu. Thay đổi breaking cần
|
|
15
|
+
major version; extension thêm optional keyword/registry. Module nội bộ `_...` không
|
|
16
|
+
có cam kết API. Tên asset mặc định và anchor cũ được giữ.
|
|
17
|
+
- Lỗi cấu hình báo ValueError/ManifestError; tên registry không có báo KeyError.
|
|
18
|
+
Lỗi external tool có thể là OSError/subprocess.CalledProcessError. Không nuốt lỗi
|
|
19
|
+
rồi báo đã render hoặc ghi đè file đích khi tác vụ thất bại.
|
|
20
|
+
|
|
21
|
+
## Cài/chạy
|
|
22
|
+
|
|
23
|
+
```powershell
|
|
24
|
+
python -m pip install -e ".[gpu,quality]"
|
|
25
|
+
python -m motionkit2d examples/episode.json --validate
|
|
26
|
+
python -m motionkit2d examples/animation.py --backend cpu --encoder cpu --workers 2
|
|
27
|
+
python -m motionkit2d examples/animation.py --quality --qc-video output/animation.mp4 --output output/qc.json
|
|
28
|
+
python -m unittest discover -s tests -v
|
|
29
|
+
python -m build --wheel --no-isolation
|
|
30
|
+
python tools/package_release.py
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`--quality`: exit 0 PASS, 1 FAIL, 2 INCOMPLETE. Findings và coverage là dữ liệu nghiệm
|
|
34
|
+
thu kỹ thuật; cảnh đen/cut có chủ ý vẫn có thể bị heuristic báo lỗi. Chưa có bounds
|
|
35
|
+
hoặc graph không thể kiểm thì không đánh PASS cho kiểm đó. QC không thay creative review.
|
|
36
|
+
|
|
37
|
+
## Spatial / choreography
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from motionkit2d import Rect, MotionPath, find_path, Character
|
|
41
|
+
region = Rect(0, 0, 400, 300)
|
|
42
|
+
points = find_path((0, 0), (400, 300), region, [Rect(190, 0, 20, 200)], cell=10)
|
|
43
|
+
path = MotionPath(points, speed=80)
|
|
44
|
+
actor = Character().move_to(path).perform(body='walk')
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Navigation là A* bốn hướng, endpoint trên grid, obstacle đóng và có clearance.
|
|
48
|
+
Không tự gọi pathfinding khi move_to; caller quyết định vùng và footprint.
|
|
49
|
+
`align`/`contain` trả Transform, không âm thầm sửa node; `collisions(graph,t)` trả
|
|
50
|
+
cặp AABB giao nhau, kể cả quan hệ group/child; caller lọc collision layer theo nhu cầu.
|
|
51
|
+
|
|
52
|
+
## Animation / particles / physics
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from motionkit2d import Ballistic, Emitter, spring, morph_polygon
|
|
56
|
+
point = Ballistic((100, 20), (60, -30), (0, 180))(.5)
|
|
57
|
+
ground_point = Ballistic((0, 0), (30, 0)).bounce(1, floor_y=180, restitution=.6)
|
|
58
|
+
value = spring(.4, initial=0, target=1, damping=.5)
|
|
59
|
+
polygon = morph_polygon(((0,0),(40,0),(20,40)), ((0,0),(80,0),(40,80)), .5)
|
|
60
|
+
hearts = Emitter(position=lambda t: (100+20*t, 80), rate=20, lifetime=1,
|
|
61
|
+
burst=5, shape='heart', seed=8, stop=2)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Morph nội suy **tọa độ vertex**, không gọi crossfade là morph. Hai polygon cần
|
|
65
|
+
số vertex tương ứng; caller chịu trách nhiệm winding/correspondence. Emitter đặt
|
|
66
|
+
position tại thời điểm sinh nên có thể tạo trail. Burst và floating hearts dùng
|
|
67
|
+
cùng cơ chế seed. Ground collision là mô hình đơn giản, không phải rigid-body world.
|
|
68
|
+
|
|
69
|
+
Hiệu ứng wave/glow/reveal/color_grade được đăng ký chung `effects_registry`;
|
|
70
|
+
parameters nhận từ JSON như các effect v0.4. Lighting ở mức raster effect và metadata.
|
|
71
|
+
|
|
72
|
+
## Audio / TTS
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from motionkit2d import AudioCue, mix_audio, loudness, normalize_audio, BeatTrack
|
|
76
|
+
mix_audio([AudioCue('voice.wav', kind='voice'),
|
|
77
|
+
AudioCue('bgm.wav', kind='bgm', volume=.3, loop=True, ducking=.2)],
|
|
78
|
+
'mix.wav', seconds=10)
|
|
79
|
+
normalize_audio('mix.wav', 'master.wav', target_lufs=-16, true_peak=-1)
|
|
80
|
+
measurements = loudness('master.wav')
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Loudness dùng FFmpeg loudnorm hai lượt, không tự gán RMS thành LUFS. Silence trả
|
|
84
|
+
measurement None và normalize báo lỗi. TTS: `SpeechSynthesizer(provider)` gọi
|
|
85
|
+
`provider(text, temporary_wav_path, **options)`. Provider phải ghi PCM WAV hợp lệ;
|
|
86
|
+
engine kiểm trước khi publish atomic. Core không tự chọn giọng, gọi mạng hay lấy key.
|
|
87
|
+
BeatTrack dùng time của BeatMap làm keyframe. Onset/BPM estimator vẫn là heuristic;
|
|
88
|
+
chưa có speech recognition/forced alignment. Karaoke mặc định chia thời gian hold.
|
|
89
|
+
|
|
90
|
+
## Manifest và preset
|
|
91
|
+
|
|
92
|
+
`includes: ["scene_a.json", ...]` ghép scenes/audio theo thứ tự, resolve audio path
|
|
93
|
+
theo từng file. `preset_files` chứa node-config maps. Preset trùng bị reject;
|
|
94
|
+
video settings của file ngoài cùng override settings của include. Mỗi include phải
|
|
95
|
+
khai báo schema_version 1, cycle và depth >32 bị reject. Dữ liệu không import code.
|
|
96
|
+
`preflight` kiểm node/camera/property mỗi frame và audio source; không thay render test.
|
|
97
|
+
|
|
98
|
+
PresetLibrary vẫn đọc được catalog project với explicit adapters. 41 preset NEON
|
|
99
|
+
là dữ liệu thiết kế riêng; schema của chúng không chứa đủ transform/choreography
|
|
100
|
+
để engine tự dựng mọi tập. Không nhúng concept kênh vào engine, không công bố 41/41
|
|
101
|
+
đã render. Đó là integration ở tầng project, không phải public engine API.
|
|
102
|
+
|
|
103
|
+
## Drawing, timeline and rig details
|
|
104
|
+
|
|
105
|
+
Import các kiểu dữ liệu từ `motionkit2d`. Các hàm vẽ nằm ở `draw`, đạo cụ ở `assets`, hiệu ứng ở `effects`, preset cảnh ở `presets`.
|
|
106
|
+
|
|
107
|
+
### GPU và hardware encode
|
|
108
|
+
|
|
109
|
+
- `Scene(..., gpu_paint=None)`: callback tùy chọn nhận GPUCanvas cùng Frame. `paint`
|
|
110
|
+
vẫn bắt buộc, dùng làm fallback CPU và preview/storyboard. Chỉ callback GPU mới
|
|
111
|
+
nhận canvas GPU; code Pillow tùy ý trong callback CPU giữ nguyên.
|
|
112
|
+
- `render(video,path,crf=18,audio=None,progress=None,backend='auto',encoder='auto',
|
|
113
|
+
speed='balanced',workers=1,project_path=None,report=None)`: encoder và backend
|
|
114
|
+
độc lập. `backend`: auto/cpu/gpu; `encoder`: auto/cpu/nvenc/qsv/amf; `speed`:
|
|
115
|
+
fast/balanced/quality. `workers`: số nguyên dương hoặc auto, cần project_path
|
|
116
|
+
nếu dùng nhiều process. `report` là dict nhận backend/thiết bị/encoder/timing.
|
|
117
|
+
- `gpu_info()`: tạo context để trả `{available,vendor,renderer,version}` hoặc reason.
|
|
118
|
+
- `GPUCanvas`: tạo qua renderer hoặc `canvas.layer()`, không khởi tạo rời device.
|
|
119
|
+
- CLI: `--devices`, `--backend`, `--encoder`, `--speed`, `--workers`.
|
|
120
|
+
- `Video.frame`, `save_frame`, `storyboard`, `frame_strip` vẫn dùng painter CPU.
|
|
121
|
+
- `auto` fallback khi khởi tạo không dùng được; callback lỗi hoặc encode đang chạy
|
|
122
|
+
bị lỗi sẽ được báo, giữ nguyên file đích cũ. Không tự retry toàn video.
|
|
123
|
+
|
|
124
|
+
Chi tiết callback, primitive hỗ trợ, chọn thiết bị, probe resize và giới hạn:
|
|
125
|
+
[GPU guide](gpu.md). GPU extra: `pip install ".[gpu]"`. Import/API CPU vẫn dùng được
|
|
126
|
+
khi không cài ModernGL. Font rasterization và một số asset vẫn dùng CPU; không
|
|
127
|
+
khẳng định toàn bộ project cũ trở thành GPU.
|
|
128
|
+
|
|
129
|
+
### Timeline
|
|
130
|
+
|
|
131
|
+
| API | Cách dùng |
|
|
132
|
+
| --- | --- |
|
|
133
|
+
| `Video(scenes, width=1024, height=576, fps=30, background="#07090B", audio=())` | Khai báo chuỗi cảnh. Kích thước đầu ra chẵn. `audio` là dãy AudioCue. |
|
|
134
|
+
| `Scene(name, seconds, paint, transition=None, still=None)` | `paint(im, f)` vẽ vào ảnh RGB. `still` tính theo giây trong cảnh và dùng cho storyboard. |
|
|
135
|
+
| `Frame` | `f.t` là giây trong cảnh, `f.time` là giây toàn video, `f.progress` chạy 0–1. `f.index` là frame toàn video, `f.local_index` là frame trong cảnh. Còn có `fps`, `width`, `height`, `scene_frames`. |
|
|
136
|
+
| `Transition(kind="crossfade", seconds=.35, ease="smooth", color="#000000", mode="freeze")` | Gắn ở cảnh tiếp theo. Hỗ trợ `crossfade`, `dip`, `slide`, `wipe`, `iris`, `push`, `match_zoom`, `glitch` và custom registry; mode `freeze` hoặc `overlap`. |
|
|
137
|
+
| `layers(background, art, lettering)` | Ghép các hàm vẽ theo thứ tự từ dưới lên. |
|
|
138
|
+
| `video.frame(index)` / `video.stills()` | Ảnh RGB đúng kích thước xuất, hoặc cặp chỉ số frame và caption đại diện từng cảnh. |
|
|
139
|
+
|
|
140
|
+
Mỗi cảnh được làm tròn sang số frame gần nhất. Chuyển cảnh dùng đoạn đầu của cảnh nhận, với hình cuối của cảnh trước giữ nguyên trong lúc trộn. Cách này giữ tổng thời lượng theo tổng các cảnh đã làm tròn. Muốn phong cách phim cắt cảnh tức thời thì bỏ tham số `transition`. Một preset chỉ là hàm vẽ và có thể xếp cùng bất kỳ lớp nào.
|
|
141
|
+
|
|
142
|
+
### Nền và đạo cụ
|
|
143
|
+
|
|
144
|
+
| API | Cách dùng |
|
|
145
|
+
| --- | --- |
|
|
146
|
+
| `draw.stage(im, t, theme="green", floor=None, seed=541, dust=60, focus=(.5,.5))` | Nền và hạt bụi. Theme có `green`, `warm`, `plum`, `blue`. `floor` là tọa độ y tùy chọn. `focus` là tỷ lệ tâm sáng theo ngang và dọc. |
|
|
147
|
+
| `draw.gradient(im, edge, center, focus=(.5,.5))` / `draw.particles(im, t, seed=541, count=60, color=..., opacity=.8)` | Tự chọn màu nền và lớp hạt. |
|
|
148
|
+
| `presets.stage_painter(...)` / `presets.spotlight_painter(x=None, y=64, floor=None, spread=1, pole=180, fade=.55)` | Trả hàm vẽ sân khấu hoặc nền có cột đèn. |
|
|
149
|
+
| `presets.title_card(title, subtitle="", theme="plum", accent=..., title_size=None, subtitle_size=None)` | Trả hàm vẽ tiêu đề chính và phụ vào giữa cảnh. Với câu dài, đặt cỡ chữ hoặc xuống dòng bằng các lệnh chữ riêng. |
|
|
150
|
+
| `draw.lamp(im, amount=1, x=476, y=64, floor=512, pole=180, spread=1)` | Đèn sân khấu. `x,y` là bóng đèn. `pole` là khoảng cách cột sang trái. |
|
|
151
|
+
| `draw.person(im, x, y, s=1, kind="female", color=..., pose=False, has_heart=True, hair=True, light=0)` | Silhouette neo chân tại `x,y`. Dáng `female` cao khoảng 215 px ở scale 1, `male` khoảng 295 px. Đặt `pose=True` để đưa tay. `hair` và `has_heart` áp dụng cho dáng váy. |
|
|
152
|
+
| `draw.heart(im, x, y, s, c=..., cracked=False)` | Tim thường hoặc nứt, `s` là bề ngang gần đúng. |
|
|
153
|
+
| `draw.eye(im, x, y, scale=1, opening=1, green=0, opacity=1, reflection=False)` | Mắt cách điệu. `opening` và `green` chạy 0–1. `scale=1` cho mắt rộng khoảng 832 px. |
|
|
154
|
+
| `assets.Message(text, at=0, sent=False)` và `assets.phone_chat(t, messages, name="Tin nhắn", avatar=...)` | Tạo điện thoại chat. Liệt kê tin theo thứ tự. Tin tự xuống dòng, loại tin cũ khỏi màn hình khi hết chỗ. |
|
|
155
|
+
| `assets.phone_feed(time="04:51", header="Bảng tin", author="Bạn bè", caption="", reaction="", picture=None)` | Feed một bài đăng. `picture` nhận ảnh PIL. Mặc định dùng hình hoàng hôn vẽ bằng code. |
|
|
156
|
+
| `assets.place_phone(im, phone, x, y, tilt=0, amount=1, scale=1)` | Đặt điện thoại từ hai hàm trên, xoay theo độ. Lớp gốc rộng 296 px và cao 534 px gồm cả lề. |
|
|
157
|
+
| `assets.full_lemon(im, x, y, s)` / `assets.lemon_slice(im, x, y, rx, ry, phase=0)` | Quả nguyên hoặc một lát chanh. `phase` là radian. |
|
|
158
|
+
| `assets.balance(im, x, floor, scale=1, tilt=13)` | Vẽ cân và trả hai cặp `(x,y)` để đặt vật lên đĩa. `tilt` tính bằng độ. |
|
|
159
|
+
| `assets.capsule(im, x, y, w, h, value, fill=..., stroke=..., c=..., size=15)` | Nhãn ngắn, neo giữa tại `x,y`. |
|
|
160
|
+
|
|
161
|
+
Rắn dùng đường thân hướng từ đuôi tới đầu. Dựng đường bằng `assets.crawl(head, y, length, t, waves=3.7)`, `assets.coil(cx, bottom, top, rx, ry, turns, t)` hoặc `assets.orbit(cx, cy, rx, ry, start, span)`. Quỹ đạo riêng nhận `assets.snake_geometry(sample, count=221)`, trong đó `sample(u)` trả `(x,y,depth)` với u trong khoảng 0–1.
|
|
162
|
+
|
|
163
|
+
Vẽ bằng `assets.snake(im, path, width=9, progress=1, t=0, darkness=0)`. Dùng `progress` để hiện dần thân và `t` để chạy lưỡi. Khi rắn quấn quanh vật, gọi `assets.coil_at(im, path, paint_prop, width=9, progress=1, t=0)`. `paint_prop` là hàm không tham số, vẽ vật vào `im` giữa hai nửa thân rắn.
|
|
164
|
+
|
|
165
|
+
### Chữ và hiệu ứng
|
|
166
|
+
|
|
167
|
+
| API | Cách dùng |
|
|
168
|
+
| --- | --- |
|
|
169
|
+
| `draw.text(im, x, y, value, size=36, c=..., style="regular", align="center", amount=1, glow=False, tracking=0, focus=1)` | Một dòng. `value` là chuỗi hoặc dãy cặp `(text, color)`. `style` nhận `regular`, `bold`, `sans` hoặc đường dẫn font TTF. `align` nhận `left`, `center`, `right`. Khoảng cách dấu câu do nội dung quyết định. |
|
|
170
|
+
| `draw.say(im, t, start, x, y, value, size=36, duration=.32, ...)` | Chữ hiện và giảm blur trong `duration` giây. Dùng một lệnh cho mỗi dòng. |
|
|
171
|
+
| `tween(t, start, end, before=0, after=1, ease="smooth")` | Nội suy số, tọa độ tuple hoặc màu RGB. Nếu `start==end`, đổi giá trị ngay tại mốc. |
|
|
172
|
+
| `Track(Key(time, value, ease), ...)(t)` | Chuỗi keyframe. Dùng easing ở key đầu của mỗi đoạn. Có `linear`, `smooth`, `in`, `out`, `in_out`, `back`, `bounce`, `elastic`, `spring`. |
|
|
173
|
+
| `effects.layer(w, h)` / `effects.sprite(im, image, x, y, scale=1, rotation=0, opacity=1, anchor=(.5,.5))` | Lớp RGBA 2× và công cụ đặt lớp. `anchor` là điểm neo tương đối. Xoay dương ngược chiều kim đồng hồ. Ảnh ngoài nên được chuẩn bị ở 2× kích thước dự kiến. |
|
|
174
|
+
| `draw.halo(im, x, y, rx, ry, color, amount)` | Quầng sáng elliptical, `rx` và `ry` là bán kính. |
|
|
175
|
+
| `effects.ripple(im, x, y, t, start=0, duration=1, radii=(12,125), color=..., width=1.5, count=3, gap=.14, opacity=.6)` | Vòng sáng loang và tan theo thời gian. |
|
|
176
|
+
| `effects.wash(im, color, opacity)` | Trộn cả cảnh về một màu. Dùng với tween để fade cuối. |
|
|
177
|
+
| `draw.draw(im)`, `draw.oval`, `draw.rect`, `draw.line`, `draw.polygon`, `draw.cubic` | Primitive cho đạo cụ mới. Lấy đối tượng vẽ bằng `d = draw.draw(im)`, rồi gọi `draw.line(d, points, color, width=2)`. Giữ tọa độ thiết kế, thư viện nhân 2 khi vẽ. |
|
|
178
|
+
|
|
179
|
+
### Một lớp riêng có xoay, scale và fade
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
from motionkit2d import draw, effects, tween
|
|
183
|
+
|
|
184
|
+
def emblem(im, f):
|
|
185
|
+
art = effects.layer(144, 144)
|
|
186
|
+
draw.heart(art, 72, 72, 66)
|
|
187
|
+
k = tween(f.t, .1, .8, 0, 1, ease="out")
|
|
188
|
+
effects.sprite(im, art, f.width/2, f.height/2,
|
|
189
|
+
scale=.72+.28*k, rotation=-12*(1-k), opacity=k)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Xuất và kiểm tra
|
|
193
|
+
|
|
194
|
+
| API | Kết quả |
|
|
195
|
+
| --- | --- |
|
|
196
|
+
| `render(video, path, crf=18, audio=None, progress=None)` | MP4 H.264 yuv420p. Callback tiến độ nhận `(đã_xong, tổng)`. |
|
|
197
|
+
| `save_frame(video, index, path)` | Một PNG. |
|
|
198
|
+
| `storyboard(video, path, columns=3, tile_width=360)` | PNG gồm các frame gốc đại diện cho mỗi cảnh. |
|
|
199
|
+
| `verify(video, path, audio=False)` | Metadata đối chiếu với timeline và kết quả giải mã toàn bộ. |
|
|
200
|
+
|
|
201
|
+
### rig, appearance, actions và anchor
|
|
202
|
+
|
|
203
|
+
Import trực tiếp từ `motionkit2d`:
|
|
204
|
+
|
|
205
|
+
| API | Quy ước |
|
|
206
|
+
| --- | --- |
|
|
207
|
+
| `Appearance(skin=..., shirt=..., trousers=..., hair=..., hairstyle='short', torso=1, legs=1, head=1)` | Màu, kiểu tóc `short/long/none/curly/bangs/bun/ponytail`, tỉ lệ hình thể dương; các option outfit/accessories/view xem API guide. |
|
|
208
|
+
| `Pose(joints)` | Bản đồ điểm local. `pose.blend(other, amount)` nội suy mọi joint. |
|
|
209
|
+
| `stand(appearance=None)`, `walk(t, appearance=None, stride=22, period=.8)` | Pose thuần, lấy mẫu lại bất kỳ thời gian. |
|
|
210
|
+
| `reach(pose, point, side='right', bend=1)` | IK cánh tay hai đoạn 39 pixel; đích trong tầm 78 pixel tính từ vai. |
|
|
211
|
+
| `sit(appearance=None)` | Hạ hông 18 pixel, đầu gối ra trước, bàn chân vẫn trên sàn. |
|
|
212
|
+
| `pose_transition(t, start, end, before, after, ease='smooth')` | Giữ pose trước/sau ngoài khoảng; blend liên tục bên trong. |
|
|
213
|
+
| `Character(appearance=None, pose=None, transform=Transform())` | `pose` và `transform` nhận giá trị hoặc callable `(t)`. |
|
|
214
|
+
| `Transform(x=0,y=0,scale=1,rotation=0,flip=False)` | Local → scene: lật x, scale, xoay CCW, dịch. `point((x,y))`, `vector((x,y))`. |
|
|
215
|
+
| `entity.local_anchor(name,t)` / `entity.anchor(name,t)` | Điểm local sau pose / điểm trong scene sau toàn bộ transform. |
|
|
216
|
+
| `entity.world_transform(t)` / `entity.draw(im,t)` | Lấy transform / vẽ ở thời gian t. |
|
|
217
|
+
|
|
218
|
+
Rig có `head`, `hip`, `feet`, `shoulder_left/right`, `elbow_left/right`,
|
|
219
|
+
`hand_left/right`, `knee_left/right`, `foot_left/right`. Gốc của Character là
|
|
220
|
+
`feet=(0,0)` trên sàn; pose và ảnh dùng cùng tọa độ.
|
|
221
|
+
|
|
222
|
+
### Tạo nhân vật mới
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
from motionkit2d import Appearance, Character, Transform, walk
|
|
226
|
+
look = Appearance(shirt='#8D718E', trousers='#263A50', hairstyle='long', head=.95)
|
|
227
|
+
student = Character(look, pose=lambda t: walk(t, look),
|
|
228
|
+
transform=lambda t: Transform(100+40*t, 450, .9))
|
|
229
|
+
# Trong paint(im,f): student.draw(im,f.t)
|
|
230
|
+
hand_in_scene = student.anchor('hand_right', .5)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### School registry và đạo cụ riêng
|
|
234
|
+
|
|
235
|
+
`catalog.get(name)` trả `Asset`; `catalog.describe()` trả dữ liệu JSON-compatible
|
|
236
|
+
gồm package, kích thước gốc, anchors, defaults và usage. CLI: `python -m motionkit2d --catalog`.
|
|
237
|
+
`Registry()` tạo registry riêng; `catalog.register(asset)` mở rộng registry mặc định.
|
|
238
|
+
Không cho ghi đè tên đã có. Đơn vị size/anchor là design pixel local, gốc trên trái.
|
|
239
|
+
|
|
240
|
+
| Asset | Size | Anchors | Parameters |
|
|
241
|
+
| --- | --- | --- | --- |
|
|
242
|
+
| `school.chair` | 84×146 | seat=(42,68), feet=(42,146) | wood, metal |
|
|
243
|
+
| `school.backpack` | 50×76 | handle=(25,6), bottom=(25,73) | color, pocket |
|
|
244
|
+
| `school.board` | 360×140 | center=(180,70) | color, frame |
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
from motionkit2d import Asset, Prop, Transform, catalog, draw
|
|
248
|
+
def paint_book(im, color):
|
|
249
|
+
draw.rect(draw.draw(im), 0, 0, 42, 30, 3, color)
|
|
250
|
+
catalog.register(Asset('my_project.book', (42,30), {'grip':(4,15)},
|
|
251
|
+
paint_book, {'color':'#C77564'}, 'Sổ tay'))
|
|
252
|
+
book = Prop(catalog.get('my_project.book'), transform=Transform(230,320), color='#738C9E')
|
|
253
|
+
# book.draw(im,f.t); book.anchor('grip',f.t)
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Gắn và thả
|
|
257
|
+
|
|
258
|
+
```python
|
|
259
|
+
from motionkit2d import Attachment, Prop, Transform, catalog
|
|
260
|
+
bag = Attachment(Prop(catalog.get('school.backpack'), transform=Transform(scale=.65)),
|
|
261
|
+
'handle', student, 'hand_right', start=0, release=3.5)
|
|
262
|
+
# Vẽ bag.draw(im,f.t), tra bag.anchor('handle',f.t).
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Trong `[start, release)`, child anchor trùng target anchor; scale/rotation/flip
|
|
266
|
+
của child được hiểu tương đối với target. Translation của child không ảnh hưởng
|
|
267
|
+
trong lúc gắn. Trước start, child giữ transform độc lập. Từ release trở đi, giữ
|
|
268
|
+
nguyên transform tại chính thời điểm release, kể cả hướng và scale. `release=None`
|
|
269
|
+
giữ mãi. Không lưu trạng thái qua frame. Attachment có thể làm target cho attachment
|
|
270
|
+
khác nhưng người viết phải tránh vòng tham chiếu. Anchor local của prop là cố định.
|
|
271
|
+
|
|
272
|
+
Để đặt balô lên ghế, đưa bàn tay tới `seat - offset(handle→bottom)` rồi thả.
|
|
273
|
+
Xem phép tính và choreography thực tế trong `examples/classroom.py`.
|
|
274
|
+
|
|
275
|
+
### cue và audio đồng bộ
|
|
276
|
+
|
|
277
|
+
`Cues(**times)` giữ các mốc giây có tên; `cues['name']` và `cues.at('name', offset)`
|
|
278
|
+
trả giây. Đổi định nghĩa cue rồi tạo lại choreography để cập nhật các consumer.
|
|
279
|
+
Cue trong scene dùng thời gian local; AudioCue dùng thời gian toàn video. Với nhiều
|
|
280
|
+
scene, cộng `video.starts[slot]/fps` vào cue local để đặt audio.
|
|
281
|
+
|
|
282
|
+
```python
|
|
283
|
+
from motionkit2d import AudioCue, Cues, Scene, Video, tween
|
|
284
|
+
cues = Cues(release=3.5)
|
|
285
|
+
def paint(im, f):
|
|
286
|
+
# Cùng cue điều khiển kết thúc đưa tay và bắt đầu rút tay.
|
|
287
|
+
placement = tween(f.t, cues.at('release',-.7), cues['release'])
|
|
288
|
+
withdrawal = tween(f.t, cues['release'], cues.at('release',.6))
|
|
289
|
+
# Dùng placement/withdrawal để blend pose rồi vẽ.
|
|
290
|
+
VIDEO = Video([Scene('Cảnh', 6, paint)],
|
|
291
|
+
audio=[AudioCue('examples/release.wav', cues['release'], .55)])
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
`AudioCue(path,start=0,volume=1)` chấp nhận nhiều nguồn chồng nhau. Mỗi nguồn
|
|
295
|
+
được resample 48 kHz, gain riêng, delay theo sample, amix không normalize, pad/cắt
|
|
296
|
+
đúng thời lượng video, encode AAC. Không loop; clip dài bị cắt. `render(...,audio=path)`
|
|
297
|
+
và `--audio` thêm một nguồn ở giây 0, dùng được cùng `Video.audio`. Không tự hạn chế
|
|
298
|
+
tổng gain. Audio nén có thể có pre-echo rất nhỏ; test so RMS trong cửa sổ cách biên.
|
|
299
|
+
|
|
300
|
+
### overlap chuyển động và số frame
|
|
301
|
+
|
|
302
|
+
`Transition(..., mode='freeze')` là hành vi cũ mô tả phía trên: tổng `sum(N_i)`.
|
|
303
|
+
Với `mode='overlap'`, số frame chồng `M_i=round(seconds*fps)` được trừ khỏi tổng:
|
|
304
|
+
`N_total=sum(N_i)-sum(M_i của transition overlap)`. Các transition freeze không trừ.
|
|
305
|
+
Python `round` được áp dụng độc lập cho từng cảnh và transition.
|
|
306
|
+
|
|
307
|
+
Ví dụ hai cảnh 10 frame, overlap 4 frame: starts=(0,6), tổng 16 frame. Output
|
|
308
|
+
6..9 lấy cảnh trước local 6..9 và cảnh đến local 0..3. Hệ số blend `k/(M-1)`:
|
|
309
|
+
đầu đoạn là 0, cuối đoạn là 1, áp easing đã chọn. Frame 10 lấy cảnh đến local 4;
|
|
310
|
+
frame 15 là cảnh đến local 9. `Frame.index/time` của cả hai painter là thời gian
|
|
311
|
+
toàn video thực, `local_index/t` là riêng từng cảnh.
|
|
312
|
+
|
|
313
|
+
Mỗi overlap cần ít nhất 2 frame, phải vừa cả hai cảnh. Các vùng transition phải
|
|
314
|
+
không tạo chồng ba cảnh; cấu hình không hợp lệ báo ValueError. Test kiểm tra cả
|
|
315
|
+
crossfade, dip và slide. `stills()` vẫn chọn một frame cho mỗi Scene;
|
|
316
|
+
dùng `frame_strip` để xuất storyboard nhiều mốc trong cùng Scene.
|
|
317
|
+
|
|
318
|
+
### layout, text và dải frame
|
|
319
|
+
|
|
320
|
+
- `Layout(width,height,margin=.06)`: `canvas`, `safe` là Rect.
|
|
321
|
+
- `layout.anchor(u,v,safe=True)`: tọa độ tương đối trong safe rect hoặc canvas.
|
|
322
|
+
- `Rect(x,y,width,height).anchor(u,v)` và `.contains((x,y))`.
|
|
323
|
+
- `text_block(value,width,height,size=32,min_size=12,style='sans')` trả TextBlock:
|
|
324
|
+
`lines`, `size`, `line_height`, `width`, `height`. Đo bằng font render thực; NFC,
|
|
325
|
+
giữ newline, wrap theo từ; từ quá dài tách theo ký tự sau chuẩn hóa.
|
|
326
|
+
- Text overflow: giảm từng cỡ chữ tới min_size, vẫn không vừa thì ValueError.
|
|
327
|
+
`block.draw(im,x,y,color=...,style='sans')` neo góc trên trái; dùng cùng style
|
|
328
|
+
lúc đo và vẽ. Không hỗ trợ rich text trong TextBlock; `draw.text` vẫn có.
|
|
329
|
+
- `frame_strip(video,indices,path,columns=5,tile_width=240)` xuất PNG có caption.
|
|
330
|
+
CLI `--strip START:STOP` xuất các frame liên tiếp, STOP không bao gồm.
|
|
331
|
+
|
|
332
|
+
Mốc thả mặc định ở 3.5s × 24 fps = frame 84. Nếu cue không nằm đúng trên lưới
|
|
333
|
+
frame, transform đóng băng tại thời gian cue, frame quan sát đầu tiên sau thả là
|
|
334
|
+
`ceil(cue*fps)`. Dải nghiệm thu mặc định là frame 79..90 cho cả hai biến thể.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# MotionKit2D documentation
|
|
2
|
+
|
|
3
|
+
Tài liệu hiện tại áp dụng cho API 1.x. Mỗi chủ đề có một tài liệu chính;
|
|
4
|
+
lịch sử thay đổi nằm trong Git và các release tags.
|
|
5
|
+
|
|
6
|
+
- [Cài đặt và ví dụ](../README.md)
|
|
7
|
+
- [API contract và hướng dẫn](guide.md)
|
|
8
|
+
- [GPU rendering và encoding](gpu.md)
|
|
9
|
+
- [Phạm vi kiểm thử và bằng chứng](verification.md)
|
|
10
|
+
- [Publish và provenance](publishing.md)
|
|
11
|
+
|
|
12
|
+
Kế hoạch và báo cáo phiên bản cũ nằm trong
|
|
13
|
+
[tag lịch sử](https://github.com/dangminhtai/motionkit2d/tree/v1.0.1).
|
|
14
|
+
Bằng chứng đã công bố vẫn được giữ trong verification/.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Publishing và provenance
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
attestation
|
|
3
|
+
Workflow release dùng GitHub Actions OIDC và PyPI Trusted Publishing. Kiểm tra
|
|
4
|
+
attestation của từng file trên trang PyPI; SHA-256 và log local không thay thế
|
|
5
|
+
chứng thực danh tính publisher.
|
|
5
6
|
|
|
6
7
|
PyPI tiếp nhận attestation cùng lúc upload file. Luồng cho các bản tiếp:
|
|
7
8
|
|
|
@@ -14,8 +15,8 @@ PyPI tiếp nhận attestation cùng lúc upload file. Luồng cho các bản ti
|
|
|
14
15
|
|
|
15
16
|
Repository: https://github.com/dangminhtai/motionkit2d
|
|
16
17
|
|
|
17
|
-
Workflow: `.github/workflows/publish.yml`. Tag
|
|
18
|
-
|
|
18
|
+
Workflow: `.github/workflows/publish.yml`. Tag `vX.Y.Z` phải khớp package version
|
|
19
|
+
`X.Y.Z`; job build kiểm sdist/wheel, chạy tests bằng wheel đã cài, lưu log/report
|
|
19
20
|
trong artifact `verification`. Chỉ job publish có quyền `id-token: write`; không
|
|
20
21
|
truyền PIPI_APIKEY vào CI. GitHub environment là `pypi`.
|
|
21
22
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Verification
|
|
2
|
+
|
|
3
|
+
The repository keeps one current set of evidence:
|
|
4
|
+
|
|
5
|
+
- [Test log](../verification/tests.txt): installed-library unittest results.
|
|
6
|
+
- [Acceptance report](../verification/report.json): package version, test count,
|
|
7
|
+
preflight, full media decode, QC findings and evidence checksums.
|
|
8
|
+
- [Benchmark](../verification/benchmark.json): measurements and the environment
|
|
9
|
+
in which they were recorded; frame timings exclude video encoding.
|
|
10
|
+
|
|
11
|
+
Regenerate with the installed package, without PYTHONPATH=src:
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
python tools/acceptance.py
|
|
15
|
+
python tools/benchmark.py --output output/benchmark.json
|
|
16
|
+
# Optional longer classroom/media checks:
|
|
17
|
+
python tools/acceptance.py --extended
|
|
18
|
+
# Optional complete backend/encoder comparisons:
|
|
19
|
+
python tools/benchmark.py --mode export
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The default acceptance runs the full unittest suite, renders the animation demo,
|
|
23
|
+
checks full decode and QC, and validates the JSON example. The extended mode
|
|
24
|
+
also renders the classroom demos and checks the release sound waveform.
|
|
25
|
+
Reports are written to output/ by default. Reviewed results replace the files in
|
|
26
|
+
verification/; old results remain in Git history, not numbered directories.
|
|
27
|
+
|
|
28
|
+
Test source hashes use UTF-8/LF text so that Windows and Linux checkouts agree.
|
|
29
|
+
Evidence file hashes cover the exact bytes of tests.txt and benchmark.json.
|
|
30
|
+
|
|
31
|
+
These local records are not CI attestations or proof of artistic quality. See
|
|
32
|
+
[publishing](publishing.md) for publisher identity and the public CI workflow.
|
|
33
|
+
GPU results apply only to the hardware recorded in the report. Real TTS-provider
|
|
34
|
+
speech, GUI playback and all project-specific presets are not covered.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
Run from the repository root after installing the package.
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
python -m motionkit2d examples/animation.py --backend cpu --encoder cpu
|
|
7
|
+
python -m motionkit2d examples/director.py --storyboard
|
|
8
|
+
python -m motionkit2d examples/episode.json --validate
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The classroom demos (`vao_lop.py`, `vao_lop_doc.py`) use a generated WAV fixture.
|
|
12
|
+
Create it before rendering these examples:
|
|
13
|
+
|
|
14
|
+
```shell
|
|
15
|
+
python examples/make_demo_audio.py
|
|
16
|
+
python -m motionkit2d examples/vao_lop.py --backend cpu --encoder cpu
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The generated `release.wav` is ignored by Git. Tests generate their own audio
|
|
20
|
+
fixtures and do not require this file. Render outputs belong in `output/`.
|