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:
or, to scale one side and keep the ratio:
To limit the output to, e.g., only the first 5 seconds, add: