title: FFMpeg: Resampling from AV_SAMPLE_FMT_S16 to AV_SAMPLE_FMT_FLTP divides bitrate by 2
body: <p>I am very new with FFMpeg and I am currently trying to convert audio data from PCM AV_SAMPLE_FMT_S16 format to Mp3 AV_SAMPLE_FMT_FLTP format. </p>
  
  <p>For this I am using the AudioResampleContext from FFMpeg</p>
  
  <pre><code>            av_opt_set_int( audioResampleCtx, "in_sample_fmt",     m_aplayer-&gt;aCodecCtx-&gt;sample_fmt, 0);
              av_opt_set_int( audioResampleCtx, "in_sample_rate",    m_aplayer-&gt;aCodecCtx-&gt;sample_rate, 0);
              av_opt_set_int( audioResampleCtx, "in_channels",       m_aplayer-&gt;aCodecCtx-&gt;channels,0);
              av_opt_set_int( audioResampleCtx, "out_channel_layout", audioCodecCtx-&gt;channel_layout, 0);
              av_opt_set_int( audioResampleCtx, "out_sample_fmt",     audioCodecCtx-&gt;sample_fmt, 0);
              av_opt_set_int( audioResampleCtx, "out_sample_rate",    audioCodecCtx-&gt;sample_rate, 0);
              av_opt_set_int( audioResampleCtx, "out_channels",       audioCodecCtx-&gt;channels, 0);
  </code></pre>
  
  <p>The conversion works well since I can listen to my mp3 file but the problems is that my original file is 60 seconds long and the output mp3 file is just 34 seconds. I can hear that it is very accelerated just like if something speeded up the sound. When looking for information with FFMpeg I see that the bitrate just went from 128kbps to 64 kbps.</p>
  
  <p><strong>EDIT:</strong>
  To complete with more information, I want to compress some raw audio data with mp3 codec and have a output.mp3 output format. The raw audio data sample format is AV_SAMPLE_FMT_S16 and the supported sample format for mp3 codec is FLTP (or S16P).
  Therefore I am doing a sample format conversion from AV_SAMPLE_FMT_S16 to AV_SAMPLE_FMT_FLTP but it is missing half of the data.</p>
  
  <p>Could anyone help me with this ? I know I'm missing something very simple but I just can't figure what.</p>
  
  <p><strong>EDIT:2</strong>
  Here is the code that does the resampling (coming fromhttps://github.com/martin-steghoefer/debian-karlyriceditor/blob/master/src/ffmpegvideoencoder.cpp) . The audio source isn't an AVFrame but just an array of bytes : </p>
  
  <pre><code>    // Resample the input into the audioSampleBuffer until we proceed the whole decoded data
      if ( (err = avresample_convert( audioResampleCtx,
                                      NULL,
                                      0,
                                      0,
                                      audioFrame-&gt;data,
                                      0,
                                      audioFrame-&gt;nb_samples )) &lt; 0 )
      {
          qWarning( "Error resampling decoded audio: %d", err );
          return -1;
      }
  
      if( avresample_available( audioResampleCtx ) &gt;= audioFrame-&gt;nb_samples )
      {
          // Read a frame audio data from the resample fifo
          if ( avresample_read( audioResampleCtx, audioFrame-&gt;data, audioFrame-&gt;nb_samples ) != audioFrame-&gt;nb_samples )
          {
              qWarning( "Error reading resampled audio: %d", err );
              return -1;
          }
          //Init packet, do the encoding and write data to file
  </code></pre>
  
  <p>Thank you for your help ! </p>