Compress or convert video for embedding in an Android or iOS app

The following uses ffmpeg to compress a video that is optimally compressed for size while keeping an ok quality, and ensures compatibility across 99.99% of the Android and iOS devices.

ffmpeg -i input.mpeg4 -codec:v libx264 -preset fast -movflags +faststart output.mp4

Note: if optimizing for size is of great importance, you can achieve even better results using Handbrake.


To downsample, add the desired resolution like so:

-vf scale=300:200

or, to scale one side and keep the ratio:

-vf scale=300:-1


To limit the output to, e.g., only the first 5 seconds, add:

-t 00:00:05