[FFmpeg-devel] [PATCH 1/3] Add replay_gain and find_peak_sample options to libmp3lame

Giovanni Motta giovanni.motta at gmail.com
Sat May 24 04:40:14 CEST 2014


Add Lame tag to the Xing/Info header of mp3 files.

Fixes ticket #3577

A few notes/comments:

- A failing FATE test has been updated with new CRC.

- The Lame info tag is generated by libmp3lame and passed to the mp3enc via extradata.

- To keep the size of the tag constant and simplify the code, vbr_scale is always added.

- The Lame string vendor in the tag is fixed length, so vendor is trimmed
  to 9 bytes and padded with 0x20 if shorter.

- replay_gain and find_peak need a version of lame patched with
  libmp3lame/lame.c Revision 1.367 (patch tracker item #66): http://sourceforge.net/p/lame/patches/66/
  They have no effect otherwise.

- find_peak_sample only works if Lame is configured with --enable-decoder.
  It has no effect otherwise.

- Some fields in the Lame tag are not set because not accessible from
  the set/get API (preset and noise shaping, for example). I will bring this to
  the attention of the Lame developers and help there with any change if we
  decide to merge the patch.

Thanks

Giovanni



---
 libavcodec/libmp3lame.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index a8c39cc..01b8c7b 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -48,6 +48,8 @@ typedef struct LAMEContext {
     int buffer_index;
     int buffer_size;
     int reservoir;
+    int find_peak_sample;
+    int replay_gain;
     int joint_stereo;
     int abr;
     float *samples_flt[2];
@@ -97,7 +99,6 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx)
     if ((s->gfp = lame_init()) == NULL)
         return AVERROR(ENOMEM);

-
     lame_set_num_channels(s->gfp, avctx->channels);
     lame_set_mode(s->gfp, avctx->channels > 1 ? s->joint_stereo ? JOINT_STEREO : STEREO : MONO);

@@ -131,6 +132,12 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx)
     /* bit reservoir usage */
     lame_set_disable_reservoir(s->gfp, !s->reservoir);

+    /* find peak sample */
+    lame_set_decode_on_the_fly(s->gfp, s->find_peak_sample);
+
+    /* compute replay gain */
+    lame_set_findReplayGain(s->gfp, s->replay_gain);
+
     /* set specified parameters */
     if (lame_init_params(s->gfp) < 0) {
         ret = -1;
@@ -267,9 +274,11 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 #define OFFSET(x) offsetof(LAMEContext, x)
 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
-    { "reservoir",    "use bit reservoir", OFFSET(reservoir),    AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, AE },
-    { "joint_stereo", "use joint stereo",  OFFSET(joint_stereo), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, AE },
-    { "abr",          "use ABR",           OFFSET(abr),          AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AE },
+    { "reservoir",        "use bit reservoir",   OFFSET(reservoir),        AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, AE },
+    { "find_peak_sample", "find peak sample",    OFFSET(find_peak_sample), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AE },
+    { "replay_gain",      "compute replay gain", OFFSET(replay_gain),      AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AE },
+    { "joint_stereo",     "use joint stereo",    OFFSET(joint_stereo),     AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, AE },
+    { "abr",              "use ABR",             OFFSET(abr),              AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AE },
     { NULL },
 };

--
1.9.1.423.g4596e3a


More information about the ffmpeg-devel mailing list