jbilcke-hf HF staff commited on
Commit
1083ad0
·
1 Parent(s): 2e5dd3f
src/core/ffmpeg/concatenateVideosWithAudio.mts CHANGED
@@ -61,7 +61,7 @@ export const concatenateVideosWithAudio = async ({
61
 
62
  videoFilePaths = videoFilePaths.filter((video) => existsSync(video))
63
 
64
- // console.log("concatenating videos (without audio)..")
65
  const tempFilePath = await concatenateVideos({
66
  videoFilePaths,
67
  })
@@ -72,6 +72,8 @@ export const concatenateVideosWithAudio = async ({
72
 
73
  const finalOutputFilePath = output || path.join(tempDir, `${uuidv4()}.${format}`);
74
 
 
 
75
  // Begin ffmpeg command configuration
76
  let cmd = ffmpeg();
77
 
@@ -113,8 +115,8 @@ export const concatenateVideosWithAudio = async ({
113
  ]);
114
  }
115
 
116
- /*
117
- console.log("DEBUG:", {
118
  videoTracksVolume,
119
  audioTrackVolume,
120
  videoFilePaths,
@@ -125,12 +127,12 @@ export const concatenateVideosWithAudio = async ({
125
  // additionalAudioVolume,
126
  finalOutputFilePath
127
  })
128
- */
129
 
130
  // Set up event handlers for ffmpeg processing
131
  const promise = new Promise<string>((resolve, reject) => {
132
  cmd.on('error', (err) => {
133
- console.error(" Error during ffmpeg processing:", err.message);
134
  reject(err);
135
  }).on('end', async () => {
136
  // When ffmpeg finishes processing, resolve the promise with file info
 
61
 
62
  videoFilePaths = videoFilePaths.filter((video) => existsSync(video))
63
 
64
+ console.log("concatenateVideosWithAudio: concatenating videos (without audio)..")
65
  const tempFilePath = await concatenateVideos({
66
  videoFilePaths,
67
  })
 
72
 
73
  const finalOutputFilePath = output || path.join(tempDir, `${uuidv4()}.${format}`);
74
 
75
+ console.log(`concatenateVideosWithAudio: finalOutputFilePath = ${finalOutputFilePath}`)
76
+
77
  // Begin ffmpeg command configuration
78
  let cmd = ffmpeg();
79
 
 
115
  ]);
116
  }
117
 
118
+
119
+ console.log("concatenateVideosWithAudio: DEBUG:", {
120
  videoTracksVolume,
121
  audioTrackVolume,
122
  videoFilePaths,
 
127
  // additionalAudioVolume,
128
  finalOutputFilePath
129
  })
130
+
131
 
132
  // Set up event handlers for ffmpeg processing
133
  const promise = new Promise<string>((resolve, reject) => {
134
  cmd.on('error', (err) => {
135
+ console.error("concatenateVideosWithAudio: Error during ffmpeg processing:", err.message);
136
  reject(err);
137
  }).on('end', async () => {
138
  // When ffmpeg finishes processing, resolve the promise with file info
src/core/files/deleteFileWithName.mts CHANGED
@@ -3,6 +3,7 @@ import path from "node:path"
3
  import { deleteFile } from "./deleteFile.mts"
4
 
5
  export const deleteFilesWithName = async (dir: string, name: string, debug?: boolean) => {
 
6
  for (const file of await fs.readdir(dir)) {
7
  if (file.includes(name)) {
8
  await deleteFile(path.join(dir, file))
 
3
  import { deleteFile } from "./deleteFile.mts"
4
 
5
  export const deleteFilesWithName = async (dir: string, name: string, debug?: boolean) => {
6
+ console.log(`deleteFilesWithName(${dir}, ${name})`)
7
  for (const file of await fs.readdir(dir)) {
8
  if (file.includes(name)) {
9
  await deleteFile(path.join(dir, file))
src/index.mts CHANGED
@@ -2,11 +2,11 @@
2
  import { Blob } from "node:buffer"
3
 
4
  import express from "express"
 
5
  import { parseClap, ClapProject } from "@aitube/clap"
6
 
7
  import { clapToTmpVideoFilePath } from "./main.mts"
8
  import { deleteFile } from "./core/files/deleteFile.mts"
9
- import queryString from "query-string"
10
  import { defaultExportFormat, SupportedExportFormat } from "./core/ffmpeg/concatenateVideosWithAudio.mts"
11
 
12
  const app = express()
 
2
  import { Blob } from "node:buffer"
3
 
4
  import express from "express"
5
+ import queryString from "query-string"
6
  import { parseClap, ClapProject } from "@aitube/clap"
7
 
8
  import { clapToTmpVideoFilePath } from "./main.mts"
9
  import { deleteFile } from "./core/files/deleteFile.mts"
 
10
  import { defaultExportFormat, SupportedExportFormat } from "./core/ffmpeg/concatenateVideosWithAudio.mts"
11
 
12
  const app = express()
src/main.mts CHANGED
@@ -37,6 +37,11 @@ export async function clapToTmpVideoFilePath({
37
  outputFilePath: string
38
  }> {
39
 
 
 
 
 
 
40
  outputDir = outputDir || (await getRandomDirectory())
41
 
42
  const videoSegments = clap.segments.filter(s => s.category === "video" && s.assetUrl.startsWith("data:video/"))
@@ -74,7 +79,10 @@ export async function clapToTmpVideoFilePath({
74
  throw new Error(`the provided Clap doesn't contain any video or storyboard`)
75
  }
76
 
77
- console.log(`clapToTmpVideoFilePath: calling concatenateVideos over ${videoFilePaths.length} video chunks: ${JSON.stringify(videoFilePaths, null, 2)}`)
 
 
 
78
 
79
  const concatenatedVideosNoMusic = await concatenateVideos({
80
  videoFilePaths,
@@ -114,7 +122,16 @@ export async function clapToTmpVideoFilePath({
114
  console.log(`clapToTmpVideoFilePath: concatenatedAudio = ${concatenatedAudio}`)
115
  }
116
 
117
-
 
 
 
 
 
 
 
 
 
118
  const finalFilePathOfVideoWithMusic = await concatenateVideosWithAudio({
119
  output: join(outputDir, `final_video.${format}`),
120
  format,
@@ -124,7 +141,8 @@ export async function clapToTmpVideoFilePath({
124
  videoTracksVolume: concatenatedAudio ? 0.85 : 1.0,
125
  audioTrackVolume: concatenatedAudio ? 0.15 : 0.0, // let's keep the music volume low
126
  })
127
- // console.log(`clapToTmpVideoFilePath: finalFilePathOfVideoWithMusic = ${finalFilePathOfVideoWithMusic}`)
 
128
 
129
  if (clearTmpFilesAtEnd) {
130
  // we delete all the temporary assets
 
37
  outputFilePath: string
38
  }> {
39
 
40
+ // in case we have an issue with the format
41
+ if (format !== "mp4" && format !== "webm") {
42
+ format = "mp4"
43
+ }
44
+
45
  outputDir = outputDir || (await getRandomDirectory())
46
 
47
  const videoSegments = clap.segments.filter(s => s.category === "video" && s.assetUrl.startsWith("data:video/"))
 
79
  throw new Error(`the provided Clap doesn't contain any video or storyboard`)
80
  }
81
 
82
+ console.log(`clapToTmpVideoFilePath: calling concatenateVideos over ${videoFilePaths.length} video chunks: ${JSON.stringify(videoFilePaths, null, 2)}\nconcatenateVideos(${JSON.stringify({
83
+ videoFilePaths,
84
+ output: join(outputDir, `tmp_asset_concatenated_videos.mp4`)
85
+ }, null, 2)})`)
86
 
87
  const concatenatedVideosNoMusic = await concatenateVideos({
88
  videoFilePaths,
 
122
  console.log(`clapToTmpVideoFilePath: concatenatedAudio = ${concatenatedAudio}`)
123
  }
124
 
125
+ console.log(`calling concatenateVideosWithAudio: `, {
126
+ output: join(outputDir, `final_video.${format}`),
127
+ format,
128
+ audioFilePath: concatenatedAudio ? concatenatedAudio?.filepath : undefined,
129
+ videoFilePaths: [concatenatedVideosNoMusic.filepath],
130
+ // videos are silent, so they can stay at 0
131
+ videoTracksVolume: concatenatedAudio ? 0.85 : 1.0,
132
+ audioTrackVolume: concatenatedAudio ? 0.15 : 0.0, // let's keep the music volume low
133
+ })
134
+
135
  const finalFilePathOfVideoWithMusic = await concatenateVideosWithAudio({
136
  output: join(outputDir, `final_video.${format}`),
137
  format,
 
141
  videoTracksVolume: concatenatedAudio ? 0.85 : 1.0,
142
  audioTrackVolume: concatenatedAudio ? 0.15 : 0.0, // let's keep the music volume low
143
  })
144
+
145
+ console.log(`clapToTmpVideoFilePath: finalFilePathOfVideoWithMusic = ${finalFilePathOfVideoWithMusic}`)
146
 
147
  if (clearTmpFilesAtEnd) {
148
  // we delete all the temporary assets