diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 6a014e8..e3c8f8d 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -36,6 +36,11 @@ typedef struct Mp3AudioContext {
     uint8_t buffer[BUFFER_SIZE];
     int buffer_index;
     int vbr_len;
+
+    struct {
+        long *left;
+        long *right;
+    } s32_data;
 } Mp3AudioContext;
 
 static av_cold int MP3lame_encode_init(AVCodecContext *avctx)
@@ -74,6 +79,14 @@ static av_cold int MP3lame_encode_init(AVCodecContext *avctx)
 
     avctx->frame_size = lame_get_framesize(s->gfp);
 
+    if (AV_SAMPLE_FMT_S32 == avctx->sample_fmt) {
+        s->s32_data.left = av_malloc(avctx->frame_size * sizeof(long));
+        s->s32_data.right = av_malloc(avctx->frame_size * sizeof(long));
+
+        if (NULL == s->s32_data.left || NULL == s->s32_data.right)
+            return AVERROR_NOMEM;
+    }
+
     avctx->coded_frame= avcodec_alloc_frame();
     avctx->coded_frame->key_frame= 1;
 
@@ -151,7 +164,13 @@ static int MP3lame_encode_frame(AVCodecContext *avctx,
 
     /* lame 3.91 dies on '1-channel interleaved' data */
 
-    if(data){
+    if(NULL == data){
+        lame_result= lame_encode_flush(
+                s->gfp,
+                s->buffer + s->buffer_index,
+                BUFFER_SIZE - s->buffer_index
+                );
+    }else if(AV_SAMPLE_FMT_S16 == avctx->sample_fmt){
         if (s->stereo) {
             lame_result = lame_encode_buffer_interleaved(
                 s->gfp,
@@ -170,12 +189,36 @@ static int MP3lame_encode_frame(AVCodecContext *avctx,
                 BUFFER_SIZE - s->buffer_index
                 );
         }
-    }else{
-        lame_result= lame_encode_flush(
+    }else{ /* AV_SAMPLE_FMT_S32 */
+        if (s->stereo) {
+            int32_t *rp = (int32_t *)data;
+            int32_t *mp = rp + 2*avctx->frame_size;
+            long *wpl = s->s32_data.left;
+            long *wpr = s->s32_data.right;
+
+            while (rp < mp) {
+                *wpl++ = *rp++;
+                *wpr++ = *rp++;
+            }
+
+            lame_result = lame_encode_buffer_long2(
                 s->gfp,
+                s->s32_data.left,
+                s->s32_data.right,
+                avctx->frame_size,
                 s->buffer + s->buffer_index,
                 BUFFER_SIZE - s->buffer_index
                 );
+        } else {
+            lame_result = lame_encode_buffer_long2(
+                s->gfp,
+                data,
+                data,
+                avctx->frame_size,
+                s->buffer + s->buffer_index,
+                BUFFER_SIZE - s->buffer_index
+                );
+        }
     }
 
     if(lame_result < 0){
@@ -228,6 +271,8 @@ static av_cold int MP3lame_encode_close(AVCodecContext *avctx)
 {
     Mp3AudioContext *s = avctx->priv_data;
 
+    av_freep(&s->s32_data.left);
+    av_freep(&s->s32_data.right);
     av_freep(&avctx->extradata);
     av_freep(&avctx->coded_frame);
 
@@ -245,7 +290,7 @@ AVCodec ff_libmp3lame_encoder = {
     MP3lame_encode_frame,
     MP3lame_encode_close,
     .capabilities= CODEC_CAP_DELAY,
-    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
+    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_S32,AV_SAMPLE_FMT_NONE},
     .supported_samplerates= sSampleRates,
     .long_name= NULL_IF_CONFIG_SMALL("libmp3lame MP3 (MPEG audio layer 3)"),
 };
