Skip to contents

Remove a media file's container and global metadata tags, together with any chapters, and write a de-identified copy. The tags include creation time, GPS or other location, device make and model, title and comment. Use it to de-identify research recordings, for example for an IRB (a research ethics board). The audio and video streams are stream-copied, not re-encoded. So the operation is lossless and fast, and the picture and sound are bit-for-bit unchanged. That includes any rotation display matrix, which is stream side data and not a metadata tag. The glossary in vignette("tidymedia") explains media terms such as container, stream and stream copy.

Usage

strip_metadata(infile, outfile, run = TRUE)

Arguments

infile

A string containing the path to a media file.

outfile

A string containing the path of the de-identified file to write. Use the same container extension as infile so the copied streams remux cleanly.

run

A logical: run the command through FFmpeg (TRUE, default) or return the compiled command without running it (FALSE).

Value

The compiled FFmpeg command (invisibly when run = TRUE).

Details

The output is written bit-exactly (-fflags +bitexact). So FFmpeg does not stamp the container again with a fresh creation_time, or with an encoder tag that names its own version. Either tag would defeat de-identification and reproducibility.

Because the streams are copied and not re-encoded, identifiers inside the encoded bitstream are not removed. Removing them requires re-encoding, which is out of scope for this function, so use the direct command ffmpeg for it.

With FFmpeg 9.0.2 on macOS, the source values of per-stream tags such as handler_name and language did not reach the output. An .mp4 output still had both tags, with generic values: handler_name was VideoHandler or SoundHandler, and language was und. An .mkv output had neither tag. Other FFmpeg versions can differ, so if these tags matter, check them in the output with probe_streams.

Examples

video <- system.file("extdata", "sample.mp4", package = "tidymedia")
strip_metadata(video, "clean.mp4", run = FALSE)
#> [1] "-y -i \"/home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4\" -codec:v copy -codec:a copy -map_metadata -1 -map_chapters -1 -fflags +bitexact -map \"0\" \"clean.mp4\""