| normalize_audio | R Documentation |
Normalize the perceived loudness of a file's audio toward an EBU R128 target.
The function uses FFmpeg's single-pass loudnorm filter. It can also
downmix the channel count and resample. The output holds one audio
stream and no video, whatever the input and whatever container
outfile names. So the output of this function is audio, as with
extract_audio and convert_audio. It does not
carry the other streams through. To normalize a recording's soundtrack
and keep its picture, first normalize to an audio file. Then put the
audio back with the picture using the ffmpeg direct command.
The glossary in vignette("tidymedia") explains media terms such as
LUFS, true peak and sample rate.
normalize_audio(
infile,
outfile,
target_loudness = -23,
true_peak = -1,
loudness_range = 7,
channels = NULL,
sample_rate = NULL,
audio_codec = NULL,
two_pass = FALSE,
audio_stream = NULL,
run = TRUE
)
infile |
A string containing the path to a media file (with audio). An input with no audio stream is an FFmpeg error, not a silent copy of the video. |
outfile |
A string containing the path of the audio file to write. The
function accepts any container that FFmpeg can write. The compiled command
does not depend on which container it is. An audio container ( |
target_loudness |
The target integrated loudness, in LUFS
(a number in |
true_peak |
The maximum true peak, in dBTP
(a number in |
loudness_range |
The target loudness range, in LU
(a number in |
channels |
The output channel count, e.g. |
sample_rate |
The output sample rate in Hz, e.g. |
audio_codec |
An optional string naming the output audio encoder (e.g.
|
two_pass |
A logical. When |
audio_stream |
The audio track to normalize, as a number that counts from |
run |
A logical: run the (correction) command through FFmpeg
( |
The default targets follow EBU Recommendation R 128 (2014). They are
target_loudness = -23 LUFS and true_peak = -1 dBTP. Loudness
is measured per ITU-R BS.1770-4. The default loudness_range is
7. This is
single-pass (dynamic) loudnorm. The same input and arguments always
compile to one reproducible command, with no separate measurement pass. The
filter changes the audio, so FFmpeg re-encodes it. Set audio_codec to
name the output encoder, or leave it NULL to use the default of the
output container. Leaving channels at NULL keeps the source
channel layout. FFmpeg's loudnorm filter resamples its output, up to
192 kHz, capped by the encoder. So the output sample rate is not the
source rate unless you set it. Set sample_rate to control the output
rate.
The function warns when no audio_stream is named and infile
carries tracks that the output will not. extract_audio and
convert_audio emit the same warning. Naming a track with
audio_stream silences it, as does
suppressWarnings(classes = "tidymedia_dropped_audio").
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. Under two_pass = TRUE, the
warning comes before the analysis pass. So it arrives while adding
audio_stream can still save that pass.
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.
The compiled FFmpeg command (invisibly when run = TRUE). Under
two_pass = TRUE this is the correction command built from the
measured values.
EBU Recommendation R 128 (2014), Loudness normalisation and permitted maximum level of audio signals; ITU-R BS.1770-4.
ffm_loudnorm(), the pipeline function it wraps.
normalize_audio_batch() for the many-file form.
extract_audio() and convert_audio(), the other task functions whose
output is one audio stream.
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_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(),
extract_audio_batch(),
format_for_web(),
format_for_web_batch(),
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")
# The output holds audio only, so name an audio file for it
normalize_audio(video, "normalized.wav", run = FALSE)
# Normalize to a streaming target and downmix to mono
normalize_audio(video, "mono.wav", target_loudness = -16, channels = 1,
run = FALSE)
# Name the output audio encoder instead of taking the container's default
normalize_audio(video, "normalized.m4a", audio_codec = "aac", run = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.