media assets: save audio volume levels in media metadata.

For videos with sound, save information about audio volume levels in the
media asset's metadata. These values are stored:

* FFmpeg:AudioPeakLoudness       The peak loudness of the audio track, from 0.0 (silent) to 1.0 (max volume)
* FFmpeg:AudioAverageLoudness    The average loudness of the audio track, from 0.0 (silent) to 1.0 (max volume).
* FFmpeg:AudioLoudnessRange      The difference between the quietest and loudest sounds in the audio track (in decibels).
* FFmpeg:AudioSilencePercentage  The percentage of the video that is silent (1.0 is completely silent, 0.5 is 50% silence, 0.0 is no silence).

These values are calculated based on the EBU R 128 standard, using the ffmpeg command below:

  ffmpeg -i file.mp4 -af silencedetect=duration=0.05:noise=0.0001,ebur128=metadata=1:peak=true:dualmono=true -f null /dev/null

See the links below for details:

* https://en.wikipedia.org/wiki/EBU_R_128
* https://www.ffmpeg.org/ffmpeg-filters.html#ebur128-1
* https://tech.ebu.ch/loudness
* https://tech.ebu.ch/docs/tech/tech3341.pdf
This commit is contained in:
evazion
2022-11-04 17:01:11 -05:00
parent a244ec5a3b
commit e005520ad8
5 changed files with 169 additions and 4 deletions

View File

@@ -5,7 +5,10 @@
#
# @see https://github.com/streamio/streamio-ffmpeg
class MediaFile::Video < MediaFile
delegate :duration, :frame_count, :frame_rate, :has_audio?, :is_corrupt?, :major_brand, :pix_fmt, :video_codec, :video_bit_rate, :video_stream, :video_streams, :audio_codec, :audio_bit_rate, :audio_stream, :audio_streams, :error, to: :video
delegate :duration, :frame_count, :frame_rate, :has_audio?, :is_corrupt?, :major_brand, :pix_fmt,
:video_codec, :video_bit_rate, :video_stream, :video_streams, :audio_codec, :audio_bit_rate,
:audio_stream, :audio_streams, :silence_duration, :silence_percentage, :average_loudness,
:peak_loudness, :loudness_range, :error, to: :video
def dimensions
[video.width, video.height]
@@ -28,6 +31,10 @@ class MediaFile::Video < MediaFile
"FFmpeg:AudioProfile" => audio_stream[:profile],
"FFmpeg:AudioLayout" => audio_stream[:channel_layout],
"FFmpeg:AudioBitRate" => audio_bit_rate,
"FFmpeg:AudioPeakLoudness" => peak_loudness,
"FFmpeg:AudioAverageLoudness" => average_loudness,
"FFmpeg:AudioLoudnessRange" => loudness_range,
"FFmpeg:AudioSilencePercentage" => silence_percentage,
}.compact_blank)
end