diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-04-13 14:39:51 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-04-13 14:39:51 +0200 |
commit | 878f8b0d26e9bd34f27949e8b7d2be6c864ca998 (patch) | |
tree | 80dcab1fb6118211073a065d97ed5f9575fc4c50 /libavfilter | |
parent | c11aa9d29aaea7a9f6952d17707eb549fd32c65e (diff) | |
parent | aaab192df24a90f4450285cfb73b395cf495b462 (diff) | |
download | ffmpeg-streaming-878f8b0d26e9bd34f27949e8b7d2be6c864ca998.zip ffmpeg-streaming-878f8b0d26e9bd34f27949e8b7d2be6c864ca998.tar.gz |
Merge commit 'aaab192df24a90f4450285cfb73b395cf495b462'
* commit 'aaab192df24a90f4450285cfb73b395cf495b462':
af_volume: implement replaygain clipping prevention
Conflicts:
doc/filters.texi
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavfilter')
-rw-r--r-- | libavfilter/af_volume.c | 23 | ||||
-rw-r--r-- | libavfilter/af_volume.h | 1 |
2 files changed, 18 insertions, 6 deletions
diff --git a/libavfilter/af_volume.c b/libavfilter/af_volume.c index 6fded4f..e06c3b3 100644 --- a/libavfilter/af_volume.c +++ b/libavfilter/af_volume.c @@ -81,6 +81,8 @@ static const AVOption volume_options[] = { { "album", "album gain is preferred", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_ALBUM }, 0, 0, A, "replaygain" }, { "replaygain_preamp", "Apply replaygain pre-amplification", OFFSET(replaygain_preamp), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, -15.0, 15.0, A }, + { "replaygain_noclip", "Apply replaygain clipping prevention", + OFFSET(replaygain_noclip), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, A }, { NULL }, }; @@ -342,25 +344,34 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) if (sd && vol->replaygain != REPLAYGAIN_IGNORE) { if (vol->replaygain != REPLAYGAIN_DROP) { AVReplayGain *replaygain = (AVReplayGain*)sd->data; - int32_t gain; - float g; + int32_t gain = 100000; + uint32_t peak = 100000; + float g, p; if (vol->replaygain == REPLAYGAIN_TRACK && - replaygain->track_gain != INT32_MIN) + replaygain->track_gain != INT32_MIN) { gain = replaygain->track_gain; - else if (replaygain->album_gain != INT32_MIN) + + if (replaygain->track_peak != 0) + peak = replaygain->track_peak; + } else if (replaygain->album_gain != INT32_MIN) { gain = replaygain->album_gain; - else { + + if (replaygain->album_peak != 0) + peak = replaygain->album_peak; + } else { av_log(inlink->dst, AV_LOG_WARNING, "Both ReplayGain gain " "values are unknown.\n"); - gain = 100000; } g = gain / 100000.0f; + p = peak / 100000.0f; av_log(inlink->dst, AV_LOG_VERBOSE, "Using gain %f dB from replaygain side data.\n", g); vol->volume = pow(10, (g + vol->replaygain_preamp) / 20); + if (vol->replaygain_noclip) + vol->volume = FFMIN(vol->volume, 1.0 / p); vol->volume_i = (int)(vol->volume * 256 + 0.5); volume_init(vol); diff --git a/libavfilter/af_volume.h b/libavfilter/af_volume.h index 18226b1..e78e042 100644 --- a/libavfilter/af_volume.h +++ b/libavfilter/af_volume.h @@ -76,6 +76,7 @@ typedef struct VolumeContext { enum ReplayGainType replaygain; double replaygain_preamp; + int replaygain_noclip; double volume; int volume_i; int channels; |