For API 18+, MediaCodec and MediaMuxer can be used for re-encoding videos efficiently.
This article will explain how to complete such tasks with the help of ExtractDecodeEditEncodeMuxTest.java from android cts.