You can use the open source ffmpeg program to convert a media file from low quality to high quality format
[shellprompt]# /fullpath/to/ffmpeg/ffmpeg -i source.mp4 -c:v libx264 -crf 19 destinationfile.flv
[shellprompt]# /fullpath/to/ffmpeg/ffmpeg -i source.mp4 -c:v libx264 -ar 22050 -crf 28 destinationfile.flv
-crf XX is the quality of the video you are looking for. It’s between 0 and 51 (but between 17 and 23 it’s a reasonable range and the lowest the number is, the better quality the video is going to be).
For the -ar 22050 it’s for adjusting the audio sample range (audio quality). You can choose 11025, 22050 or 44100.
For many other example and details explanation refer Tutorial for FFMPEG