egatari 0.6.6 → 0.6.7-rc.1
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.
- package/NOTICE +6 -0
- package/README.ja.md +3 -3
- package/README.md +3 -3
- package/bin/egatari.mjs +2 -2
- package/components.lock.json +33 -15
- package/components2.lock.json +409 -1
- package/kit/build.mjs +28 -4
- package/kit/check-messages.mjs +14 -0
- package/kit/check.mjs +21 -0
- package/kit/core/build-core.mjs +84 -19
- package/kit/core/colab-core.mjs +3 -1
- package/kit/core/fill-measure.mjs +79 -0
- package/kit/core/font-coverage.mjs +52 -0
- package/kit/core/font-subset-core.mjs +101 -0
- package/kit/core/llm-fix.mjs +3 -2
- package/kit/core/llm-pack-data.mjs +39 -41
- package/kit/core/parts2.mjs +34 -0
- package/kit/core/portable.mjs +30 -2
- package/kit/core/scorm.mjs +109 -0
- package/kit/core/tier-a.mjs +72 -26
- package/kit/core/zip-write.mjs +57 -0
- package/kit/deck.js +118 -29
- package/kit/fill-scan.mjs +95 -0
- package/kit/font-subset.mjs +33 -0
- package/kit/instruction-version.json +1 -1
- package/kit/live.js +3 -1
- package/kit/llm-pack.mjs +15 -14
- package/kit/panes.js +26 -14
- package/kit/player.json +1 -1
- package/kit/player.lock.json +2 -2
- package/kit/tools.js +20 -23
- package/kit/track.js +11 -5
- package/package.json +4 -2
- package/render/audio-track.mjs +112 -0
- package/render/render.mjs +99 -51
- package/tools/video.mjs +17 -9
- package/vendor/components/CATALOG.md +2 -2
- package/vendor/components/sha256/0787c5bbf2e61801398aeefc39a3674b1fc0e556173c450b85cafa4201cb44a6/README.en.md +40 -0
- package/vendor/components/sha256/0787c5bbf2e61801398aeefc39a3674b1fc0e556173c450b85cafa4201cb44a6/index.js +348 -0
- package/vendor/components/sha256/0cab77d128c5f304c2d2ba32841b0bc5adc54b4e72f6681e0a0dda68c96b5d7e/README.en.md +32 -0
- package/vendor/components/sha256/0cab77d128c5f304c2d2ba32841b0bc5adc54b4e72f6681e0a0dda68c96b5d7e/index.js +222 -0
- package/vendor/components/sha256/25eab59287c5c52f9d2f8a7cee3d61ed513cc1c9ca846bba96b45cd59b39f822/README.en.md +42 -0
- package/vendor/components/sha256/25eab59287c5c52f9d2f8a7cee3d61ed513cc1c9ca846bba96b45cd59b39f822/index.js +481 -0
- package/vendor/components/sha256/28238c4fa50a377b96ce8a130ce5bdbf7bfc0536ed9c331499ea22377c43adb6/README.en.md +39 -0
- package/vendor/components/sha256/28238c4fa50a377b96ce8a130ce5bdbf7bfc0536ed9c331499ea22377c43adb6/index.js +323 -0
- package/vendor/components/sha256/2f1c797ecd028d04ce12b3d55d8ef9d5a4180d564aa99afb492d0bfc9cd39c94/README.en.md +42 -0
- package/vendor/components/sha256/2f1c797ecd028d04ce12b3d55d8ef9d5a4180d564aa99afb492d0bfc9cd39c94/index.js +267 -0
- package/vendor/components/sha256/389ab61c0dafed88074c0c459ed40b6738bec05ebf6e4566bba1394405f2392e/README.en.md +52 -0
- package/vendor/components/sha256/389ab61c0dafed88074c0c459ed40b6738bec05ebf6e4566bba1394405f2392e/index.js +219 -0
- package/vendor/components/sha256/3df7d0ec0c3ed4a6b06fbe3befec78b65a2202e5571580d8b28700a14b7b4321/README.en.md +66 -0
- package/vendor/components/sha256/3df7d0ec0c3ed4a6b06fbe3befec78b65a2202e5571580d8b28700a14b7b4321/index.js +920 -0
- package/vendor/components/sha256/40571cbc11cd649c447da73ede0f89937da344b05d4386abeb4afeecedfe7d3e/README.en.md +32 -0
- package/vendor/components/sha256/40571cbc11cd649c447da73ede0f89937da344b05d4386abeb4afeecedfe7d3e/index.js +352 -0
- package/vendor/components/sha256/4dd7e6a02f4128e90d4e2a86cccd9bf267a02cebcff1cdf36e0aaff8848af66e/README.en.md +31 -0
- package/vendor/components/sha256/4dd7e6a02f4128e90d4e2a86cccd9bf267a02cebcff1cdf36e0aaff8848af66e/index.js +232 -0
- package/vendor/components/sha256/520606a746b0d38fdc1aa380e665a1b95eead2487b11f389d2ebac4abe8f07cb/README.en.md +48 -0
- package/vendor/components/sha256/520606a746b0d38fdc1aa380e665a1b95eead2487b11f389d2ebac4abe8f07cb/index.js +384 -0
- package/vendor/components/sha256/554ed56e1ec963627be86ba1f573099ff57cf4cb22e8e10ce00e2128e30d39e2/README.en.md +42 -0
- package/vendor/components/sha256/554ed56e1ec963627be86ba1f573099ff57cf4cb22e8e10ce00e2128e30d39e2/index.js +481 -0
- package/vendor/components/sha256/782ae2154247b00451fc30aa140bf386d3a7a56ac4ad9ee04916f4bd1d29dda0/README.en.md +37 -0
- package/vendor/components/sha256/782ae2154247b00451fc30aa140bf386d3a7a56ac4ad9ee04916f4bd1d29dda0/index.js +424 -0
- package/vendor/components/sha256/808f748e76833742bb12a80482b37cb3dedaf3dcd592ee477d611cb40e95b094/README.en.md +44 -0
- package/vendor/components/sha256/808f748e76833742bb12a80482b37cb3dedaf3dcd592ee477d611cb40e95b094/index.js +304 -0
- package/vendor/components/sha256/8c3d7e9921f249cf45ce26d5a449f2b01fef683f500afed69d0b189312c4464e/index.js +904 -0
- package/vendor/components/sha256/96ad8eaf0ea7c23a31b72657964f23a02165765845991cafc41ee2835b97e40f/README.en.md +42 -0
- package/vendor/components/sha256/96ad8eaf0ea7c23a31b72657964f23a02165765845991cafc41ee2835b97e40f/index.js +170 -0
- package/vendor/components/sha256/b86c0e95622ff3be5fb0b208672ebca5018c34fd192e1b431cfd0fe912df2a7f/index.js +916 -0
- package/vendor/components/sha256/bec04685638f8fc1217c380d361fd9a425ffeade0291a4f2b2d4e41a5628e0ef/index.js +809 -0
- package/vendor/components/sha256/c3d3d56101f430f3468a8f281055c3ea5093fc5c77a35f14fabeb85ad363e209/README.en.md +37 -0
- package/vendor/components/sha256/c3d3d56101f430f3468a8f281055c3ea5093fc5c77a35f14fabeb85ad363e209/index.js +424 -0
- package/vendor/components/sha256/e1a0240f83e1925ee59ef2752662e2b0ec27f69251c012f8bab682aadcd8695f/README.en.md +34 -0
- package/vendor/components/sha256/e1a0240f83e1925ee59ef2752662e2b0ec27f69251c012f8bab682aadcd8695f/index.js +244 -0
- package/vendor/components/sha256/e2181655ed2050668133e08eb14b5683cda48d6af8d76fd7b551c58798c95287/README.en.md +50 -0
- package/vendor/components/sha256/e2181655ed2050668133e08eb14b5683cda48d6af8d76fd7b551c58798c95287/index.js +171 -0
- package/vendor/components/sha256/ef9c8c77ddf2b3953376a2db700c1277f550ea2606eab11cd8e18056dcba84c1/README.en.md +35 -0
- package/vendor/components/sha256/ef9c8c77ddf2b3953376a2db700c1277f550ea2606eab11cd8e18056dcba84c1/index.js +179 -0
- package/vendor/components/sha256/f3d5b6ce53f40c5f355a67538ff11b9cd28297da6292125ccb6e055aeddef906/README.en.md +51 -0
- package/vendor/components/sha256/f3d5b6ce53f40c5f355a67538ff11b9cd28297da6292125ccb6e055aeddef906/index.js +228 -0
- package/vendor/components-2/manifest-2.4.3.json +1962 -0
- package/vendor/components-2/manifest-2.4.4.json +1911 -0
- package/vendor/components-2/manifest-2.5.0.json +1911 -0
package/kit/player.json
CHANGED
package/kit/player.lock.json
CHANGED
package/kit/tools.js
CHANGED
|
@@ -168,10 +168,10 @@ css(
|
|
|
168
168
|
"#dt-cb svg{width:15px;height:15px;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round;flex:none}" +
|
|
169
169
|
"#dt-cb kbd{font:600 9px/1 ui-monospace,SFMono-Regular,Menlo,monospace;opacity:.55;letter-spacing:.02em}#dt-cb button.on kbd{opacity:.7}" +
|
|
170
170
|
"#dt-cb .sep{width:1px;height:18px;background:rgba(255,255,255,.18);margin:0 5px}" +
|
|
171
|
-
//
|
|
171
|
+
// 再生速度:字で今の速さを見せる
|
|
172
172
|
"#dt-cb button[data-b=rate]{width:auto;min-width:40px;padding:0 4px;font:600 12px/1 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;font-variant-numeric:tabular-nums}" +
|
|
173
|
-
//
|
|
174
|
-
"#dt-cb.dt-edit [data-b=auto],#dt-cb.dt-edit [data-b=laser],#dt-cb.dt-edit [data-b=vpen],#dt-cb.dt-edit [data-b=pen] .dt-dot,#dt-cb.dt-edit .dt-sw," +
|
|
173
|
+
// 編集モードの間は、発表の道具(再生・再生速度・レーザー・ペン・消えるペン・色・消す・一覧・全画面)のボタンを隠す
|
|
174
|
+
"#dt-cb.dt-edit [data-b=auto],#dt-cb.dt-edit [data-b=rate],#dt-cb.dt-edit [data-b=laser],#dt-cb.dt-edit [data-b=vpen],#dt-cb.dt-edit [data-b=pen] .dt-dot,#dt-cb.dt-edit .dt-sw," +
|
|
175
175
|
"#dt-cb.dt-edit [data-b=clear],#dt-cb.dt-edit [data-b=over],#dt-cb.dt-edit [data-b=full],#dt-cb.dt-edit .dt-tsep{display:none!important}" +
|
|
176
176
|
// 合成した声の札(format spec §7.3):帯と一緒に出て、一緒に隠れる
|
|
177
177
|
// 読み上げ中の札(format spec §5.6:端末の声で読んでいることを示す)。読んでいる間だけ出る。印刷には出さない
|
|
@@ -677,7 +677,8 @@ function closeOverview(){ if (ov){ var back = ov.back; ov.box.remove(); ov = nul
|
|
|
677
677
|
function pick(i){
|
|
678
678
|
var same = i === ov.ci;
|
|
679
679
|
closeOverview();
|
|
680
|
-
|
|
680
|
+
// 一覧で選ぶのは跳ぶ:再生中なら再生を続ける(Player P1)
|
|
681
|
+
if (!same){ if (DECK.jump) DECK.jump(i, 0); else { DECK.autoplay(false); DECK.go(i, 0, false); } }
|
|
681
682
|
}
|
|
682
683
|
function cols(){ return getComputedStyle(ov.box.querySelector("#dt-grid")).gridTemplateColumns.split(" ").length; }
|
|
683
684
|
window.addEventListener("resize", fitOv);
|
|
@@ -700,10 +701,10 @@ var RA = (function(){
|
|
|
700
701
|
var RA_T = DECK.ja !== false
|
|
701
702
|
? {btn: "読み上げで聞く(音声ファイルにはなりません)", stop: "読み上げを止める", on: "読み上げ中", esc: "Esc で止める",
|
|
702
703
|
old: "読み方は反映されません(古いファイル)",
|
|
703
|
-
audio: "
|
|
704
|
+
audio: "このステップには音声があります(再生 a で流れます)", none: "このステップには台本がありません", voice: "この端末には、この言語の読み上げの声がありません"}
|
|
704
705
|
: {btn: "Listen with read-aloud (not saved as audio)", stop: "Stop read-aloud", on: "Reading aloud", esc: "Esc to stop",
|
|
705
706
|
old: "Pronunciations not applied (older file)",
|
|
706
|
-
audio: "This step has audio (
|
|
707
|
+
audio: "This step has audio (press Play or a)", none: "This step has no script", voice: "This device has no read-aloud voice for this language"};
|
|
707
708
|
function deckLang(){ return document.documentElement.lang || (DECK.ja !== false ? "ja" : "en"); }
|
|
708
709
|
function raTurns(key){
|
|
709
710
|
var p = key.lastIndexOf(":"), sk = key.slice(0, p), st = key.slice(p + 1);
|
|
@@ -771,22 +772,20 @@ if (RA){
|
|
|
771
772
|
function press(k, shift){ document.dispatchEvent(new KeyboardEvent("keydown", {key: k, shiftKey: !!shift, bubbles: true, cancelable: true})); }
|
|
772
773
|
var JA = DECK.ja !== false;
|
|
773
774
|
var TIP = JA
|
|
774
|
-
? {prev: "前へ", next: "次へ", auto: "
|
|
775
|
+
? {prev: "前へ", next: "次へ", auto: "再生", laser: "レーザーポインター", pen: "ペン", vpen: "消えるペン", clear: "書き込みを消す", over: "スライド一覧", view: "表示",
|
|
775
776
|
lect: "先のステップを薄く見せる", cap: "字幕", mute: "効果音を消す", read: "読み上げで聞く(音声ファイルにはなりません)", pres: "発表者ビュー", full: "全画面", help: "キーの一覧", ink: "マーカー"}
|
|
776
|
-
: {prev: "Previous", next: "Next", auto: "
|
|
777
|
+
: {prev: "Previous", next: "Next", auto: "Play", laser: "Laser pointer", pen: "Pen", vpen: "Fading pen", clear: "Clear ink", over: "Slide overview", view: "View",
|
|
777
778
|
lect: "Show later steps faintly", cap: "Captions", mute: "Mute sound effects", read: "Listen with read-aloud (not saved as audio)", pres: "Presenter view", full: "Fullscreen", help: "Keyboard shortcuts", ink: "Marker"};
|
|
778
|
-
//
|
|
779
|
-
|
|
779
|
+
// 再生(Player P1):前へ・再生 / 一時停止・次へ・再生速度。帯の前へ・次へは再生の状態を保つ(DECK.playStep。キーの ← → は発表者の送りで、再生を止める)。
|
|
780
|
+
// 発表者の道具(レーザー・ペン・消えるペン・発表者ビュー)も同じ帯に並べる
|
|
780
781
|
var PLAY = JA ? {play: "再生", pause: "一時停止", rate: "再生速度"} : {play: "Play", pause: "Pause", rate: "Playback speed"};
|
|
781
782
|
function rateNext(){ var R = DECK.RATES || [1], j = R.indexOf(DECK.rate()); DECK.rate(R[(j + 1) % R.length]); }
|
|
782
783
|
// [名前, 表示するキー, 押すキー(関数なら直接呼ぶ)]。null は区切り
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
["over", "o", "o"], ["view", "r", function(b){ DECK.panes.menu(b); }], ["lect", "l", "l"], ["cap", "s", "s"], ["read", "", function(){ raStart(); }], ["mute", "", function(){ DECK.muteSounds(!DECK.muteSounds()); }], ["full", "f", "f"], null, ["help", "?", "?"]]
|
|
786
|
-
: [["prev", "←", "ArrowLeft"], ["next", "→", "ArrowRight"], ["auto", "a", "a"], null,
|
|
784
|
+
function playStep(d){ if (DECK.playStep) DECK.playStep(d); else press(d < 0 ? "ArrowLeft" : "ArrowRight"); }
|
|
785
|
+
var BTNS = [["prev", "←", function(){ playStep(-1); }], ["auto", "a", "a"], ["next", "→", function(){ playStep(1); }], ["rate", "", rateNext], null,
|
|
787
786
|
["laser", "x", "x"], ["pen", "d", "d"], ["vpen", "v", "v"], ["clear", "⌫", function(){ clear(false); }], null,
|
|
788
787
|
["over", "o", "o"], ["view", "r", function(b){ DECK.panes.menu(b); }], ["lect", "l", "l"], ["cap", "s", "s"], ["read", "", function(){ raStart(); }], ["mute", "", function(){ DECK.muteSounds(!DECK.muteSounds()); }], ["pres", "p", "p"], ["full", "f", "f"], null, ["help", "?", "?"]];
|
|
789
|
-
|
|
788
|
+
TIP.auto = PLAY.play; TIP.rate = PLAY.rate;
|
|
790
789
|
// 押すと入/切が変わるボタン(aria-pressed を付ける)
|
|
791
790
|
var TOGGLES = ["auto", "laser", "pen", "vpen", "lect", "cap", "read", "mute", "full", "help"];
|
|
792
791
|
function canFull(){ return DECK.canFullscreen ? DECK.canFullscreen() : true; }
|
|
@@ -810,7 +809,7 @@ function buildBar(){
|
|
|
810
809
|
if (!b){ var s = document.createElement("i"); s.className = "sep" + (cb.querySelector('[data-b="clear"]') && !cb.querySelector(".dt-tsep") ? " dt-tsep" : ""); s.setAttribute("aria-hidden", "true"); cb.appendChild(s); return; }
|
|
811
810
|
if (b[0] === "read" && !RA) return; // 読み上げ:端末で読めないとき・読めるステップがないときは出さない
|
|
812
811
|
if (b[0] === "mute" && !(DECK.hasComponentSounds && DECK.hasComponentSounds())) return;
|
|
813
|
-
if (b[0] === "view" && !DECK.panes) return; // 表示(並べ方。kit/panes.js):動画・発表者ビューの中の画面にはない
|
|
812
|
+
if (b[0] === "view" && !(DECK.panes && (!DECK.panes.offered || DECK.panes.offered().length > 1))) return; // 表示(並べ方。kit/panes.js):動画・発表者ビューの中の画面にはない
|
|
814
813
|
if (b[0] === "full" && !canFull()) return; // 全画面:要素の全画面がない所(iPhone の Safari・全画面を許さない枠の中)では出さない(deck.js)
|
|
815
814
|
var e = document.createElement("button"); e.type = "button";
|
|
816
815
|
e.setAttribute("data-b", b[0]);
|
|
@@ -1008,8 +1007,8 @@ function syncBar(){
|
|
|
1008
1007
|
var playing = document.documentElement.classList.contains("autoplay"), a = on("auto", playing);
|
|
1009
1008
|
if (a && a._p !== playing){
|
|
1010
1009
|
a._p = playing;
|
|
1011
|
-
var stopName =
|
|
1012
|
-
a.innerHTML = (playing ?
|
|
1010
|
+
var stopName = PLAY.pause;
|
|
1011
|
+
a.innerHTML = (playing ? ICON.pause : ICON.play) + "<kbd>a</kbd>";
|
|
1013
1012
|
a.title = (playing ? stopName : TIP.auto) + kk("a");
|
|
1014
1013
|
a.setAttribute("aria-label", playing ? stopName : TIP.auto);
|
|
1015
1014
|
}
|
|
@@ -1035,12 +1034,11 @@ function helpHtml(){
|
|
|
1035
1034
|
row(K("Shift") + "+" + K("←", "→"), j ? "スライド単位" : "By slide"), row(K("Home", "End"), j ? "最初 / 最後" : "First / last"),
|
|
1036
1035
|
row(K("12") + " " + K("Enter"), j ? "そのページへ" : "Go to slide"), row(K("o"), j ? "スライド一覧" : "Slide overview"),
|
|
1037
1036
|
row(K("Backspace") + " / " + K("Alt") + "+" + K("←"), j ? "リンクの前に戻る" : "Back (after a link)")]),
|
|
1038
|
-
sec(j ? "表示" : "View",
|
|
1039
|
-
row(K("a"), j ? "自動再生" : "Autoplay")]).concat(DECK.panes && !isDev() ? [row(K("r"), DECK.panes.order())] : []).concat([row(K("l"), j ? "先のステップを薄く見せる(l)" : "Show later steps faintly (l)"), row(K("s"), j ? "字幕" : "Captions"),
|
|
1037
|
+
sec(j ? "表示" : "View", [row(K("a"), PLAY.play + " / " + PLAY.pause), row(K("<") + " " + K(">"), PLAY.rate + (j ? "(遅く / 速く)" : " (slower / faster)"))].concat(DECK.panes && !isDev() && (!DECK.panes.offered || DECK.panes.offered().length > 1) ? [row(K("r"), DECK.panes.order())] : []).concat([row(K("l"), j ? "先のステップを薄く見せる(l)" : "Show later steps faintly (l)"), row(K("s"), j ? "字幕" : "Captions"),
|
|
1040
1038
|
row(K("Shift") + "+" + K("s"), j ? "字幕の大きさ(S / M / L)" : "Caption size (S / M / L)"),
|
|
1041
|
-
row(K("b"), j ? "黒い画面" : "Black screen")].concat(canFull() ? [row(K("f"), j ? "全画面" : "Fullscreen")] : []).concat(
|
|
1039
|
+
row(K("b"), j ? "黒い画面" : "Black screen")].concat(canFull() ? [row(K("f"), j ? "全画面" : "Fullscreen")] : []).concat([row(K("p"), j ? "発表者ビュー" : "Presenter view")]).concat([
|
|
1042
1040
|
row(K("?"), j ? "このキーの一覧" : "This help")]))),
|
|
1043
|
-
|
|
1041
|
+
sec(j ? "道具" : "Tools", [
|
|
1044
1042
|
row(K("x"), j ? "レーザーポインター" : "Laser pointer"), row(K("d"), j ? "ペン" : "Pen"), row(K("v"), j ? "消えるペン" : "Fading pen"),
|
|
1045
1043
|
row(K("Shift") + "+" + K("d"), j ? "ペンの色" : "Pen color"), row(K("Backspace"), j ? "ペンのとき:書き込みを消す(Shift で全部)" : "With a pen: clear ink (Shift: all slides)"),
|
|
1046
1044
|
row(K("Esc"), j ? "道具を解除" : "Exit tool")])
|
|
@@ -1160,7 +1158,6 @@ window.addEventListener("keydown", function(e){
|
|
|
1160
1158
|
else if (k === "?") toggleHelp();
|
|
1161
1159
|
else if (k === "Escape" && helpBox && helpBox.classList.contains("show")) toggleHelp(false);
|
|
1162
1160
|
else if (k === "o") openOverview();
|
|
1163
|
-
else if (LEARN && (k === "x" || k === "d" || k === "v" || k === "D")) done = false; // 自習:発表者の道具はない
|
|
1164
1161
|
else if (k === "x") toggle("laser");
|
|
1165
1162
|
else if (k === "d") toggle("pen");
|
|
1166
1163
|
else if (k === "v") toggle("vpen");
|
package/kit/track.js
CHANGED
|
@@ -129,11 +129,15 @@ function scormAdapter(api){
|
|
|
129
129
|
};
|
|
130
130
|
var get = function(k){ return call("LMSGetValue", k); };
|
|
131
131
|
var set = function(k, v){ if (!finished) call("LMSSetValue", k, v); };
|
|
132
|
-
|
|
132
|
+
// 保存のたびに、ここまでの時間(session_time)と出口(exit:終えていなければ suspend)も書く。閉じる間(pagehide)の保存は届かないことがある:
|
|
133
|
+
// ILIAS の SCORM 1.2 は同期の XHR で送り、Chrome・Safari はページを閉じる間の同期の XHR を止める。そのとき exit と時間が残らず、次は最初から・時間は 0 になる
|
|
134
|
+
var stamp = function(){ set("cmi.core.session_time", time()); set("cmi.core.exit", done ? "" : "suspend"); };
|
|
135
|
+
var commit = function(){ if (finished) return; clearTimeout(commitT); commitT = 0; commitAt = Date.now(); if (!review) stamp(); call("LMSCommit", ""); };
|
|
133
136
|
var later = function(){ if (commitT) return; commitT = setTimeout(commit, Math.max(0, commitAt + COMMIT_GAP - Date.now())); };
|
|
137
|
+
// CMITimespan(HHHH:MM:SS.SS)。百分の一秒の整数で数える(59.996 秒を "60.00" にしない)。9999 時間で止める
|
|
134
138
|
var time = function(){
|
|
135
|
-
var
|
|
136
|
-
return (
|
|
139
|
+
var cs = Math.min(Math.round((Date.now() - t0) / 10), 359999999), pad = function(x, k){ return ("000" + x).slice(-k); };
|
|
140
|
+
return pad(Math.floor(cs / 360000), 4) + ":" + pad(Math.floor(cs / 6000) % 60, 2) + ":" + pad(Math.floor(cs / 100) % 60, 2) + "." + pad(cs % 100, 2);
|
|
137
141
|
};
|
|
138
142
|
var a = {name: "scorm12", resumeAt: null,
|
|
139
143
|
init: function(){
|
|
@@ -155,10 +159,11 @@ function scormAdapter(api){
|
|
|
155
159
|
},
|
|
156
160
|
completed: function(){ if (review || lmsDone) return; lmsDone = true; set("cmi.core.lesson_status", "completed"); commit(); },
|
|
157
161
|
hidden: function(){ commit(); },
|
|
162
|
+
// beforeunload:pagehide より先に来る。ILIAS は Chrome でこの出来事の中なら sendBeacon で送る(basisAPI.js の useSendBeacon)。終えるのは pagehide のまま
|
|
163
|
+
leaving: function(){ commit(); },
|
|
158
164
|
end: function(){
|
|
159
165
|
if (finished) return;
|
|
160
|
-
|
|
161
|
-
set("cmi.core.exit", done ? "" : "suspend");
|
|
166
|
+
if (review) stamp(); // 見直し(review)では閉じるときだけ書く
|
|
162
167
|
commit(); call("LMSFinish", ""); finished = true;
|
|
163
168
|
},
|
|
164
169
|
finished: function(){ return finished; }
|
|
@@ -290,6 +295,7 @@ function init(){
|
|
|
290
295
|
if (document.visibilityState === "hidden"){ since.clear(); lastStageKey = null; adapter.hidden(); }
|
|
291
296
|
else { onStage(); schedule(); }
|
|
292
297
|
});
|
|
298
|
+
if (adapter.leaving) window.addEventListener("beforeunload", function(){ adapter.leaving(); });
|
|
293
299
|
window.addEventListener("pagehide", function(){ adapter.end(); });
|
|
294
300
|
window.addEventListener("pageshow", function(e){ if (e.persisted && adapter.finished && adapter.finished() && !document.getElementById("deck-track-notice")) notice(); });
|
|
295
301
|
onStage(); schedule();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "egatari",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7-rc.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://studio.egatari.org/",
|
|
6
6
|
"repository": {
|
|
@@ -91,10 +91,12 @@
|
|
|
91
91
|
"dependencies": {
|
|
92
92
|
"abcjs": "6.7.2",
|
|
93
93
|
"citeproc": "2.4.63",
|
|
94
|
+
"harfbuzzjs": "1.6.4",
|
|
94
95
|
"katex": "0.19.1",
|
|
95
96
|
"lame-wasm": "0.3.0",
|
|
96
97
|
"parse5": "8.0.1",
|
|
97
|
-
"playwright-core": "1.64.1"
|
|
98
|
+
"playwright-core": "1.64.1",
|
|
99
|
+
"wawoff2": "2.0.1"
|
|
98
100
|
},
|
|
99
101
|
"peerDependencies": {
|
|
100
102
|
"@egatari/fonts-extra": "^1.0.0"
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// 動画の音声を 1 本の続いた音にする(純粋な計算。ffmpeg もファイルも使わない。render.mjs が使う)
|
|
2
|
+
//
|
|
3
|
+
// 段階ごとの音声を、積み上げた時間(DECK.timeline() の start。コマに丸めない)の標本の位置にそのまま置く。
|
|
4
|
+
// クリップの音はこの 1 本から、コマの境目で切った続きの区間を取り出す。継ぎ目で標本がずれない・跳ばない・途切れない。
|
|
5
|
+
// trackLayout(tl, fps, sr) → {sr, starts(コマ), total(標本の数), frameSample(f), stepRange(n)}
|
|
6
|
+
// placeNarration(ch, pcm, from, to) → 置いた標本の数([from, to) より先は切る)
|
|
7
|
+
// narrationWindows(tl) → [[開始, 終わり](秒)]:台本の声が鳴る区間(背景の音楽を下げる)
|
|
8
|
+
// musicGain(windows, n, sr, opts) → Float32Array:背景の音楽の音量(声の下で下げ、終わりで消える。決まった式で毎回同じ)
|
|
9
|
+
// limitPeaks(channels, limit, sr) → 変えた標本があるか(先を読む上限。決まった式で毎回同じ)
|
|
10
|
+
import { frameStarts } from './sounds.mjs';
|
|
11
|
+
|
|
12
|
+
export const VIDEO_SR = 48000; // 動画の音声の標本化周波数(30・25・24・60 fps でコマあたりの標本が整数)
|
|
13
|
+
|
|
14
|
+
export function trackLayout(tl, fps, sr = VIDEO_SR) {
|
|
15
|
+
const starts = frameStarts(tl, fps);
|
|
16
|
+
const frameSample = (f) => Math.round((f * sr) / fps);
|
|
17
|
+
const at = (sec) => Math.round(+(sec * sr).toFixed(6));
|
|
18
|
+
return {
|
|
19
|
+
sr, starts, total: frameSample(starts.at(-1)), frameSample,
|
|
20
|
+
// 段階 n の正しい区間(標本)。次の段階の始まりで終わる(コマの丸めは入れない)
|
|
21
|
+
stepRange: (n) => [at(tl[n].start), n + 1 < tl.length ? at(tl[n + 1].start) : at(tl[n].start + tl[n].dur)],
|
|
22
|
+
at,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// pcm を ch[from …] に足す(to より先は捨てる)。足した数を返す
|
|
27
|
+
export function placeNarration(ch, pcm, from, to) {
|
|
28
|
+
const end = Math.min(to, ch.length, from + pcm.length);
|
|
29
|
+
for (let i = Math.max(0, from); i < end; i++) ch[i] += pcm[i - from];
|
|
30
|
+
return Math.max(0, end - Math.max(0, from));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 台本の声が鳴る区間(秒)。lead のあとから、音声の長さか段階の終わりの早いほうまで
|
|
34
|
+
export function narrationWindows(tl) {
|
|
35
|
+
const out = [];
|
|
36
|
+
for (const s of tl) {
|
|
37
|
+
if (!s.audio || !(s.audioDur > 0)) continue;
|
|
38
|
+
const a = s.start + (s.lead || 0), b = Math.min(a + s.audioDur, s.start + s.dur);
|
|
39
|
+
if (b > a) out.push([a, b]);
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 背景の音楽の音量(標本ごと)。base:声のないときの倍率、duck:声の間にさらに掛ける倍率、
|
|
45
|
+
// attack:声の前に下げ始める秒、release:声のあとに戻す秒、gap:これより短い声の切れ目では戻さない、fadeOut:終わりで消す秒
|
|
46
|
+
export const MUSIC = Object.freeze({ duckDb: -12, attack: 0.25, release: 0.6, gap: 0.8, fadeIn: 0.05, fadeOut: 3, targetRms: 0.05, maxGainDb: 12 });
|
|
47
|
+
export function musicGain(windows, n, sr, opts = {}) {
|
|
48
|
+
const o = { ...MUSIC, base: 1, ...opts };
|
|
49
|
+
const duck = 10 ** (o.duckDb / 20);
|
|
50
|
+
// 近い区間はつなぐ(短い間で音楽が上がり下がりしない)
|
|
51
|
+
const ws = [];
|
|
52
|
+
for (const [a, b] of [...windows].sort((x, y) => x[0] - y[0])) {
|
|
53
|
+
if (ws.length && a - ws.at(-1)[1] < o.gap) ws.at(-1)[1] = Math.max(ws.at(-1)[1], b);
|
|
54
|
+
else ws.push([a, b]);
|
|
55
|
+
}
|
|
56
|
+
const g = new Float32Array(n);
|
|
57
|
+
const T = n / sr, fo = Math.min(o.fadeOut, T / 3);
|
|
58
|
+
let w = 0;
|
|
59
|
+
for (let i = 0; i < n; i++) {
|
|
60
|
+
const t = i / sr;
|
|
61
|
+
while (w < ws.length && ws[w][1] + o.release < t) w++;
|
|
62
|
+
// 声に下げる量 d(0〜1):区間の中で 1、前の attack 秒と後の release 秒で直線
|
|
63
|
+
let d = 0;
|
|
64
|
+
for (let j = w; j < ws.length && ws[j][0] - o.attack <= t; j++) {
|
|
65
|
+
const [a, b] = ws[j];
|
|
66
|
+
const x = t < a ? 1 - (a - t) / o.attack : t <= b ? 1 : 1 - (t - b) / o.release;
|
|
67
|
+
if (x > d) d = x;
|
|
68
|
+
}
|
|
69
|
+
let v = o.base * (1 - d * (1 - duck));
|
|
70
|
+
if (o.fadeIn > 0 && t < o.fadeIn) v *= t / o.fadeIn;
|
|
71
|
+
if (fo > 0 && t > T - fo) v *= Math.max(0, (T - t) / fo);
|
|
72
|
+
g[i] = v;
|
|
73
|
+
}
|
|
74
|
+
return g;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 背景の音楽の基準の倍率:RMS を targetRms に(上げるのは maxGainDb まで)
|
|
78
|
+
export function musicBase(channels, o = MUSIC) {
|
|
79
|
+
let s = 0, n = 0;
|
|
80
|
+
for (const c of channels) { for (let i = 0; i < c.length; i++) s += c[i] * c[i]; n += c.length; }
|
|
81
|
+
const rms = n ? Math.sqrt(s / n) : 0;
|
|
82
|
+
return rms > 1e-6 ? Math.min(10 ** (o.maxGainDb / 20), o.targetRms / rms) : 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 上限を超える標本の前後 win だけ音量を下げる(先読みあり。どの標本も |x| ≤ limit になる)。
|
|
86
|
+
// 要る倍率 r[i] = min(1, limit/|x|) の ±win の最小を、幅 win の移動平均でならす:平均する範囲のどの最小も r[i] 以下なので、結果も r[i] 以下
|
|
87
|
+
export function limitPeaks(channels, limit = 0.98, sr = VIDEO_SR, ms = 5) {
|
|
88
|
+
const n = channels[0].length, win = Math.max(1, Math.round((sr * ms) / 1000));
|
|
89
|
+
let peak = 0;
|
|
90
|
+
for (const c of channels) for (let i = 0; i < n; i++) { const a = Math.abs(c[i]); if (a > peak) peak = a; }
|
|
91
|
+
if (peak <= limit) return false;
|
|
92
|
+
const r = new Float32Array(n).fill(1);
|
|
93
|
+
for (const c of channels) for (let i = 0; i < n; i++) { const a = Math.abs(c[i]); if (a > limit) r[i] = Math.min(r[i], limit / a); }
|
|
94
|
+
// ±win の最小(単調な待ち行列)
|
|
95
|
+
const m = new Float32Array(n), q = new Int32Array(n + 2 * win + 1);
|
|
96
|
+
let h = 0, tl = 0, j = 0;
|
|
97
|
+
for (let i = 0; i < n; i++) {
|
|
98
|
+
for (; j < n && j <= i + win; j++) { while (tl > h && r[q[tl - 1]] >= r[j]) tl--; q[tl++] = j; }
|
|
99
|
+
while (q[h] < i - win) h++;
|
|
100
|
+
m[i] = r[q[h]];
|
|
101
|
+
}
|
|
102
|
+
// 幅 win の移動平均(中央。端は 1 で埋める)
|
|
103
|
+
const half = Math.floor(win / 2), pre = new Float64Array(n + 1);
|
|
104
|
+
for (let i = 0; i < n; i++) pre[i + 1] = pre[i] + m[i];
|
|
105
|
+
for (let i = 0; i < n; i++) {
|
|
106
|
+
const a = i - half, b = i - half + win; // [a, b)
|
|
107
|
+
const sum = pre[Math.min(n, b)] - pre[Math.max(0, a)] + Math.max(0, -a) + Math.max(0, b - n);
|
|
108
|
+
const gi = Math.min(sum / win, r[i]);
|
|
109
|
+
for (const c of channels) c[i] *= gi;
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
package/render/render.mjs
CHANGED
|
@@ -4,9 +4,13 @@
|
|
|
4
4
|
//
|
|
5
5
|
// - 画面は DECK.seek(i, k, t) だけで描く(docs/contract.md §1)。仮想の時刻 t = f/fps でコマを撮る
|
|
6
6
|
// - 動きのある区間 [0, motion)(motion = max(anim, 注目の演出の終わり))だけを fps で撮り、残り(dur - anim)は最終状態(t = Infinity)の 1 枚を伸ばす
|
|
7
|
-
// -
|
|
8
|
-
//
|
|
9
|
-
// -
|
|
7
|
+
// - 音声は全体で 1 本(48 kHz):各段階の口述音声を、積み上げた時間(コマに丸めない)の標本の位置に、lead 秒のあとから置く
|
|
8
|
+
// (段階の終わりを超えたら切って警告)。継ぎ目で標本がずれず、跳ばない(render/audio-track.mjs)
|
|
9
|
+
// - 部品の音は作者の時刻で合成して同じ 1 本に混ぜる。段階をまたぐ余韻を残す(見る人の延長・ミュートは使わない)
|
|
10
|
+
// - --music <ファイル>:背景の音楽を 1 本、全体の下に流す(台本の声の間は下げ、終わりで消す。拍には合わせない。秒の設定はない)
|
|
11
|
+
// - クリップの音声は、その 1 本をコマの境目で切った続きの区間。full.mp4・章の mp4 の音声も、その 1 本から 1 回だけ AAC にする
|
|
12
|
+
// (クリップの AAC を繋いで作り直さない:先頭の 1024 標本の遅れと継ぎ目の隙間が出ない)
|
|
13
|
+
// - 出力:clip_NNNN.mp4(H.264 yuv420p・固定フレームレート・faststart、AAC 48 kHz)、clip_NNNN.png、
|
|
10
14
|
// timeline.out.json(各段階の開始・長さ・題名・章・原稿。字幕・チャプターの印に使える)
|
|
11
15
|
// - --full:全体を 1 本(full.mp4)に。章(timeline の chapter)が 2 つ以上あれば章ごとの mp4 も作る
|
|
12
16
|
// - キャッシュ(<out>/.render-cache.json):段階ごとの「入力」のハッシュ(スライドの HTML・部品のコード・テーマなど
|
|
@@ -22,15 +26,15 @@ import { spawnSync } from 'node:child_process';
|
|
|
22
26
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
23
27
|
import { launch } from '../kit/browser.mjs';
|
|
24
28
|
import { readRegular, READ_LIMITS } from '../kit/bounded-read.mjs';
|
|
25
|
-
import { encodeWav } from '../kit/core/wav-core.mjs';
|
|
26
29
|
import { resolveOnly, unknownOnlyMessage } from './only.mjs';
|
|
27
|
-
import { collectVideoEvents, videoSoundEvents, renderStepSounds
|
|
30
|
+
import { collectVideoEvents, videoSoundEvents, renderStepSounds } from './sounds.mjs';
|
|
31
|
+
import { VIDEO_SR, trackLayout, placeNarration, narrationWindows, musicGain, musicBase, limitPeaks } from './audio-track.mjs';
|
|
28
32
|
|
|
29
|
-
const RENDER_VERSION =
|
|
33
|
+
const RENDER_VERSION = 6; // 書き出しの方法を変えたら上げる(キャッシュを捨てる)
|
|
30
34
|
const CACHE_FILE = '.render-cache.json';
|
|
31
35
|
|
|
32
36
|
function parseArgs(argv) {
|
|
33
|
-
const o = { fps: 30, scale: 1.5, only: null, full: false, force: false, captions: false, out: null, src: null };
|
|
37
|
+
const o = { fps: 30, scale: 1.5, only: null, full: false, force: false, captions: false, music: null, out: null, src: null };
|
|
34
38
|
for (let i = 0; i < argv.length; i++) {
|
|
35
39
|
const a = argv[i];
|
|
36
40
|
if (a === '--out') o.out = argv[++i];
|
|
@@ -40,14 +44,16 @@ function parseArgs(argv) {
|
|
|
40
44
|
else if (a === '--full') o.full = true;
|
|
41
45
|
else if (a === '--force') o.force = true;
|
|
42
46
|
else if (a === '--captions') o.captions = true; // 口述原稿の字幕を映像に焼き込む
|
|
47
|
+
else if (a === '--music') o.music = argv[++i]; // 背景の音楽(任意)
|
|
43
48
|
else o.src = a;
|
|
44
49
|
}
|
|
45
50
|
if (!o.src || !o.out) {
|
|
46
|
-
console.error('usage: node render/render.mjs <built.html> --out <dir> [--fps 30] [--scale 1.5] [--only key|id|key:step,...] [--full] [--force]');
|
|
51
|
+
console.error('usage: node render/render.mjs <built.html> --out <dir> [--fps 30] [--scale 1.5] [--only key|id|key:step,...] [--full] [--force] [--music <file>]');
|
|
47
52
|
process.exit(1);
|
|
48
53
|
}
|
|
49
54
|
if (!Number.isInteger(o.fps) || o.fps < 1 || o.fps > 120) { console.error(`--fps は 1〜120 の整数 / --fps must be an integer in 1..120(${o.fps})`); process.exit(1); }
|
|
50
55
|
if (!Number.isFinite(o.scale) || o.scale < 0.25 || o.scale > 4) { console.error(`--scale は 0.25〜4 / --scale must be in 0.25..4(${o.scale})`); process.exit(1); }
|
|
56
|
+
if (o.music !== null && !(o.music && fs.existsSync(o.music) && fs.statSync(o.music).isFile())) { console.error(`--music のファイルがない / --music file not found(${o.music})`); process.exit(1); }
|
|
51
57
|
if (o.only && !o.only.size) { console.error('--only に鍵がない / --only needs at least one slide key, id or step key'); process.exit(1); }
|
|
52
58
|
return o;
|
|
53
59
|
}
|
|
@@ -83,10 +89,30 @@ function audioFile(src, htmlUrl, tmp, idx) {
|
|
|
83
89
|
return f;
|
|
84
90
|
}
|
|
85
91
|
|
|
92
|
+
// 音声のファイルを 48 kHz の PCM にする(ffmpeg で復号。channels:1 か 2)→ [Float32Array, …]
|
|
93
|
+
function decodePcm(file, channels = 1, sr = VIDEO_SR) {
|
|
94
|
+
const r = spawnSync('ffmpeg', ['-hide_banner', '-loglevel', 'error', '-i', file, '-vn', '-f', 'f32le', '-acodec', 'pcm_f32le', '-ac', String(channels), '-ar', String(sr), '-'], { maxBuffer: 2 ** 31 - 1 });
|
|
95
|
+
if (r.error) throw new Error(`ffmpeg を起動できない / cannot run ffmpeg (install ffmpeg and put it on PATH): ${r.error.message}`);
|
|
96
|
+
if (r.status !== 0) throw new Error(`ffmpeg (decode ${path.basename(file)}) failed:\n${String(r.stderr).slice(-2000)}`);
|
|
97
|
+
const b = r.stdout, n = Math.floor(b.length / 4 / channels);
|
|
98
|
+
const f = new Float32Array(b.buffer.slice(b.byteOffset, b.byteOffset + n * channels * 4));
|
|
99
|
+
const out = Array.from({ length: channels }, () => new Float32Array(n));
|
|
100
|
+
for (let i = 0; i < n; i++) for (let c = 0; c < channels; c++) out[c][i] = f[i * channels + c];
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
// 2 チャンネルの区間 [a, b) を、交互に並べた f32le のバイト列にする(ffmpeg の -f f32le -ac 2 の入力)
|
|
104
|
+
function interleave(ch, a, b) {
|
|
105
|
+
const n = Math.max(0, b - a), f = new Float32Array(n * 2);
|
|
106
|
+
for (let i = 0; i < n; i++) { f[2 * i] = ch[0][a + i] ?? 0; f[2 * i + 1] = ch[1][a + i] ?? 0; }
|
|
107
|
+
return Buffer.from(f.buffer);
|
|
108
|
+
}
|
|
109
|
+
const rawAudioArgs = (file) => ['-f', 'f32le', '-ar', String(VIDEO_SR), '-ac', '2', '-i', file];
|
|
110
|
+
const AAC = ['-c:a', 'aac', '-b:a', '192k', '-ar', String(VIDEO_SR), '-ac', '2'];
|
|
111
|
+
|
|
86
112
|
// 1 段階を mp4 にする。frames: 動きの区間のコマ(PNG のパス)、final: 最終状態の PNG
|
|
87
|
-
//
|
|
113
|
+
// pcm:この段階の音声(1 本の音声をコマの境目で切った区間。f32le・2 チャンネルのファイル)
|
|
88
114
|
// N:クリップのコマ数(固定フレームレート。frameStarts の境目の差)
|
|
89
|
-
function encodeClip({ frames, final,
|
|
115
|
+
function encodeClip({ frames, final, pcm, N, fps, out }) {
|
|
90
116
|
const nA = Math.min(frames.length, N);
|
|
91
117
|
const nH = N - nA;
|
|
92
118
|
const args = [];
|
|
@@ -104,33 +130,34 @@ function encodeClip({ frames, final, audio, sounds, N, lead, offset = 0, fps, ou
|
|
|
104
130
|
const nV = (nA > 0) + (nH > 0);
|
|
105
131
|
vf.push(nV > 1 ? `${vlabels}concat=n=${nV}:v=1:a=0,fps=${fps},format=yuv420p[v]` : `${vlabels}fps=${fps},format=yuv420p[v]`);
|
|
106
132
|
const T = (N / fps).toFixed(6);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const ms = Math.max(0, Math.round(lead * 1000));
|
|
110
|
-
const cut = offset > 0 ? `atrim=start=${offset.toFixed(6)},asetpts=PTS-STARTPTS,` : '';
|
|
111
|
-
vf.push(`[${vi}:a]${cut}aresample=44100,aformat=sample_fmts=fltp:channel_layouts=stereo,adelay=${ms}:all=1,apad,atrim=0:${T}[narr]`);
|
|
112
|
-
} else {
|
|
113
|
-
args.push('-f', 'lavfi', '-t', T, '-i', 'anullsrc=r=44100:cl=stereo');
|
|
114
|
-
vf.push(`[${vi}:a]atrim=0:${T}[narr]`);
|
|
115
|
-
}
|
|
116
|
-
if (sounds) {
|
|
117
|
-
args.push('-i', sounds);
|
|
118
|
-
vf.push(`[${vi + 1}:a]aformat=sample_fmts=fltp:channel_layouts=stereo,apad,atrim=0:${T}[sounds]`);
|
|
119
|
-
vf.push('[narr][sounds]amix=inputs=2:normalize=0,alimiter=limit=0.98:level=0:latency=1[a]');
|
|
120
|
-
} else vf.push('[narr]anull[a]');
|
|
121
|
-
args.push('-filter_complex', vf.join(';'), '-map', '[v]', '-map', '[a]',
|
|
133
|
+
args.push(...rawAudioArgs(pcm));
|
|
134
|
+
args.push('-filter_complex', vf.join(';'), '-map', '[v]', '-map', `${vi}:a`,
|
|
122
135
|
'-c:v', 'libx264', '-preset', 'medium', '-crf', '20', '-pix_fmt', 'yuv420p', '-r', String(fps), '-fps_mode', 'cfr',
|
|
123
136
|
'-g', String(fps * 2), '-frames:v', String(N),
|
|
124
|
-
|
|
137
|
+
...AAC, '-t', T,
|
|
125
138
|
'-movflags', '+faststart', out);
|
|
126
139
|
ff(args, path.basename(out));
|
|
127
140
|
}
|
|
128
141
|
|
|
129
|
-
//
|
|
130
|
-
|
|
142
|
+
// 同じ設定のクリップの映像を 1 本に繋ぎ(コピー。各クリップの長さはコマ数で決める)、音声は 1 本の音声の区間 [a, b) を 1 回だけ AAC にする
|
|
143
|
+
// 繋ぐ前に各クリップの映像だけを取り出す:クリップの AAC は先頭の 1024 標本(priming)が負の時刻にあり、concat はファイルの
|
|
144
|
+
// 始まり(その負の時刻)を 0 に合わせるため、音声つきのまま繋ぐと映像が 21 ms 遅れる
|
|
145
|
+
function joinClips(clips, out, tmp, track, a, b, fps) {
|
|
146
|
+
const vdir = fs.mkdtempSync(path.join(tmp, 'join-'));
|
|
147
|
+
const vids = clips.map((c, j) => {
|
|
148
|
+
const v = path.join(vdir, `v_${pad4(j)}.mp4`);
|
|
149
|
+
ff(['-i', c.file, '-map', '0:v', '-c', 'copy', v], `${path.basename(c.file)} (video)`);
|
|
150
|
+
return { file: v, frames: c.frames };
|
|
151
|
+
});
|
|
131
152
|
const list = path.join(tmp, `concat_${path.basename(out)}.txt`);
|
|
132
|
-
fs.writeFileSync(list,
|
|
133
|
-
|
|
153
|
+
fs.writeFileSync(list, vids.map((c) => `file '${c.file.replace(/'/g, "'\\''")}'\nduration ${(c.frames / fps).toFixed(6)}`).join('\n') + '\n');
|
|
154
|
+
const raw = path.join(tmp, `audio_${path.basename(out)}.f32`);
|
|
155
|
+
fs.writeFileSync(raw, interleave(track, a, b));
|
|
156
|
+
const frames = clips.reduce((x, c) => x + c.frames, 0);
|
|
157
|
+
ff(['-f', 'concat', '-safe', '0', '-i', list, ...rawAudioArgs(raw), '-map', '0:v', '-map', '1:a', '-c:v', 'copy', '-frames:v', String(frames),
|
|
158
|
+
...AAC, '-t', (frames / fps).toFixed(6), '-movflags', '+faststart', out], path.basename(out));
|
|
159
|
+
fs.rmSync(raw, { force: true });
|
|
160
|
+
fs.rmSync(vdir, { recursive: true, force: true });
|
|
134
161
|
}
|
|
135
162
|
|
|
136
163
|
async function main() {
|
|
@@ -162,8 +189,6 @@ async function main() {
|
|
|
162
189
|
const { tl, narration, ids } = await page.evaluate(() => ({ tl: DECK.timeline(), narration: DECK.NARRATION, ids: DECK.slides.map((x) => x.id || null) }));
|
|
163
190
|
let onlyKeys = null;
|
|
164
191
|
const soundEvents = videoSoundEvents(tl, await page.evaluate(collectVideoEvents), o.fps);
|
|
165
|
-
// 音色の変更・前の段階からの余韻もキャッシュの入力にする。
|
|
166
|
-
const soundHash = sha(JSON.stringify(soundEvents), readRegular(fileURLToPath(new URL('../kit/core/sounds.mjs', import.meta.url)), { max: READ_LIMITS.built }));
|
|
167
192
|
// 段階の入力:build 済みの HTML を(スクリプトを動かさずに)読み、スライドごとの HTML と、それ以外(部品のコード・
|
|
168
193
|
// テーマの CSS・deck.js など)に分ける。段階ごとの音声・注目の演出・時間の上書き・原稿は鍵ごとに入れる
|
|
169
194
|
const inputs = await page.evaluate((html) => {
|
|
@@ -210,7 +235,35 @@ async function main() {
|
|
|
210
235
|
|
|
211
236
|
const segsOut = [];
|
|
212
237
|
// 境目のコマは累積の時刻から決める(段階ごとに丸めると、短い段階が続く曲でずれがたまる)
|
|
213
|
-
const
|
|
238
|
+
const layout = trackLayout(tl, o.fps, VIDEO_SR);
|
|
239
|
+
const starts = layout.starts;
|
|
240
|
+
// 全体の音声を 1 本にする(左右。口述音声と部品の音は両方に同じものを置く)
|
|
241
|
+
const track = [new Float32Array(layout.total), new Float32Array(layout.total)];
|
|
242
|
+
for (let n = 0; n < tl.length; n++) {
|
|
243
|
+
const s = tl[n];
|
|
244
|
+
const file = audioFile(s.audio, htmlUrl, tmpRoot, n);
|
|
245
|
+
if (!file) continue;
|
|
246
|
+
readRegular(file, { max: READ_LIMITS.audio }); // 通常のファイルだけ、上限つきで
|
|
247
|
+
const [pcm] = decodePcm(file, 1);
|
|
248
|
+
const skip = Math.round((s.audioOffset || 0) * VIDEO_SR); // 音声の符号化の遅れ(format spec §5.2 startOffset)を先頭から切る
|
|
249
|
+
const from = layout.at(s.start + s.lead), to = layout.stepRange(n)[1];
|
|
250
|
+
const body = pcm.subarray(Math.min(skip, pcm.length));
|
|
251
|
+
placeNarration(track[0], body, from, to);
|
|
252
|
+
placeNarration(track[1], body, from, to);
|
|
253
|
+
if (from + body.length > to + Math.round(VIDEO_SR / 1000)) console.warn(` ⚠ ${s.key}: 音声(${s.lead}+${(body.length / VIDEO_SR).toFixed(2)} s)が dur(${s.dur.toFixed(2)} s)を超える。末尾を切る`);
|
|
254
|
+
}
|
|
255
|
+
if (soundEvents.length) {
|
|
256
|
+
const pcm = renderStepSounds(soundEvents, 0, layout.total / VIDEO_SR, VIDEO_SR);
|
|
257
|
+
for (const c of track) for (let i = 0; i < c.length && i < pcm.length; i++) c[i] += pcm[i];
|
|
258
|
+
}
|
|
259
|
+
if (o.music) {
|
|
260
|
+
const m = decodePcm(path.resolve(o.music), 2);
|
|
261
|
+
const g = musicGain(narrationWindows(tl), layout.total, VIDEO_SR, { base: musicBase(m) });
|
|
262
|
+
for (let c = 0; c < 2; c++) for (let i = 0; i < layout.total && i < m[c].length; i++) track[c][i] += m[c][i] * g[i];
|
|
263
|
+
console.log(` 背景の音楽: ${path.basename(o.music)}(${(m[0].length / VIDEO_SR).toFixed(1)} s。声の間は下げ、終わりで消す)`);
|
|
264
|
+
}
|
|
265
|
+
if (limitPeaks(track, 0.98, VIDEO_SR)) console.log(' 音声の山を 0.98 に抑えた');
|
|
266
|
+
const sliceHash = (a, b) => sha(interleave(track, a, b));
|
|
214
267
|
let made = 0, skipped = 0, clipT = 0; // clipT:ここまでのコマ数
|
|
215
268
|
for (let n = 0; n < tl.length; n++) {
|
|
216
269
|
const s = tl[n];
|
|
@@ -233,10 +286,10 @@ async function main() {
|
|
|
233
286
|
const motion = s.motion ?? s.anim;
|
|
234
287
|
const nA = Math.min(Math.ceil(motion * o.fps - 1e-6), N);
|
|
235
288
|
const tmp = fs.mkdtempSync(path.join(tmpRoot, `${clip}-`));
|
|
236
|
-
const
|
|
237
|
-
const audioHash =
|
|
289
|
+
const a0 = layout.frameSample(starts[n]), a1 = layout.frameSample(starts[n + 1]);
|
|
290
|
+
const audioHash = sliceHash(a0, a1); // このクリップの音声そのもの(前後の段階の余韻・背景の音楽も入る)
|
|
238
291
|
const per = inputs.per[n];
|
|
239
|
-
const input = sha(globalHash, audioHash,
|
|
292
|
+
const input = sha(globalHash, audioHash, JSON.stringify({
|
|
240
293
|
slides: inputs.ok ? per.deps.map((j) => slideHash[j]) : null, data: per.data, key: s.key, i: s.i, k: s.k,
|
|
241
294
|
dur: s.dur, lead: s.lead, anim: s.anim, motion, frames: N, nA, fps: o.fps, scale: o.scale, captions: o.captions }));
|
|
242
295
|
rec.input = input;
|
|
@@ -265,22 +318,15 @@ async function main() {
|
|
|
265
318
|
await shot(s.i, s.k, f / o.fps, file);
|
|
266
319
|
frames.push(file);
|
|
267
320
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const pcm = renderStepSounds(soundEvents, (clipT - N) / o.fps, N / o.fps);
|
|
272
|
-
if (pcm.some((x) => x !== 0)) {
|
|
273
|
-
sounds = path.join(tmp, 'sounds.wav');
|
|
274
|
-
fs.writeFileSync(sounds, encodeWav(pcm, 44100));
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
encodeClip({ frames, final, audio, sounds, N, lead: s.lead, offset: s.audioOffset || 0, fps: o.fps, out: mp4 });
|
|
321
|
+
const pcm = path.join(tmp, 'audio.f32');
|
|
322
|
+
fs.writeFileSync(pcm, interleave(track, a0, a1));
|
|
323
|
+
encodeClip({ frames, final, pcm, N, fps: o.fps, out: mp4 });
|
|
278
324
|
fs.copyFileSync(final, png);
|
|
279
325
|
cache.clips[clip] = { key: s.key, input, hash };
|
|
280
326
|
saveCache();
|
|
281
327
|
fs.rmSync(tmp, { recursive: true, force: true });
|
|
282
328
|
made++;
|
|
283
|
-
console.log(` [${n + 1}/${tl.length}] ${s.key}: ${s.dur.toFixed(2)} s(動き ${nA} コマ${audio ? '、音声あり' : ''})→ ${clip}.mp4`);
|
|
329
|
+
console.log(` [${n + 1}/${tl.length}] ${s.key}: ${s.dur.toFixed(2)} s(動き ${nA} コマ${s.audio ? '、音声あり' : ''})→ ${clip}.mp4`);
|
|
284
330
|
}
|
|
285
331
|
// 段階の数が減ったときの古いクリップは消す(連番がずれないように)
|
|
286
332
|
for (const f of fs.readdirSync(outDir)) {
|
|
@@ -294,7 +340,7 @@ async function main() {
|
|
|
294
340
|
const c = cache.clips[r.clip.replace(/\.mp4$/, '')];
|
|
295
341
|
return !c || c.input !== r.input || c.key !== r.key || !fs.existsSync(path.join(outDir, r.clip)) || !fs.existsSync(path.join(outDir, r.still));
|
|
296
342
|
}).map((r) => r.key);
|
|
297
|
-
const meta = { source: src, sourceHash: sha(htmlText), fps: o.fps, scale: o.scale, width: Math.round(W * o.scale), height: Math.round(H * o.scale),
|
|
343
|
+
const meta = { source: src, sourceHash: sha(htmlText), fps: o.fps, sampleRate: VIDEO_SR, music: o.music ? path.basename(o.music) : null, scale: o.scale, width: Math.round(W * o.scale), height: Math.round(H * o.scale),
|
|
298
344
|
duration: +total.toFixed(3), clipDuration: +(clipT / o.fps).toFixed(6), complete: stale.length === 0, stale, segments: segsOut };
|
|
299
345
|
fs.writeFileSync(path.join(outDir, 'timeline.out.json'), JSON.stringify(meta, null, 1));
|
|
300
346
|
console.log(`完了: 新規 ${made} / キャッシュ ${skipped} → ${outDir}`);
|
|
@@ -309,18 +355,20 @@ async function main() {
|
|
|
309
355
|
const clips = segsOut.map((s) => path.join(outDir, s.clip));
|
|
310
356
|
const missing = clips.filter((f) => !fs.existsSync(f));
|
|
311
357
|
if (missing.length) throw new Error(`--full: クリップが足りない(${missing.length} 本)。--only なしで書き出してから`);
|
|
312
|
-
|
|
358
|
+
joinClips(segsOut.map((s) => ({ file: path.join(outDir, s.clip), frames: s.frames })), path.join(outDir, 'full.mp4'), tmpRoot, track, 0, layout.total, o.fps);
|
|
313
359
|
console.log(` full.mp4: ${(+probe(path.join(outDir, 'full.mp4')).format.duration).toFixed(2)} s(timeline ${total.toFixed(2)} s)`);
|
|
314
360
|
// 章ごと(連続する同じ chapter をまとめる)
|
|
315
361
|
const groups = [];
|
|
316
362
|
for (const s of segsOut) {
|
|
317
|
-
if (!groups.length || groups.at(-1).chapter !== s.chapter) groups.push({ chapter: s.chapter, clips: [] });
|
|
363
|
+
if (!groups.length || groups.at(-1).chapter !== s.chapter) groups.push({ chapter: s.chapter, clips: [], f0: starts[s.index], f1: starts[s.index] });
|
|
318
364
|
groups.at(-1).clips.push(path.join(outDir, s.clip));
|
|
365
|
+
groups.at(-1).frames = (groups.at(-1).frames || []).concat(s.frames);
|
|
366
|
+
groups.at(-1).f1 = starts[s.index + 1];
|
|
319
367
|
}
|
|
320
368
|
if (groups.length > 1) {
|
|
321
369
|
groups.forEach((g, j) => {
|
|
322
370
|
const name = `chapter_${String(j + 1).padStart(2, '0')}.mp4`;
|
|
323
|
-
|
|
371
|
+
joinClips(g.clips.map((file, j) => ({ file, frames: g.frames[j] })), path.join(outDir, name), tmpRoot, track, layout.frameSample(g.f0), layout.frameSample(g.f1), o.fps);
|
|
324
372
|
console.log(` ${name}: ${g.chapter || '(章の前)'} ${g.clips.length} 段階`);
|
|
325
373
|
});
|
|
326
374
|
fs.writeFileSync(path.join(outDir, 'chapters.json'), JSON.stringify(groups.map((g, j) => ({ file: `chapter_${String(j + 1).padStart(2, '0')}.mp4`, chapter: g.chapter, clips: g.clips.map((c) => path.basename(c)) })), null, 1));
|