Re-encode many files to a reproducible format, using one jobs table. This is
the batch form of standardize_video(), for when you have more than one
video to standardize. Each row is one input, and the only required column
names its source. The function is a thin wrapper over
ffm_batch. It builds one reproducible command for each input.
The glossary in vignette("tidymedia") explains media terms such as
codec, pixel format and frame rate.
Usage
standardize_video_batch(
jobs,
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,
parallel = FALSE,
...
)Arguments
- jobs
A data frame with one row per input. It needs at least an
inputcolumn, the source path. An optionaloutputcolumn names the destination. Without it, each row's output name adds_standardizedto the input's base name and keeps its extension. For example,clip.mkvbecomesclip_standardized.mkv. Two rows naming the same output path are refused before any row runs. That is a path repeated in theoutputcolumn, or a repeatedinputwhen there is nooutputcolumn. A column can override any of the six format arguments for each row:width,height,fps,video_codec,audio_codecandpixel_format. An argument with no column applies its value to every row. In either codec column,NAleaves that row's codec unset. That is the column form ofvideo_codec = NULLoraudio_codec = NULL. In awidth,height,fpsorpixel_formatcolumn,NAis an error.pixel_formathas no unset state to express.width,heightandfpsdo acceptNULLas arguments, but their columns have noNAform for it. Anaudio_streamcolumn overrides theaudio_streamargument for each row, andNAkeeps that row on every audio track. A numericqualitycolumn overrides thequalityargument per row (seequality). Any other columns are ignored.- width, height
Optional target dimensions for every row, unless
jobshas a column of the same name (seejobs). When only one is given, the other is derived to keep the aspect ratio. When neither is given, the frame is floor-cropped to even dimensions, so odd-sized sources encode. (default =NULL)- fps
Optional target frame rate applied to every row, unless
jobscarries anfpscolumn. (default =NULL, i.e. leave the frame rate unchanged)- video_codec
A string naming the video codec for every row, unless
jobshas avideo_codeccolumn. In that column,NAleaves that row's codec unset. The default is"libx264".NULLemits no-codec:vand lets the output container's default encoder decide. For a.webmoutput, passaudio_codec = NULLtoo, because the default"copy"would otherwise carry a codec WebM cannot hold.- audio_codec
A string naming the audio codec for every row, unless
jobshas anaudio_codeccolumn. In that column,NAleaves that row's codec unset."copy"(default) stream-copies the audio through untouched. Name an encoder, such as"aac", when the source audio cannot be copied into the output container.- pixel_format
A string naming the pixel format applied to every row, unless
jobscarries apixel_formatcolumn. (default ="yuv420p")- hardware
The encoder backend for every row.
"none"is the default."nvenc"uses NVIDIA GPU encoding (H.264, HEVC and AV1), and"videotoolbox"uses Apple GPU encoding (H.264 and HEVC). It applies to the whole batch and is not read as a column. Seestandardize_videoandhas_hardware_encoder. Resolving a hardware backend asks this FFmpeg build which encoders it has. So the first such call that re-encodes the video runs FFmpeg while the command is built, even underrun = FALSE. The answer is remembered for the rest of the R session. Seerefresh_ffmpeg_capabilitiesto discard it. This function checks that the encoder is available before any row runs. So an unavailable encoder aborts naming this function, not the internal step that runs the rows.- fallback
A logical. When a
hardwareother than"none"is requested but its encoder is unavailable,TRUEre-encodes with the softwarevideo_codecand a message.FALSE(default) aborts instead. Avideo_codecin a family that the backend has no encoder for is a wrong argument, not an absent encoder. So it aborts whateverfallbacksays.- quality
A number, or
NULL(default), applied to each row unlessjobscarries a numericqualitycolumn. In that column,NAleaves that row's encoder default in place, whatever the argument says. The value is the encoder's own rate-control value, passed through unchanged. Each cell is checked against the encoder its own row resolves to. A wrong cell is refused before any row runs, and the error names this function and the row. Seestandardize_video()for the encoders, their flags and ranges, and the values it refuses.- audio_stream
The audio track to carry into each output, as a number that counts from
0among the audio tracks of each row's input.0is the first audio track and1is the second. Other streams in the file, such as video, do not count.NULL(default) carries every audio track. Without anaudio_streamcolumn, the argument applies to every row. AnNAcell in that column meansNULLfor that row. It does not fall back to the argument. The every-track family readsNULLas every audio track:separate_audio_video,standardize_video,anonymize_video,crop_video,segment_videoandformat_for_web, and their_batchforms. The first-track family reads it as the first audio track only:extract_audio,convert_audioandnormalize_audio, and their_batchforms. The function does not carry subtitle or data streams in either case. A track the input does not have gives an FFmpeg error, not an R one. Seeaudio_streamfor how this differs fromaudio_input, the input index oncompare_videosandpicture_in_picture. (default =NULL)- run
A logical: run each input's command through FFmpeg (
TRUE, default) or only compile them for inspection (FALSE).- parallel
A logical passed to
ffm_batch: standardize in parallel with furrr (TRUE) or sequentially (FALSE, default). Parallelism follows the activefutureplan;TRUEunder the default sequential plan runs one input at a time and warns. Set a plan first, e.g.future::plan(future::multisession).- ...
Additional arguments forwarded to
ffm_batch, such asverify,manifest,checksums, andprogress.
Value
The tibble returned by ffm_batch: jobs with an added command column. When output was derived, it also has the resolved output column. When run = TRUE, it has a success column, plus any columns the forwarded arguments add, such as verified.
See also
standardize_video() for the single-input form; ffm_batch() for
the batch runner and the arguments forwarded through ...;
segment_video_batch() and extract_frame_batch() for the other batch
task functions.
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(),
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()
Examples
video <- system.file("extdata", "sample.mp4", package = "tidymedia")
jobs <- tibble::tibble(
input = c(video, video),
output = c("a.mp4", "b.mp4"),
width = c(640, 320)
)
# run = FALSE compiles one command per input without calling FFmpeg
standardize_video_batch(jobs, run = FALSE)
#> # A tibble: 2 × 4
#> input output width command
#> <chr> <chr> <dbl> <chr>
#> 1 /home/runner/work/_temp/Library/tidymedia/extdata/sample… a.mp4 640 "-y -i…
#> 2 /home/runner/work/_temp/Library/tidymedia/extdata/sample… b.mp4 320 "-y -i…