Write the audio stream of infile into outfile. By default
(audio_codec = NULL), the output format follows the outfile
file extension, at the highest VBR quality (-q:a 0). For example, an
.mp3 extension gives an MP3. Pass audio_codec to set the output
audio codec yourself, whatever the extension is. The glossary in
vignette("tidymedia") explains media terms such as codec and stream.
Arguments
- infile
A string containing the path to a media file.
- outfile
A string containing the path of the audio file to write.
- audio_codec
An optional string naming the output audio codec (e.g.
"libmp3lame","aac","flac"), passed to FFmpeg's-c:a. WhenNULL(default), FFmpeg infers the codec from theoutfileextension and encodes at the highest VBR quality. On the other task functions,NULLmeans "leave the codec unset". HereNULLdoes not leave the codec unset.NULLselects-q:a 0.- audio_stream
The audio track to take, as a number that counts from
0among the audio tracks of the 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. The first-track family readsNULLthis way: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 the command through FFmpeg (
TRUE, default) or return the compiled command without running it (FALSE).
Details
When infile has more than one audio track, audio_stream names
which one to take. With no audio_stream, the function takes the
first one.
When no audio_stream is named and the input has tracks that the output will not carry, the function warns. The check costs one FFprobe call per distinct input, which is one call here, because this function takes a single infile. The warning is given when FFprobe is available and the input can be probed. Otherwise the check is skipped silently. It never runs under run = FALSE, and never changes the compiled command. Suppress it by naming a track with audio_stream, or by class with suppressWarnings(classes = "tidymedia_dropped_audio").
To switch the check off and skip its FFprobe call, 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
ffm_codec() and ffm_map(), the pipeline functions it wraps.
extract_audio() to copy audio without re-encoding.
convert_audio_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_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(),
anonymize_video_batch(),
audio_stream,
compare_videos(),
compare_videos_batch(),
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()
Examples
video <- system.file("extdata", "sample.mp4", package = "tidymedia")
convert_audio(video, "audio.mp3", run = FALSE)
#> [1] "-y -i \"/home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4\" -q:a 0 -map \"0:a:0\" \"audio.mp3\""
convert_audio(video, "audio.m4a", audio_codec = "aac", run = FALSE)
#> [1] "-y -i \"/home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4\" -codec:a aac -map \"0:a:0\" \"audio.m4a\""
# Convert the second audio track instead of the first
convert_audio(video, "audio.mp3", audio_stream = 1, run = FALSE)
#> [1] "-y -i \"/home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4\" -q:a 0 -map \"0:a:1\" \"audio.mp3\""