@twick/cloud-subtitle-video 0.15.1 → 0.15.2
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/core/project.utils.js +32 -7
- package/package.json +1 -1
package/core/project.utils.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a short UUID for element and track identification.
|
|
3
|
+
* Creates a 12-character unique identifier using a simplified
|
|
4
|
+
* UUID generation algorithm.
|
|
5
|
+
*
|
|
6
|
+
* @returns A 12-character unique identifier string
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* const id = generateShortUuid();
|
|
11
|
+
* // id = "a1b2c3d4e5f6"
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
const generateShortUuid = () => {
|
|
15
|
+
return "xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
16
|
+
const r = (Math.random() * 16) | 0;
|
|
17
|
+
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
18
|
+
return v.toString(16);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
1
21
|
/**
|
|
2
22
|
* Builds a Twick subtitle video project JSON structure from transcription results.
|
|
3
23
|
*
|
|
@@ -11,6 +31,9 @@
|
|
|
11
31
|
export const buildProject = (params) => {
|
|
12
32
|
const { subtitles, duration, videoUrl, videoSize } = params;
|
|
13
33
|
|
|
34
|
+
const videoTrackId = `t-${generateShortUuid()}`;
|
|
35
|
+
const captionTrackId = `t-${generateShortUuid()}`;
|
|
36
|
+
|
|
14
37
|
return {
|
|
15
38
|
properties: {
|
|
16
39
|
width: videoSize?.width || 720,
|
|
@@ -18,29 +41,30 @@ export const buildProject = (params) => {
|
|
|
18
41
|
},
|
|
19
42
|
tracks: [
|
|
20
43
|
{
|
|
21
|
-
id:
|
|
44
|
+
id: videoTrackId,
|
|
22
45
|
type: "video",
|
|
23
46
|
elements: [
|
|
24
47
|
{
|
|
25
|
-
id:
|
|
48
|
+
id: `e-${generateShortUuid()}`,
|
|
26
49
|
type: "video",
|
|
27
50
|
s: 0,
|
|
28
51
|
e: duration,
|
|
29
52
|
props: {
|
|
30
53
|
src: videoUrl,
|
|
31
|
-
|
|
32
|
-
|
|
54
|
+
},
|
|
55
|
+
frame: {
|
|
56
|
+
size: [videoSize?.width || 720, videoSize?.height || 1280],
|
|
33
57
|
},
|
|
34
58
|
},
|
|
35
59
|
],
|
|
36
60
|
},
|
|
37
61
|
{
|
|
38
|
-
id:
|
|
62
|
+
id: captionTrackId,
|
|
39
63
|
type: "caption",
|
|
40
64
|
props: {
|
|
41
65
|
capStyle: "highlight_bg",
|
|
42
66
|
font: {
|
|
43
|
-
size:
|
|
67
|
+
size: 46,
|
|
44
68
|
weight: 700,
|
|
45
69
|
family: "Bangers",
|
|
46
70
|
},
|
|
@@ -59,7 +83,8 @@ export const buildProject = (params) => {
|
|
|
59
83
|
applyToAll: true,
|
|
60
84
|
},
|
|
61
85
|
elements: subtitles.map((subtitle, index) => ({
|
|
62
|
-
id: `
|
|
86
|
+
id: `e-${generateShortUuid()}`,
|
|
87
|
+
trackId: captionTrackId,
|
|
63
88
|
type: "caption",
|
|
64
89
|
s: subtitle.s / 1000,
|
|
65
90
|
e: subtitle.e / 1000,
|
package/package.json
CHANGED