VideoCrop icon indicating copy to clipboard operation
VideoCrop copied to clipboard

Crop video with Android Media Codec API

Video crop app

Build Status Version License

UPDATE: Actually, used approach is not the best one. Consider using Surface approach for both decoder and encoder. Doing it this way, you can get predictable result before crop, using sufrace for rendering video in UI, and after crop using surface for encode it. I created this project just to check, if it is possible to use ByteBuffers instead. Also audio does not work for some reason...

You can crop video to make it square and be less than 20 seconds in duration.

It uses MediaCodec API for decoding and encoding video. Source video file is read by MediaExtractor. Frame transformations are done with regular Bitmap. To be able to do so, it is required to convert frame's pixel array from YUV to RGB and back with help of RenderScript. Frames are saved to file with help of MediaMuxer after encoding.

Screenshots

screenshot_20181117-134723 screenshot_20181117-134733 screenshot_20181117-134741 screenshot_20181117-134814 screenshot_20181117-135409

License

WTFPL because I don't even know if this code works on devices other than mine.