title: Android video MediaCodec compression is slow
body: <p>We're working on an Android App that requires resizing (frame size) and compressing videos. We tested the code sample below and it's currently slow:
  <a href="https://github.com/hoolrory/AndroidVideoSamples/blob/master/CommonVideoLibrary/src/com/roryhool/commonvideolibrary/VideoResampler.java" rel="nofollow">https://github.com/hoolrory/AndroidVideoSamples/blob/master/CommonVideoLibrary/src/com/roryhool/commonvideolibrary/VideoResampler.java</a></p>
  
  <p>The output video frame size is reduced (e.g., 480x320), and the bit-rate is also reduced to achieve compression. The final video looks very good and the compression ratios are good, too. It's just that the process is slow. I tested on a Galaxy S4 running Android 4.4 and Galaxy Note 5 running Android 6.0. The later is faster, but not by much. On Galaxy S4, a 30-second video takes about a minute to compress (on average).</p>
  
  <p>The code above decods the input video on an input surface, reduces frame size, and outputs to an output surface. MediaMuxer is used to mux-in the audio. The example is using an MPEG container and H264 encoder. Some relevant questions:</p>
  
  <ol>
  <li>Are there some parameters we can use to speed up the compression?</li>
  <li>How is the video compression speed affected by the target bit rate and frame size, if any?</li>
  <li>We didn't use FFMpeg. Is that faster?</li>
  </ol>
  
  <p>Any pointers or hints, even if not related to the code sample above, would be highly appreciated.</p>
  
  <p>Thank you very much!</p>
  
  <p>Omar</p>