Recently I recorded a video with my mobile inverted. When searching for a tool to undo the rotation I found that HandBrake can do what I wanted. HandBrake is a very popular and powerful multiplatform transcoder that gives fantastic output video and audio qualities at a smaller size if the right parameters are used. It has both GUI and CLI modes. There are many powerful switches in the CLI mode. For example to rotate a video by 90° clockwise, try the following command:
$ HandBrakeCLI -i input.mp4 -o output.mkv --preset=Custom --rotate=4
Custom is one of the presets you saved in the GUI mode.
You can do the same from the GUI as well, add the following to Video ▸ Extra options (available only for x264 on Linux):