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
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
Total duration of the media file in seconds (as string). Example: "125.482000"
Overall bitrate of the file in bits per second. Example: "2500000"
Video Stream
Video codec name. Examples: "h264", "hevc", "vp9", "av1"
Video resolution as formatted string. Example: "1920x1080"
Video width in pixels. Example: 1920
Video height in pixels. Example: 1080
Video frame rate in frames per second. Example: 29.97
Video bitrate in kilobits per second. Example: 2500.0
Pixel format. Examples: "yuv420p", "yuv420p10le"
Color space. Examples: "bt709", "bt2020nc"
Color range. Examples: "tv", "pc"
Color primaries. Examples: "bt709", "bt2020"
Codec profile. Examples: "High", "Main 10"
Audio Streams
Primary audio codec (from first audio track). Examples: "aac", "mp3", "opus"
Array of all audio tracks in the file. Show AudioTrack properties
Stream index in the container. Example: 1
Audio codec name. Example: "aac"
Channel count or layout. Examples: "2", "6", "stereo"
ISO 639 language code. Examples: "eng", "jpn"
Track title/label. Example: "English Commentary"
Audio bitrate in kilobits per second. Example: 192.0
Sample rate in Hz. Example: "48000"
Subtitle Streams
Array of all subtitle tracks in the file. Show SubtitleTrack properties
Stream index in the container. Example: 3
Subtitle codec. Examples: "subrip", "ass", "mov_text"
ISO 639 language code. Examples: "eng", "spa"
Subtitle track title. Example: "English SDH"
Metadata Tags
Container-level metadata tags. Show FfprobeTags properties
ISO 8601 timestamp. Example: "2024-01-15T10:30:00.000000Z"
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:
Extracts format-level metadata (duration, bitrate, tags)
Identifies and processes the video stream
Collects all audio tracks with their properties
Collects all subtitle tracks
Calculates video bitrate if not directly available (container bitrate - audio bitrates)
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