Skip to content

Commit bab2d96

Browse files
committed
logging
1 parent 6e6374b commit bab2d96

File tree

4 files changed

+147
-39
lines changed

4 files changed

+147
-39
lines changed

apps/worker/src/app.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable turbo/no-undeclared-env-vars */
22
/* eslint-disable @typescript-eslint/no-non-null-assertion */
3-
import { rm } from "fs/promises";
3+
import { existsSync } from "fs";
4+
import { readdir, rm, stat } from "fs/promises";
45
import { join } from "path";
56
import { Worker } from "bullmq";
67

@@ -24,6 +25,8 @@ export async function createVideo(
2425
data: CreateVideoData,
2526
updateProgress: (progress: JobProgress) => Promise<void>,
2627
) {
28+
console.log("=== Starting video creation for ID:", data.id);
29+
2730
// Generate the script
2831
await updateProgress({ state: "Generating script...", progress: 10 });
2932
const { lines: script, title, description } = await generateScript(data);
@@ -41,6 +44,50 @@ export async function createVideo(
4144
),
4245
);
4346

47+
console.log("=== Generated audio paths:", audioPaths);
48+
49+
// Log what's in the public directory
50+
const publicDir = join(process.cwd(), "public");
51+
const jobPublicDir = join(publicDir, data.id);
52+
53+
console.log("=== Checking public directory structure:");
54+
console.log("Public dir exists:", existsSync(publicDir));
55+
console.log("Job public dir exists:", existsSync(jobPublicDir));
56+
57+
if (existsSync(publicDir)) {
58+
try {
59+
const publicContents = await readdir(publicDir);
60+
console.log("Public directory contents:", publicContents);
61+
} catch (error) {
62+
console.error("Error reading public directory:", error);
63+
}
64+
}
65+
66+
if (existsSync(jobPublicDir)) {
67+
try {
68+
const jobPublicContents = await readdir(jobPublicDir);
69+
console.log(
70+
`Job public directory (${data.id}) contents:`,
71+
jobPublicContents,
72+
);
73+
74+
// Check file sizes and permissions
75+
for (const file of jobPublicContents) {
76+
try {
77+
const filePath = join(jobPublicDir, file);
78+
const stats = await stat(filePath);
79+
console.log(
80+
`File ${file}: size=${stats.size} bytes, readable=${stats.isFile()}`,
81+
);
82+
} catch (error) {
83+
console.error(`Error checking file ${file}:`, error);
84+
}
85+
}
86+
} catch (error) {
87+
console.error("Error reading job public directory:", error);
88+
}
89+
}
90+
4491
// Generate master transcript
4592
await updateProgress({ state: "Generating transcript...", progress: 40 });
4693
const transcript = await generateTranscript({

apps/worker/src/remotion/Root.tsx

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,47 @@ export const RemotionRoot: React.FC = () => {
3636
return { durationInFrames: 300 }; // 10 seconds at 30fps
3737
}
3838

39-
// Calculate total duration including delays
40-
const durations = await Promise.all(
41-
audioPaths.map(async (audio) => {
42-
const audioData = await getAudioData(staticFile(audio.path));
43-
return audioData.durationInSeconds;
44-
}),
45-
);
39+
try {
40+
// Calculate total duration including delays
41+
const durations = await Promise.all(
42+
audioPaths.map(async (audio) => {
43+
console.log("Attempting to get audio data for:", audio.path);
44+
try {
45+
const audioData = await getAudioData(staticFile(audio.path));
46+
console.log(
47+
"Successfully got audio data for:",
48+
audio.path,
49+
"duration:",
50+
audioData.durationInSeconds,
51+
);
52+
return audioData.durationInSeconds;
53+
} catch (error) {
54+
console.error(
55+
"Failed to get audio data for:",
56+
audio.path,
57+
error,
58+
);
59+
// Return a default duration if audio data fails
60+
return 5; // 5 seconds default
61+
}
62+
}),
63+
);
4664

47-
const totalDuration =
48-
durations.reduce((acc, duration, index) => {
49-
return (
50-
acc + duration + (index < durations.length - 1 ? delay : 0)
51-
);
52-
}, 0) + 2; // Add 2 second buffer
65+
const totalDuration =
66+
durations.reduce((acc, duration, index) => {
67+
return (
68+
acc + duration + (index < durations.length - 1 ? delay : 0)
69+
);
70+
}, 0) + 2; // Add 2 second buffer
5371

54-
return {
55-
durationInFrames: Math.ceil(totalDuration * 30), // Convert to frames at 30fps
56-
};
72+
return {
73+
durationInFrames: Math.ceil(totalDuration * 30), // Convert to frames at 30fps
74+
};
75+
} catch (error) {
76+
console.error("Error in calculateMetadata:", error);
77+
// Return default duration if everything fails
78+
return { durationInFrames: 300 };
79+
}
5780
}}
5881
/>
5982
</>

apps/worker/src/remotion/Video.tsx

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,62 @@ export const Video: React.FC<VideoProps> = ({
143143

144144
useEffect(() => {
145145
const calculateStartTimes = async () => {
146-
const audioData = await Promise.all(
147-
audioPaths.map((audio) => getAudioData(staticFile(audio.path))),
148-
);
149-
150-
const times = audioData.reduce<number[]>((acc, _, index) => {
151-
const previousStart = acc[index - 1] ?? 0;
152-
const previousDuration = audioData[index - 1]?.durationInSeconds ?? 0;
153-
return [...acc, previousStart + previousDuration + delay];
154-
}, []);
155-
156-
setStartTimes(times);
157-
setDurations(audioData.map((data) => data.durationInSeconds));
146+
try {
147+
const audioData = await Promise.all(
148+
audioPaths.map(async (audio) => {
149+
console.log(
150+
"Video component: Attempting to get audio data for:",
151+
audio.path,
152+
);
153+
try {
154+
const data = await getAudioData(staticFile(audio.path));
155+
console.log(
156+
"Video component: Successfully got audio data for:",
157+
audio.path,
158+
"duration:",
159+
data.durationInSeconds,
160+
);
161+
return data;
162+
} catch (error) {
163+
console.error(
164+
"Video component: Failed to get audio data for:",
165+
audio.path,
166+
error,
167+
);
168+
// Return a mock audio data object if getAudioData fails
169+
return {
170+
durationInSeconds: 5, // Default 5 seconds
171+
sampleRate: 44100,
172+
numberOfChannels: 2,
173+
};
174+
}
175+
}),
176+
);
177+
178+
const times = audioData.reduce<number[]>((acc, _, index) => {
179+
const previousStart = acc[index - 1] ?? 0;
180+
const previousDuration = audioData[index - 1]?.durationInSeconds ?? 0;
181+
return [...acc, previousStart + previousDuration + delay];
182+
}, []);
183+
184+
setStartTimes(times);
185+
setDurations(audioData.map((data) => data.durationInSeconds));
186+
} catch (error) {
187+
console.error("Video component: Error in calculateStartTimes:", error);
188+
// Set default values if everything fails
189+
const defaultDurations = audioPaths.map(() => 5); // 5 seconds each
190+
const defaultTimes = defaultDurations.reduce<number[]>(
191+
(acc, _, index) => {
192+
const previousStart = acc[index - 1] ?? 0;
193+
const previousDuration = defaultDurations[index - 1] ?? 0;
194+
return [...acc, previousStart + previousDuration + delay];
195+
},
196+
[],
197+
);
198+
199+
setStartTimes(defaultTimes);
200+
setDurations(defaultDurations);
201+
}
158202
};
159203

160204
void calculateStartTimes();

apps/worker/src/utils/generate-video.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export interface GenerateVideoData {
2727

2828
export async function generateVideo(data: GenerateVideoData): Promise<string> {
2929
console.log("Generating video");
30+
console.log("Environment:", process.env.NODE_ENV);
31+
console.log("Audio paths:", data.audioPaths);
3032

3133
// Bundle the Remotion project
3234
const bundled = await bundle("./src/remotion/index.ts");
@@ -37,6 +39,8 @@ export async function generateVideo(data: GenerateVideoData): Promise<string> {
3739
speaker: audio.speaker,
3840
}));
3941

42+
console.log("Relative audio paths:", relativeAudioPaths);
43+
4044
// Get the composition configuration
4145
const composition = await selectComposition({
4246
serveUrl: bundled,
@@ -50,11 +54,6 @@ export async function generateVideo(data: GenerateVideoData): Promise<string> {
5054
backgroundBlurPx: data.backgroundBlurPx,
5155
backgroundVideo: data.backgroundVideo,
5256
},
53-
// Add chromium options to fix AudioContext issues in headless environments
54-
chromiumOptions: {
55-
disableWebSecurity: true,
56-
gl: "swiftshader", // Use software rendering to avoid GPU/audio device dependencies
57-
},
5857
});
5958

6059
// Render the video
@@ -73,11 +72,6 @@ export async function generateVideo(data: GenerateVideoData): Promise<string> {
7372
backgroundBlurPx: data.backgroundBlurPx,
7473
backgroundVideo: data.backgroundVideo,
7574
},
76-
// Add chromium options to fix AudioContext issues in headless environments
77-
chromiumOptions: {
78-
disableWebSecurity: true,
79-
gl: "swiftshader", // Use software rendering to avoid GPU/audio device dependencies
80-
},
8175
});
8276

8377
return outputPath;

0 commit comments

Comments
 (0)