(filePath: string)
| 349 | export const extractVideoMetadata = extractMediaMetadata; |
| 350 | |
| 351 | export async function extractAudioMetadata(filePath: string): Promise<AudioMetadata> { |
| 352 | const cached = audioMetadataCache.get(filePath); |
| 353 | if (cached) return cached; |
| 354 | |
| 355 | const probePromise = (async (): Promise<AudioMetadata> => { |
| 356 | const stdout = await runFfprobe([ |
| 357 | "-v", |
| 358 | "quiet", |
| 359 | "-print_format", |
| 360 | "json", |
| 361 | "-show_format", |
| 362 | "-show_streams", |
| 363 | filePath, |
| 364 | ]); |
| 365 | const output = parseProbeJson(stdout); |
| 366 | const audioStream = output.streams.find((s) => s.codec_type === "audio"); |
| 367 | if (!audioStream) throw new Error("[FFmpeg] No audio stream found"); |
| 368 | |
| 369 | const durationSeconds = output.format.duration ? parseFloat(output.format.duration) : 0; |
| 370 | const streamDuration = audioStream.duration ? parseFloat(audioStream.duration) : undefined; |
| 371 | |
| 372 | return { |
| 373 | durationSeconds, |
| 374 | streamDurationSeconds: streamDuration && streamDuration > 0 ? streamDuration : undefined, |
| 375 | sampleRate: audioStream.sample_rate ? parseInt(audioStream.sample_rate) : 44100, |
| 376 | channels: audioStream.channels || 2, |
| 377 | audioCodec: audioStream.codec_name || "unknown", |
| 378 | bitrate: output.format.bit_rate ? parseInt(output.format.bit_rate) : undefined, |
| 379 | }; |
| 380 | })(); |
| 381 | |
| 382 | audioMetadataCache.set(filePath, probePromise); |
| 383 | probePromise.catch(() => { |
| 384 | if (audioMetadataCache.get(filePath) === probePromise) { |
| 385 | audioMetadataCache.delete(filePath); |
| 386 | } |
| 387 | }); |
| 388 | return probePromise; |
| 389 | } |
| 390 | |
| 391 | export interface KeyframeAnalysis { |
| 392 | avgIntervalSeconds: number; |
no test coverage detected