Throw on invalid ffprobe duration, remove prefetch
Remove prefetching of video duration from the initial Promise.all and change getDuration to stop swallowing errors: it now throws when ffprobe returns a non-numeric duration (including the raw stdout in the error) instead of returning a default 60s. This prevents silently masking ffprobe failures — callers should handle or catch errors from getDuration.
This commit is contained in:
1 parent
59bd457a97
commit
973ccaebed
1 file changed
+16
-15
@@ -101,7 +101,6 @@ export class FFmpegExecAdapter implements IFFmpegAdapter {
|
|||||||
// 获取文件大小和类型
|
// 获取文件大小和类型
|
||||||
const [fileType, duration] = await Promise.all([
|
const [fileType, duration] = await Promise.all([
|
||||||
fileTypeFromFile(videoPath).catch(() => null),
|
fileTypeFromFile(videoPath).catch(() => null),
|
||||||
this.getDuration(videoPath),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 创建临时缩略图路径
|
// 创建临时缩略图路径
|
||||||
@@ -136,22 +135,24 @@ export class FFmpegExecAdapter implements IFFmpegAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取时长
|
* 获取时长
|
||||||
*/
|
*/
|
||||||
async getDuration (filePath: string): Promise<number> {
|
async getDuration(filePath: string): Promise<number> {
|
||||||
try {
|
const { stdout } = await execFileAsync(this.ffprobePath, [
|
||||||
const { stdout } = await execFileAsync(this.ffprobePath, [
|
"-v",
|
||||||
'-v', 'error',
|
"error",
|
||||||
'-show_entries', 'format=duration',
|
"-show_entries",
|
||||||
'-of', 'default=noprint_wrappers=1:nokey=1',
|
"format=duration",
|
||||||
filePath,
|
"-of",
|
||||||
]);
|
"default=noprint_wrappers=1:nokey=1",
|
||||||
|
filePath,
|
||||||
|
]);
|
||||||
|
|
||||||
const duration = parseFloat(stdout.trim());
|
const duration = parseFloat(stdout.trim());
|
||||||
return isNaN(duration) ? 60 : duration;
|
if (isNaN(duration)) {
|
||||||
} catch {
|
throw new Error(`ffprobe 返回了无效的时长值: "${stdout.trim()}"`);
|
||||||
return 60; // 默认时长
|
|
||||||
}
|
}
|
||||||
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user