| anonymize_video | R Documentation |
Anonymize a video by covering one or more fixed rectangular regions with
opaque filled boxes. For example, you can redact a face, a name badge, or a
screen that stays in one place for the whole clip. The regions are fixed
(there is no face or object tracking), so this suits footage where the areas
to cover do not move. The glossary in vignette("tidymedia") explains
media terms such as codec, pixel format and stream copy.
anonymize_video(
infile,
outfile,
regions,
color = "black",
video_codec = "libx264",
audio_codec = "copy",
pixel_format = "yuv420p",
hardware = c("none", "nvenc", "videotoolbox"),
fallback = FALSE,
quality = NULL,
audio_stream = NULL,
run = TRUE
)
infile |
A string containing the path to a video file. |
outfile |
A string containing the path of the video file to write. |
regions |
A data frame with one row per box and columns |
color |
A string naming the default fill color in FFmpeg color syntax,
used for any row without its own |
video_codec |
A string naming the output video codec (default
|
audio_codec |
A string naming the output audio codec. The default
|
pixel_format |
A string naming the output pixel format (default
|
hardware |
The encoder backend. |
fallback |
A logical. When a |
quality |
A number, or |
audio_stream |
The audio track to carry into the output, as a number that counts from |
run |
A logical: run the command through FFmpeg ( |
regions is a data frame with one row per box and the columns
x, y, width, and height. Each value is a pixel
number or an FFmpeg expression such as "in_w/2". x and
y give the top-left corner, and width and height give
the size. An optional
color column overrides the color argument for that row. Every
box is a solid fill (FFmpeg's drawbox with t=fill). The
function intentionally does not offer hollow outlines.
Because the function applies a filter, it re-encodes the video. The
video_codec and pixel_format arguments set the encoding, and
default to H.264 and yuv420p. The function floors odd source
dimensions to even, so the output always encodes. yuv420p and
libx264 require even dimensions, and the step changes nothing for
input that is already even. The function stream-copies the audio unchanged
(-c:a copy) unless
audio_codec names an encoder. The same input and regions therefore
always compile to a byte-identical command.
The compiled FFmpeg command (invisibly when run = TRUE).
https://ffmpeg.org/ffmpeg-filters.html#drawbox
ffm_drawbox(), the pipeline function it wraps;
has_hardware_encoder() for the
hardware argument; anonymize_video_batch()
for the many-file (batch) form.
Other task functions:
anonymize_video_batch(),
compare_videos(),
compare_videos_batch(),
concatenate_videos(),
concatenate_videos_batch(),
convert_audio(),
convert_audio_batch(),
crop_video(),
crop_video_batch(),
extract_audio(),
extract_audio_batch(),
extract_frame(),
extract_frame_batch(),
format_for_web(),
format_for_web_batch(),
normalize_audio(),
normalize_audio_batch(),
picture_in_picture(),
picture_in_picture_batch(),
sample_frames(),
sample_frames_batch(),
segment_video(),
segment_video_batch(),
separate_audio_video(),
separate_audio_video_batch(),
standardize_video(),
standardize_video_batch(),
strip_metadata(),
strip_metadata_batch()
Other audio selection functions:
anonymize_video_batch(),
audio_stream,
compare_videos(),
compare_videos_batch(),
convert_audio(),
convert_audio_batch(),
crop_video(),
crop_video_batch(),
extract_audio(),
extract_audio_batch(),
format_for_web(),
format_for_web_batch(),
normalize_audio(),
normalize_audio_batch(),
picture_in_picture(),
picture_in_picture_batch(),
segment_video(),
segment_video_batch(),
separate_audio_video(),
separate_audio_video_batch(),
standardize_video(),
standardize_video_batch()
video <- system.file("extdata", "sample.mp4", package = "tidymedia")
# Cover two fixed regions with black boxes
regions <- data.frame(
x = c(10, 200), y = c(10, 150),
width = c(120, 80), height = c(90, 60)
)
anonymize_video(video, "anon.mp4", regions, run = FALSE)
# Carry only the second audio track instead of all of them
anonymize_video(video, "anon.mp4", regions, audio_stream = 1, run = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.