Skip to contents

Probe a media file and check its structural metadata against a set of expectations, returning a tidy pass/fail tibble with one row per checked property. A reproducible command tells you what ran. This function tells you whether the result is what you asked for. Use it after a conversion to confirm that the output has the duration, dimensions, codecs and other properties the pipeline was meant to produce.

Usage

verify_media(
  file,
  duration = NULL,
  width = NULL,
  height = NULL,
  video_codec = NULL,
  audio_codec = NULL,
  sample_rate = NULL,
  ...,
  tolerance = 0.1
)

Arguments

file

A string naming a single media file to verify.

duration

Expected container duration in seconds (numeric).

width, height

Expected video-frame dimensions in pixels (numeric).

video_codec, audio_codec

Expected codec names for the first video and audio stream (strings, e.g. "h264", "aac").

sample_rate

Expected audio sample rate in Hz (numeric).

...

Further expectations given as name = value, each checked against the FFprobe field of that name (container first, then video, then audio).

tolerance

The absolute tolerance for numeric checks (default 0.1).

Value

A tibble with one row per checked property and columns file, check, expected, actual, and pass (logical).

Details

The glossary in vignette("tidymedia") explains media terms such as codec, stream and keyframe.

Checks are structural (drawn from FFprobe metadata), not perceptual: this does not measure visual or audio quality. The named arguments cover the most common properties; pass any other FFprobe field by name through ... (for example pix_fmt = "yuv420p" or bit_rate = 141800). Extra names are resolved against the probe columns in the order container, then video stream, then audio stream, and the first match wins.

Numeric checks pass when abs(actual - expected) <= tolerance. With the default tolerance of 0.1, whole-number properties (width, height, sample rate) must match exactly. The duration check allows a small difference, for example for cuts that snap to a keyframe. String checks (the codecs) must match exactly. A property whose stream or column is absent yields an NA actual value and a failing check.

See also

ffm_run() and ffm_batch(), which accept a verify = spec.

Other verification functions: ffm_manifest()

Examples

video <- system.file("extdata", "sample.mp4", package = "tidymedia")
verify_media(video, width = 320, height = 240, video_codec = "h264")
#> # A tibble: 3 × 5
#>   file                                               check expected actual pass 
#>   <chr>                                              <chr> <chr>    <chr>  <lgl>
#> 1 /home/runner/work/_temp/Library/tidymedia/extdata… width 320      320    TRUE 
#> 2 /home/runner/work/_temp/Library/tidymedia/extdata… heig… 240      240    TRUE 
#> 3 /home/runner/work/_temp/Library/tidymedia/extdata… vide… h264     h264   TRUE