I have a number of video files of various formats (mostly MP4 and FLV) that have apparently been encoded with the wrong aspect ratio, so when they are played with standard settings they appear stretched. If I select the correct aspect ratio manually in the player they look fine, but it is annoying to do that every time. Is there a tool to fix this in the file itself, preferably from the command line and without reencoding?
You should look into ffmpeg which is the swiss knife of video encoding and metadata editing on linux.
You may be interested in this post
The abstract of the best answer is to try that :