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

Function extractMediaMetadata

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

Source from the content-addressed store, hash-verified

254 * can be used uniformly for any visual asset the HDR pipeline encounters.
255 */
256export async function extractMediaMetadata(filePath: string): Promise<VideoMetadata> {
257 const cached = videoMetadataCache.get(filePath);
258 if (cached) return cached;
259
260 const probePromise = (async (): Promise<VideoMetadata> => {
261 const stillImageMeta = extractStillImageMetadata(filePath);
262
263 let output: FFProbeOutput | null = null;
264 try {
265 const stdout = await runFfprobe([
266 "-v",
267 "quiet",
268 "-print_format",
269 "json",
270 "-show_format",
271 "-show_streams",
272 filePath,
273 ]);
274 output = parseProbeJson(stdout);
275 } catch (error) {
276 if (!stillImageMeta) throw error;
277 }
278
279 const videoStream = output?.streams.find((s) => s.codec_type === "video");
280 if (!videoStream) {
281 if (stillImageMeta) {
282 return {
283 durationSeconds: 0,
284 videoStreamDurationSeconds: 0,
285 width: stillImageMeta.width,
286 height: stillImageMeta.height,
287 fps: 0,
288 videoCodec: "png",
289 hasAudio: false,
290 isVFR: false,
291 hasAlpha: false,
292 colorSpace: stillImageMeta.colorSpace,
293 };
294 }
295 throw new Error("[FFmpeg] No video stream found");
296 }
297
298 const rFps = parseFrameRate(videoStream.r_frame_rate);
299 const avgFps = parseFrameRate(videoStream.avg_frame_rate);
300 const fps = avgFps || rFps;
301 // VFR: r_frame_rate (max/nominal) differs from avg_frame_rate (actual average) by >10%
302 const isVFR = rFps > 0 && avgFps > 0 && Math.abs(rFps - avgFps) / Math.max(rFps, avgFps) > 0.1;
303
304 const colorTransfer = videoStream.color_transfer || "";
305 const colorPrimaries = videoStream.color_primaries || "";
306 const colorSpaceVal = videoStream.color_space || "";
307 const ffprobeColorSpace =
308 colorTransfer || colorPrimaries || colorSpaceVal
309 ? { colorTransfer, colorPrimaries, colorSpace: colorSpaceVal }
310 : null;
311 const colorSpace = ffprobeColorSpace ?? stillImageMeta?.colorSpace ?? null;
312 const pixelFormat = videoStream.pix_fmt || "";
313 const alphaMode = readTagCI(videoStream.tags, "alpha_mode");

Callers 9

runExtractVideosStageFunction · 0.90
runTestSuiteFunction · 0.85
resolveMediaDurationFunction · 0.85
compileForRenderFunction · 0.85
ffprobe.test.tsFile · 0.85
extractVideoFramesRangeFunction · 0.85
extractAllVideoFramesFunction · 0.85
shouldUseVp9AlphaDecoderFunction · 0.85

Calls 10

runFfprobeFunction · 0.85
parseProbeJsonFunction · 0.85
readTagCIFunction · 0.85
getMethod · 0.80
absMethod · 0.80
deleteMethod · 0.80
parseFrameRateFunction · 0.70
findMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected