knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

tidymedia

Lifecycle: experimental

The goal of tidymedia is to provide tools for easily working with media (e.g., image, audio, and video) files within R and the tidyverse.

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("jmgirard/tidymedia")

Dependencies

1. MediaInfo

tidymedia uses MediaInfo to query information about media files. If you would like to use these functions, you will need to install the command line interface (CLI) version of this program. Links and instructions for doing so are available here. Below are instructions for several popular platforms.

Debian/Ubuntu

  1. Enter this code into your terminal:
    sudo apt-get install mediainfo

Windows

  1. Download the appropriate CLI .zip file from:
    https://mediaarea.net/en/MediaInfo/Download/Windows
  2. Extract (or copy) the contents of this .zip file to a folder on your computer such as:
    C:/Program Files/MediaInfo
  3. Run the following code in R (changing the path to match Step 2):
    tidymedia::set_mediainfo("C:/Program Files/MediaInfo/mediainfo.exe")

Mac

  1. Download the appropriate CLI .dmg file from:
    https://mediaarea.net/en/MediaInfo/Download/Mac_OS
  2. Open the .dmg file and drag the program icon to the Applications folder

2. FFmpeg

tidymedia uses FFmpeg to encode media files. If you would like to use these functions, you will need to install the command line interface (CLI) version of this program. Links and instructions for doing so are available here. Below are instructions for several popular platforms.

Debian/Ubuntu

  1. Enter this code into your terminal:
    sudo apt-get install ffmpeg

Windows

  1. Install the tidymedia package in R.
  2. Run tidymedia::install_on_win() in R.

macOS Homebrew Install

  1. Open the macOS Terminal or Linux shell prompt.
  2. Install Homebrew by entering this code into your terminal:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  3. Enter this code into your terminal:
    brew install ffmpeg

macOS Manual Install

  1. Download the latest snapshot version from:
    https://evermeet.cx/ffmpeg/get
  2. Extract the contents of the downloaded .7z file
  3. Drag the extracted contents to the Applications folder

Examples

library(tidymedia)

MediaInfo

# Interface with the mediainfo CLI
mediainfo("--Version")
# Create a row tibble using a built-in template
mediainfo_template(file = "C:/example.m4v", template = "brief")
knitr::kable(mediainfo_template(file = "C:/example.m4v", template = "brief"))
# Create a row tibble from specific parameters
mediainfo_query(
  file = "C:/example.m4v", 
  section = "Video", 
  parameters = c("Width", "Height", "DisplayAspectRatio")
)
knitr::kable(mediainfo_query(
  file = "C:/example.m4v", 
  section = "Video", 
  parameters = c("Width", "Height", "DisplayAspectRatio")
))
# Lookup common parameters
get_duration(file = "C:/example.m4v", unit = "sec")
get_height(file = "C:/example.m4v")

FFmpeg

# Interface with the mediainfo CLI
ffmpeg("-version")
# Query information about codecs from FFmpeg
get_codecs()
# Query information about encoders from FFmpeg
get_encoders()
# Create ffmpeg commands by pipeline
ffm(input = "C:/example.m4v", output = "C:/example2.m4v") |>
  ffm_trim(start = 1, end = 5) |> 
  ffm_crop(width = 640, height = 480) |>  
  ffm_codec(video = "libx264") |>
  ffm_drop(streams = "audio") |> 
  ffm_compile()
# Run ffmpeg commands by pipeline
ffm(input = "C:/example.m4v", output = "C:/example2.m4v") |> 
  ffm_trim(start = 1, end = 5) |> 
  ffm_crop(width = 640, height = 480) |> 
  ffm_codec(video = "libx264") |>
  ffm_drop(streams = "audio") |> 
  ffm_run()

Code of Conduct

Please note that the tidymedia project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.



jmgirard/tidymedia documentation built on June 15, 2024, 1:52 p.m.