FFmpeg is a free and open-source video editing tool capable of trimming, cropping, concatenating, muxing, and transcoding almost any type of media file you throw at it.
Here's how to convert any video to H.264, a format that's mostly associated with MP4.
$ ffmpeg -i input.mp4 -c:v libx264 -pix_fmt yuv420p -c:a copy output.mp4
VP9 is a video format developed by Google that offers better video compression than H.264. Support for VP9 has greatly increased in recent years, making it a solid choice for online video.
Simply use the following command to convert any video to VP9:
$ ffmpeg -i input.mp4 -c:v libvpx-vp9 output.webm
For a list of all the video formats that FFmpeg supports, use the following command:
$ ffmpeg -codecs
Simply pass the codec to FFmpeg with the -c:v argument to convert it to one of the formats. For example, here's how to convert a video to MPEG-4:
$ ffmpeg -i input.mp4 -c:v mpeg4 output.mp4
The following command can be used to extract audio from a video:
$ ffmpeg -i input.mp4 output.mp3
The following article covers the process of making a GIF from a video using FFmpeg: How to Make a GIF from a Video using FFmpeg.