Take the audio track out of many input files, using one jobs table. This is
the batch form of extract_audio(), for when you have more than one
file. Each row is one input. The input and output columns are
required. The function is a thin wrapper over ffm_batch. It
builds one reproducible command for each input, with the same steps as
extract_audio(): select the audio track and drop the video. The
glossary in vignette("tidymedia") explains media terms such as codec,
container and stream copy.
Usage
extract_audio_batch(
jobs,
audio_codec = "copy",
audio_stream = NULL,
run = TRUE,
parallel = FALSE,
...
)Arguments
- jobs
A data frame with one row per input. It needs at least an
inputcolumn (source path) and anoutputcolumn (destination path). Theoutputcolumn is required. Unlike the video batch functions, this function cannot name an audio destination for you, because the extension is the instruction. The extension picks the container, and withaudio_codec = "copy"it must match the source codec. An optionalaudio_codeccolumn overrides theaudio_codecargument per row. Rows without a value use the argument.NAin a cell leaves that row's codec unset, which is the column form ofaudio_codec = NULL. An optionalaudio_streamcolumn overrides theaudio_streamargument per row in the same way, andNAkeeps that row on the first audio track. The function refuses two rows with the sameoutputpath, before any row runs. The function ignores any other columns.- audio_codec
The audio codec applied to every row, unless
jobshas anaudio_codeccolumn. In that column,NAin a cell leaves that row's codec unset."copy"(default) copies the audio stream with no quality loss. Name an encoder (e.g."aac") to re-encode. Or passNULLto write no-codec:a, so the output container's default encoder decides.- audio_stream
The audio track to take, 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) takes the first 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 first-track family readsNULLas the first audio track only:extract_audio,convert_audioandnormalize_audio, and their_batchforms. The every-track family reads it as every audio track:separate_audio_video,standardize_video,anonymize_video,crop_video,segment_videoandformat_for_web, and their_batchforms. 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 command through FFmpeg (
TRUE, default) or only compile them for inspection (FALSE).- parallel
A logical: process the jobs in parallel with furrr (
TRUE) or one at a time (FALSE, default). Seeffm_batchfor the future plan requirement.- ...
Additional arguments forwarded to
ffm_batch(e.g.verify,manifest,progress).
Value
The jobs tibble with an added command column. When run = TRUE, it also has a success column, plus verified or a provenance manifest, each when requested through .... See ffm_batch.
Details
When a row names no audio_stream and its input has tracks that the output will not carry, the function warns once for the whole batch. The warning names every affected row. The check costs one FFprobe call per distinct input it has to probe. A repeated input is probed once, and a row that names a track is not probed at all. The warning is given when FFprobe is available and the input can be probed. Otherwise the check is skipped silently. Those probes run one at a time, before any row starts, so parallel does not reach them. A sweep long enough to look like a hang reports its progress. The check never runs under run = FALSE, never changes any compiled command, and is skipped entirely when every row names a track. Suppress it by class with suppressWarnings(classes = "tidymedia_dropped_audio").
To switch the check off and skip the whole sweep, use options(tidymedia.check_tracks = FALSE) for the session. Use withr::local_options(tidymedia.check_tracks = FALSE) for the rest of one function.
See also
extract_audio(), the single-input form it wraps. ffm_batch(),
the batch runner. convert_audio_batch() to re-encode audio in batch.
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_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(),
anonymize_video_batch(),
audio_stream,
compare_videos(),
compare_videos_batch(),
convert_audio(),
convert_audio_batch(),
crop_video(),
crop_video_batch(),
extract_audio(),
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()
Examples
video <- system.file("extdata", "sample.mp4", package = "tidymedia")
jobs <- tibble::tibble(input = c(video, video), output = c("a.aac", "b.aac"))
extract_audio_batch(jobs, run = FALSE)
#> # A tibble: 2 × 3
#> input output command
#> <chr> <chr> <chr>
#> 1 /home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4 a.aac "-y -i \"…
#> 2 /home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4 b.aac "-y -i \"…