Skip to main content

probe_media

Probes a media file using FFprobe to extract comprehensive metadata including video/audio/subtitle streams, format information, and technical properties.

Signature

pub async fn probe_media(
    app: AppHandle,
    file_path: String,
) -> Result<ProbeMetadata, ConversionError>

Parameters

filePath
string
required
Absolute path to the media file to probe. File must exist and be readable.

Response

Returns a ProbeMetadata object containing all extracted information.

ProbeMetadata

Format Information

duration
string | null
Total duration of the media file in seconds (as string). Example: "125.482000"
bitrate
string | null
Overall bitrate of the file in bits per second. Example: "2500000"

Video Stream

videoCodec
string | null
Video codec name. Examples: "h264", "hevc", "vp9", "av1"
resolution
string | null
Video resolution as formatted string. Example: "1920x1080"
width
number | null
Video width in pixels. Example: 1920
height
number | null
Video height in pixels. Example: 1080
frameRate
number | null
Video frame rate in frames per second. Example: 29.97
videoBitrateKbps
number | null
Video bitrate in kilobits per second. Example: 2500.0
pixelFormat
string | null
Pixel format. Examples: "yuv420p", "yuv420p10le"
colorSpace
string | null
Color space. Examples: "bt709", "bt2020nc"
colorRange
string | null
Color range. Examples: "tv", "pc"
colorPrimaries
string | null
Color primaries. Examples: "bt709", "bt2020"
profile
string | null
Codec profile. Examples: "High", "Main 10"

Audio Streams

audioCodec
string | null
Primary audio codec (from first audio track). Examples: "aac", "mp3", "opus"
audioTracks
AudioTrack[]
Array of all audio tracks in the file.

Subtitle Streams

subtitleTracks
SubtitleTrack[]
Array of all subtitle tracks in the file.

Metadata Tags

tags
FfprobeTags | null
Container-level metadata tags.

Implementation Details

The probe function (probe.rs:8-133) executes FFprobe with:
ffprobe -v quiet -print_format json -show_format -show_streams {file_path}
It then parses the JSON output and:
  1. Extracts format-level metadata (duration, bitrate, tags)
  2. Identifies and processes the video stream
  3. Collects all audio tracks with their properties
  4. Collects all subtitle tracks
  5. Calculates video bitrate if not directly available (container bitrate - audio bitrates)
  6. Parses frame rate from fraction strings (e.g., "30000/1001"29.97)

Example Usage

import { invoke } from '@tauri-apps/api/core';

interface ProbeMetadata {
  duration: string | null;
  bitrate: string | null;
  videoCodec: string | null;
  audioCodec: string | null;
  resolution: string | null;
  frameRate: number | null;
  width: number | null;
  height: number | null;
  videoBitrateKbps: number | null;
  audioTracks: AudioTrack[];
  subtitleTracks: SubtitleTrack[];
  tags: object | null;
  pixelFormat: string | null;
  colorSpace: string | null;
  colorRange: string | null;
  colorPrimaries: string | null;
  profile: string | null;
}

interface AudioTrack {
  index: number;
  codec: string;
  channels: string;
  language: string | null;
  label: string | null;
  bitrateKbps: number | null;
  sampleRate: string | null;
}

interface SubtitleTrack {
  index: number;
  codec: string;
  language: string | null;
  label: string | null;
}

try {
  const metadata: ProbeMetadata = await invoke('probe_media', {
    filePath: '/path/to/video.mp4'
  });
  
  console.log(`Duration: ${metadata.duration}s`);
  console.log(`Resolution: ${metadata.resolution}`);
  console.log(`Video: ${metadata.videoCodec} @ ${metadata.videoBitrateKbps}kbps`);
  console.log(`Audio: ${metadata.audioCodec}`);
  console.log(`Audio tracks: ${metadata.audioTracks.length}`);
  console.log(`Subtitle tracks: ${metadata.subtitleTracks.length}`);
  
  metadata.audioTracks.forEach((track, i) => {
    console.log(`  Track ${i}: ${track.codec} ${track.channels}ch ${track.language || 'unknown'}`);
  });
} catch (error) {
  console.error('Probe failed:', error);
}

Example Response

{
  "duration": "125.482000",
  "bitrate": "2846289",
  "videoCodec": "h264",
  "audioCodec": "aac",
  "resolution": "1920x1080",
  "frameRate": 29.97,
  "width": 1920,
  "height": 1080,
  "videoBitrateKbps": 2654.3,
  "pixelFormat": "yuv420p",
  "colorSpace": "bt709",
  "colorRange": "tv",
  "colorPrimaries": "bt709",
  "profile": "High",
  "audioTracks": [
    {
      "index": 1,
      "codec": "aac",
      "channels": "2",
      "language": "eng",
      "label": null,
      "bitrateKbps": 192.0,
      "sampleRate": "48000"
    }
  ],
  "subtitleTracks": [
    {
      "index": 2,
      "codec": "mov_text",
      "language": "eng",
      "label": "English"
    }
  ],
  "tags": {
    "title": "Sample Video",
    "creationTime": "2024-01-15T10:30:00.000000Z"
  }
}

Error Handling

Possible errors:
  • Shell - FFprobe sidecar not found or failed to execute
  • Probe - FFprobe returned non-zero exit code (contains stderr)
  • Json - Failed to parse FFprobe JSON output
  • Io - File not accessible or I/O error

Build docs developers (and LLMs) love