Skip to content

Commit

Permalink
Don't throw an error if ffprobe fails - instead default to whisperx
Browse files Browse the repository at this point in the history
  • Loading branch information
philmcmahon committed Feb 24, 2025
1 parent ae48da5 commit c8302cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/backend-common/src/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import { promisify } from 'node:util';

const execPromise = promisify(exec);

export const getFileDuration = async (filePath: string): Promise<number> => {
export const getFileDuration = async (
filePath: string,
): Promise<number | undefined> => {
const command = `ffprobe -i ${filePath} -show_entries format=duration -v quiet -of csv="p=0"`;
try {
const { stdout, stderr } = await execPromise(command);
if (stderr) {
logger.error(` ffprobe stderr: `, stderr);
logger.error(`ffprobe stderr: `, stderr);
}
return parseFloat(stdout);
} catch (error) {
logger.error(`Error during ffprobe file duration detection`, error);
throw error;
return undefined;
}
};
5 changes: 3 additions & 2 deletions packages/backend-common/src/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const generateOutputSignedUrlAndSendMessage = async (
languageCode: InputLanguageCode,
translationRequested: boolean,
diarizationRequested: boolean,
duration: number,
duration?: number,
): Promise<SendResult> => {
const signedUrls = await generateOutputSignedUrls(
s3Key,
Expand All @@ -81,7 +81,8 @@ export const generateOutputSignedUrlAndSendMessage = async (
);

const engine =
config.app.useWhisperx && (duration > 600 || diarizationRequested)
config.app.useWhisperx &&
(!duration || duration > 600 || diarizationRequested)
? TranscriptionEngine.WHISPER_X
: TranscriptionEngine.WHISPER_CPP;

Expand Down

0 comments on commit c8302cc

Please sign in to comment.