get_duration: Get the duration of a media file

View source: R/mediainfo.R

get_durationR Documentation

Get the duration of a media file

Description

get_duration() uses the MediaInfo program to look up the duration of a media file. You choose the section of the file and the unit.

Usage

get_duration(
  file,
  section = c("General", "Video", "Audio"),
  unit = c("ms", "sec", "min", "hour")
)

Arguments

file

A character vector of one or more media file paths.

section

A string indicating the MediaInfo section from which to query the duration value. Can be either "General", "Video", or "Audio" (default = "General").

unit

A string indicating whether the duration should be returned in milliseconds ("ms"), seconds ("sec"), minutes ("min"), or hours ("hour") (default = "ms").

Details

The function returns one number for each file. The ⁠probe_*()⁠ functions, mediainfo_query() and mediainfo_template() return tibbles instead.

Value

A double vector (one per file) giving the duration of the specified section in the specified units.

See Also

mediainfo_parameter() for arbitrary MediaInfo fields, and probe_all() to read information with FFprobe.

Other metadata functions: get_frame_rate(), get_height(), get_sample_rate(), get_width(), mediainfo_parameter(), mediainfo_query(), mediainfo_template(), probe_all(), probe_container()

Examples


video <- system.file("extdata", "sample.mp4", package = "tidymedia")
get_duration(video, unit = "sec")


tidymedia documentation built on Oct. 11, 2026, 5:08 p.m.