MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / extractAudioMetadata

Function extractAudioMetadata

packages/engine/src/utils/ffprobe.ts:351–389  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

349export const extractVideoMetadata = extractMediaMetadata;
350
351export 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
391export interface KeyframeAnalysis {
392 avgIntervalSeconds: number;

Callers 6

defaultProbeAudioInfoFunction · 0.90
resolveMediaDurationFunction · 0.85
ffprobe.test.tsFile · 0.85
processCompositionAudioFunction · 0.85
shouldCopyAacSidecarFunction · 0.85

Calls 6

runFfprobeFunction · 0.85
parseProbeJsonFunction · 0.85
getMethod · 0.80
deleteMethod · 0.80
findMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected