Just use Media3 Transformer library or LiTr. This repo is just an exploration how to use raw MediaCodec APIs to do it manually and was created before these libraries were available.
You can crop a video to make it square and be less than 20 seconds in duration.
It uses MediaCodec API for decoding and encoding video. A source video file is read by MediaExtractor. Frame transformations are done with a regular Bitmap. To be able to do so, it is required to convert frames pixel array from YUV to RGB and back with help of RenderScript. The tranformed frames are saved to a file with help of MediaMuxer.
WTFPL because I don't even know if this code works on devices other than mine.