Spaces:
Running
Running
Commit ·
d86e8a7
1
Parent(s): b1a7870
Pick the transtions:
Browse files- utils/AvatarRender.js +23 -0
utils/AvatarRender.js
CHANGED
|
@@ -27,6 +27,10 @@ export class AvatarRenderer {
|
|
| 27 |
|
| 28 |
const tempFiles = []; // track intermediate files for cleanup
|
| 29 |
const sectionCaptionedVideos = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
// Step 1: For each section, concat its media files and burn its captions
|
| 32 |
for (let i = 0; i < originalManuscript.transcript.length; i++) {
|
|
@@ -37,6 +41,15 @@ export class AvatarRenderer {
|
|
| 37 |
continue;
|
| 38 |
}
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
let sectionVideo;
|
| 41 |
|
| 42 |
// Concat all media files within this section
|
|
@@ -91,11 +104,15 @@ export class AvatarRenderer {
|
|
| 91 |
await this.runFFmpeg(subArgs, controller, onLog);
|
| 92 |
tempFiles.push(subbedFile);
|
| 93 |
sectionCaptionedVideos.push(subbedFile);
|
|
|
|
|
|
|
| 94 |
} else {
|
| 95 |
let sourceAfterBubblesInoutDir = path.join(outDir, path.basename(sourceAfterBubbles))
|
| 96 |
fs.copyFileSync(sourceAfterBubbles, sourceAfterBubblesInoutDir)
|
| 97 |
sectionCaptionedVideos.push(sourceAfterBubblesInoutDir);
|
| 98 |
tempFiles.push(sourceAfterBubblesInoutDir);
|
|
|
|
|
|
|
| 99 |
}
|
| 100 |
}
|
| 101 |
|
|
@@ -118,6 +135,12 @@ export class AvatarRenderer {
|
|
| 118 |
'-c', 'copy',
|
| 119 |
'-y', videoWithSubs
|
| 120 |
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
onLog && onLog(`Concatenating ${sectionCaptionedVideos.length} captioned sections...\n`);
|
| 122 |
await this.runFFmpeg(finalConcatArgs, controller, onLog);
|
| 123 |
tempFiles.push(videoWithSubs);
|
|
|
|
| 27 |
|
| 28 |
const tempFiles = []; // track intermediate files for cleanup
|
| 29 |
const sectionCaptionedVideos = [];
|
| 30 |
+
// track last media path of previous processed section for transition logging
|
| 31 |
+
let prevSectionLastMedia = null;
|
| 32 |
+
// collect requested transitions to log during final concat step
|
| 33 |
+
const transitions = [];
|
| 34 |
|
| 35 |
// Step 1: For each section, concat its media files and burn its captions
|
| 36 |
for (let i = 0; i < originalManuscript.transcript.length; i++) {
|
|
|
|
| 41 |
continue;
|
| 42 |
}
|
| 43 |
|
| 44 |
+
// Check for requested transition on this section
|
| 45 |
+
const transitionType = section.transition_type || section.transitionType || null;
|
| 46 |
+
const transitionDuration = (section.transition_duration_sec !== undefined && section.transition_duration_sec !== null) ? section.transition_duration_sec : (section.transitionDurationSec !== undefined ? section.transitionDurationSec : null);
|
| 47 |
+
const firstMedia = sectionVideos[0];
|
| 48 |
+
if (transitionType && firstMedia) {
|
| 49 |
+
// record transition to be logged during final concatenation
|
| 50 |
+
transitions.push({ type: transitionType, duration: transitionDuration, from: prevSectionLastMedia ? prevSectionLastMedia : 'start', to: firstMedia });
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
let sectionVideo;
|
| 54 |
|
| 55 |
// Concat all media files within this section
|
|
|
|
| 104 |
await this.runFFmpeg(subArgs, controller, onLog);
|
| 105 |
tempFiles.push(subbedFile);
|
| 106 |
sectionCaptionedVideos.push(subbedFile);
|
| 107 |
+
// update prevSectionLastMedia to the last media path of this section
|
| 108 |
+
prevSectionLastMedia = sectionVideos[sectionVideos.length - 1];
|
| 109 |
} else {
|
| 110 |
let sourceAfterBubblesInoutDir = path.join(outDir, path.basename(sourceAfterBubbles))
|
| 111 |
fs.copyFileSync(sourceAfterBubbles, sourceAfterBubblesInoutDir)
|
| 112 |
sectionCaptionedVideos.push(sourceAfterBubblesInoutDir);
|
| 113 |
tempFiles.push(sourceAfterBubblesInoutDir);
|
| 114 |
+
// update prevSectionLastMedia to the last media path of this section
|
| 115 |
+
prevSectionLastMedia = sectionVideos[sectionVideos.length - 1];
|
| 116 |
}
|
| 117 |
}
|
| 118 |
|
|
|
|
| 135 |
'-c', 'copy',
|
| 136 |
'-y', videoWithSubs
|
| 137 |
];
|
| 138 |
+
// Log collected transitions before final concatenation
|
| 139 |
+
if (transitions && transitions.length) {
|
| 140 |
+
for (const t of transitions) {
|
| 141 |
+
onLog && onLog("Applying transition", t.type, "for duration", t.duration, "between", t.from, t.to);
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
onLog && onLog(`Concatenating ${sectionCaptionedVideos.length} captioned sections...\n`);
|
| 145 |
await this.runFFmpeg(finalConcatArgs, controller, onLog);
|
| 146 |
tempFiles.push(videoWithSubs);
|