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, some data is not removed. Those are identifiers inside the encoded bitstream, and per-stream metadata such as handler_name or language. Removing them would require one of two things. One is re-encoding, which is out of scope for this function, so use the direct command ffmpeg for it. The other is per-stream metadata mapping that must probe the file first.

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\""