Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xsline OpenChatCut ParseProbe

From Leeroopedia
Knowledge Sources
Domains Media_Analysis, Media_Import, Probing
Last Updated 2026-10-22 14:00 GMT

Overview

Concrete pure function that normalizes raw FFprobe JSON output into a compact `ProbeResult` with dimensions, codecs, frame rate, track flags, and auto-detected quality risks.

Description

The parseProbe function is a pure and total parser — it never throws on malformed input. This makes it safe to run in any context: browser, server, CLI, or offline tests.

It extracts:

  • Duration from format or stream metadata.
  • Width/height from the video stream.
  • Frame rate by parsing rational strings like "30000/1001" into 29.97, preferring `avg_frame_rate` over `r_frame_rate`.
  • Audio/video track presence as boolean flags.
  • Video/audio codec names from stream `codec_name`.
  • Quality risks — heuristically detected:
    • `low_resolution` — width < 720 or height < 480
    • `mono_audio` — single audio channel
    • `very_short` — duration under 3 seconds
    • `variable_frame_rate` — avg and nominal FPS differ by > 0.01
    • `low_frame_rate` — FPS below 20

Usage

  • Import pipeline: Called after `probeMediaFile` to normalize the raw probe output.
  • Browser tool: Used in the browser media tool for client-side probe display.
  • Offline tests: Pure function, no I/O dependencies — ideal for unit testing.

Code Reference

Source Location

Signature

export interface ProbeResult {
  durationSeconds?: number;
  width?: number;
  height?: number;
  fps?: number;
  hasAudioTrack: boolean;
  hasVideoTrack: boolean;
  videoCodec?: string;
  audioCodec?: string;
  qualityRisks: string[];
}

export function parseProbe(json: unknown): ProbeResult;

Import

import { parseProbe, type ProbeResult } from '../shared/media-probe.ts';

I/O Contract

Inputs

Name Type Required Description
json unknown Yes Raw FFprobe JSON (typically Record<string, unknown>)

Outputs

Name Type Description
ProbeResult object Normalized media summary with quality risks

Usage Examples

Parse Raw FFprobe Output

import { parseProbe } from '../shared/media-probe.ts';

const raw = {
  streams: [
    { codec_type: 'video', codec_name: 'h264', width: 1920, height: 1080,
      avg_frame_rate: '30/1', r_frame_rate: '30/1' },
    { codec_type: 'audio', codec_name: 'aac', channels: 2 },
  ],
  format: { duration: '120.5' },
};

const result = parseProbe(raw);
console.log(`${result.width}x${result.height} @ ${result.fps}fps`);
console.log(`Audio: ${result.hasAudioTrack}, Video: ${result.hasVideoTrack}`);
console.log(`Risks: ${result.qualityRisks.join(', ') || 'none'}`);

Safe on Malformed Input

// Never throws — returns safe defaults
const result = parseProbe(null);
console.log(result.hasVideoTrack); // false
console.log(result.qualityRisks);  // []

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment