Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
fc91769
1
Parent(s):
b80b9f7
let's support silent videos
Browse files- src/main.mts +18 -14
src/main.mts
CHANGED
@@ -2,7 +2,7 @@ import { join } from "node:path"
|
|
2 |
|
3 |
import { ClapProject } from "@aitube/clap";
|
4 |
|
5 |
-
import { concatenateAudio } from "./core/ffmpeg/concatenateAudio.mts";
|
6 |
import { concatenateVideosWithAudio, defaultExportFormat, SupportedExportFormat } from "./core/ffmpeg/concatenateVideosWithAudio.mts";
|
7 |
import { writeBase64ToFile } from "./core/files/writeBase64ToFile.mts";
|
8 |
import { concatenateVideos } from "./core/ffmpeg/concatenateVideos.mts"
|
@@ -101,19 +101,23 @@ export async function clapToTmpVideoFilePath({
|
|
101 |
)
|
102 |
}
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
113 |
console.log(`clapToTmpVideoFilePath: calling concatenateVideosWithAudio with: ${JSON.stringify({
|
114 |
output: join(outputDir, `final_video.${format}`),
|
115 |
format,
|
116 |
-
audioFilePath: concatenatedAudio
|
117 |
videoFilePaths: [concatenatedVideosNoMusic.filepath],
|
118 |
// videos are silent, so they can stay at 0
|
119 |
videoTracksVolume: 0.85,
|
@@ -123,11 +127,11 @@ export async function clapToTmpVideoFilePath({
|
|
123 |
const finalFilePathOfVideoWithMusic = await concatenateVideosWithAudio({
|
124 |
output: join(outputDir, `final_video.${format}`),
|
125 |
format,
|
126 |
-
audioFilePath: concatenatedAudio
|
127 |
videoFilePaths: [concatenatedVideosNoMusic.filepath],
|
128 |
// videos are silent, so they can stay at 0
|
129 |
-
videoTracksVolume: 0.85,
|
130 |
-
audioTrackVolume: 0.15, // let's keep the music volume low
|
131 |
})
|
132 |
console.log(`clapToTmpVideoFilePath: finalFilePathOfVideoWithMusic = ${finalFilePathOfVideoWithMusic}`)
|
133 |
|
|
|
2 |
|
3 |
import { ClapProject } from "@aitube/clap";
|
4 |
|
5 |
+
import { concatenateAudio, ConcatenateAudioOutput } from "./core/ffmpeg/concatenateAudio.mts";
|
6 |
import { concatenateVideosWithAudio, defaultExportFormat, SupportedExportFormat } from "./core/ffmpeg/concatenateVideosWithAudio.mts";
|
7 |
import { writeBase64ToFile } from "./core/files/writeBase64ToFile.mts";
|
8 |
import { concatenateVideos } from "./core/ffmpeg/concatenateVideos.mts"
|
|
|
101 |
)
|
102 |
}
|
103 |
|
104 |
+
let concatenatedAudio: ConcatenateAudioOutput | undefined = undefined
|
105 |
+
|
106 |
+
if (audioTracks.length > 0) {
|
107 |
+
console.log(`clapToTmpVideoFilePath: calling concatenateAudio over ${audioTracks.length} audio tracks`)
|
108 |
+
|
109 |
+
concatenatedAudio = await concatenateAudio({
|
110 |
+
output: join(outputDir, `tmp_asset_concatenated_audio.wav`),
|
111 |
+
audioTracks,
|
112 |
+
crossfadeDurationInSec: 2 // 2 seconds
|
113 |
+
})
|
114 |
+
console.log(`clapToTmpVideoFilePath: concatenatedAudio = ${concatenatedAudio}`)
|
115 |
+
}
|
116 |
+
|
117 |
console.log(`clapToTmpVideoFilePath: calling concatenateVideosWithAudio with: ${JSON.stringify({
|
118 |
output: join(outputDir, `final_video.${format}`),
|
119 |
format,
|
120 |
+
audioFilePath: concatenatedAudio ? concatenatedAudio?.filepath : "",
|
121 |
videoFilePaths: [concatenatedVideosNoMusic.filepath],
|
122 |
// videos are silent, so they can stay at 0
|
123 |
videoTracksVolume: 0.85,
|
|
|
127 |
const finalFilePathOfVideoWithMusic = await concatenateVideosWithAudio({
|
128 |
output: join(outputDir, `final_video.${format}`),
|
129 |
format,
|
130 |
+
audioFilePath: concatenatedAudio ? concatenatedAudio?.filepath : undefined,
|
131 |
videoFilePaths: [concatenatedVideosNoMusic.filepath],
|
132 |
// videos are silent, so they can stay at 0
|
133 |
+
videoTracksVolume: concatenatedAudio ? 0.85 : 1.0,
|
134 |
+
audioTrackVolume: concatenatedAudio ? 0.15 : 0.0, // let's keep the music volume low
|
135 |
})
|
136 |
console.log(`clapToTmpVideoFilePath: finalFilePathOfVideoWithMusic = ${finalFilePathOfVideoWithMusic}`)
|
137 |
|