| standardize_video | R Documentation |
Re-encode a video to a consistent, reproducible format for analysis. The
format is one video codec and pixel format, and optionally a resolution and
frame rate, with +faststart for smooth playback.
format_for_web uses a fixed recipe for web delivery. Here,
every part of the standard is an argument. So a lab can set its own house
format once and apply it across a dataset. The glossary in
vignette("tidymedia") explains media terms such as codec, pixel format
and frame rate.
standardize_video(
infile,
outfile,
width = NULL,
height = NULL,
fps = NULL,
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. |
width |
The output width in pixels (a positive number), or |
height |
The output height in pixels (a positive number), or |
fps |
The output frame rate (a positive number or FFmpeg framerate
expression such as |
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 ( |
The default standard, standardize_video(infile, outfile), re-encodes
to H.264 video (video_codec = "libx264") with
pixel_format = "yuv420p" and -movflags +faststart. It keeps
the source resolution and frame rate. Audio is stream-copied unchanged
(-c:a copy) unless audio_codec names an encoder. The same
input therefore always compiles to a byte-identical command. Loudness
standardization is out of scope. For that, see
normalize_audio.
Resolution follows width and height:
With both, the output has exactly those dimensions.
With only one, the aspect ratio is kept, and the other dimension is
rounded to the nearest even number (FFmpeg's -2).
With neither, the source resolution is kept, but odd dimensions are
rounded down to the nearest even value. yuv420p and
libx264 require this, and it changes nothing for input that is
already even. So the output always encodes.
The compiled FFmpeg command (invisibly when run = TRUE).
ffm_scale(), ffm_codec(), and ffm_pixel_format(), among the
pipeline functions it wraps; has_hardware_encoder() for the
hardware toggle;
standardize_video_batch() for the many-file form.
Other task functions:
anonymize_video(),
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_batch(),
strip_metadata(),
strip_metadata_batch()
Other audio selection functions:
anonymize_video(),
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_batch()
video <- system.file("extdata", "sample.mp4", package = "tidymedia")
# The documented default standard (H.264 / yuv420p / +faststart)
standardize_video(video, "std.mp4", run = FALSE)
# Pin resolution and frame rate too
standardize_video(video, "std.mp4", width = 1280, height = 720, fps = 30,
run = FALSE)
# Carry only the second audio track instead of all of them
standardize_video(video, "std.mp4", audio_stream = 1, run = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.