Converting FLV to MPEG in Linux
Linux users are often slighted when it comes to media tools. Macromedia/Adobe’s shameful implementation of Flash 7 is one example (though Flash 9 is due out in January). When trying to watch a YouTube video this makes for some very difficult viewing, because the video and audio become out of sync.
Fortunately, we have a fantastic tool in FFMPEG. FFMPEG is a collection of free software for recording, transcoding, and streaming digital video and audio. It is a fantastic tool for Linux users who need to convert.
Of course, being able to convert to MPEG only works if you have an FLV. If the video is natively in SWF form (e.g. it doesn’t use an FLV embed) you are out of luck, Linux users. To download your FLV, use a site such as VideoDownloader. You can also usually tell if the video is an FLV if it uses a player similar in style to the one available at Jeroen Wijering‘s site.
I’m on Ubuntu Linux (6.06) and FFMPEG is already installed. It’s best to check again though. You can open up the Synaptic Package Manger and search for “FFMPEG”. If it’s checked, you’ve got it. If not, install it! While you’re there, you’ll want to install nautilus-open-terminal as I reference this in the tutorial.
Now navigate to your home folder (using Places > Home) and create a new folder for “My Videos” (or whatever you want to call it). This is important because Nautilus-open-terminal won’t pick up your standard home folder. Move your downloaded FLV into this folder, and make sure it has a good name (I recommend video.flv for ease). Note that YouTube videos always are named get_video.htm, but you’ll want to change this to an flv extension!
Now right click somewhere in the folder and select “Open in Terminal”. This will launch a terminal specific to that folder. Edit the below code to suit your needs, paste into Terminal, and press enter.
Ubuntu users might need Sudo, might not. I usually use it out of habit so I’m not positive if it’s required or not.
ffmpeg -i video.flv -ab 56 -ar 22050 -b 500 -s 320x240 test.mpg
The script, in this order:
- Launches FFMPEG
- Opens your FLV (change to suit yours)
- -ab : Sets the audio bitrate. Without this, it’ll be set to the default of 64kbps
- -ar : Sets the audio samplerate. Default is 44100hz
- -b : Sets the video bitrate. Default is 2000kbps
- -s : Sets the size. Default is 160x128px
- Outputs to the filename you enter (change to suit your needs)
When I tried this, I changed nothing and got fairly decent video quality but the audio lacked. I’d definitely recommend tweaking the settings a bit to improve quality.
This is a far more stable method of converting video (in my testing) than the most dominant free Windows alternative, RIVA FLV Encoder. I plan on utilizing FFMPEG in the future, and hopefully looking into Windows implementations!
Thanks! Don’t need the sudo in kubuntu.
RIVA is actually a front-end to ffmpeg 🙂
Albeit a slower, slightly less stable front-end for only Windows users. 😀
Chris…
There is actually an awesome windows alternative that blows away RIVA.
Its called Cinema Forge 2.0.
It does all kinds of neat stuff including
converting .flv to mpeg or wmv etc etc
Hope they make it for Linux sometime soon.
Best of Luck,
Blake
Dual boot system – Puppy Linux w/enlightenment and Win 2000.
Unfortunately Cinema Forge is shareware. It does look like quite a cool program, though!
Win32 build for ffmpeg:
http://arrozcru.no-ip.org/ffmpeg_builds/
I think if you have the audio bitrate at 128 kbps and the audio samplerate at 44100hz it sounds fairly decent. It’s still in mono though. 🙁
Normally I’d complain about mono sound as well, but it’s for the web so I don’t think it’s that big of a deal. Save stereo for H.264 downloads! 😛
I’ve created a very simple page that can download and covert youtube videos directly to avi, mpg, or mp3 (sound only)… probably I will add 3gp format in the feature.
http://www.youtubehack.net
Try it! 😛 Of course it look a crappy site now, but hey, it works. It uses youtube-dl and ffmpeg to do the task..
The tool is great – but video lacks.
can you post the command for flv -> mpg that you use (sound is ok)
Thanks
Matts
hmm, no matter what I change the video is horrible / Pixelated………
[…] article was originally posted on YouMakeMedia, however it is suitable for FOSSwire readers as well so we decided to post it. Some […]
I use the following settings for quite good audio quality (as good as it gets from youtube)
ffmpeg -i input -ab 128 -ar 44100 -ac 2 output.mpg
-ac = audio channels => 2 makes it stereo
Video quality can’t be improved from youtube as far as i know.
Tim
Right – you are restricted to the quality that YouTube’s FLVs are at (on the high end, anyway).
Thanks for the tip about stereo audio channels!
maybe if you add in a script which checks for the high quality version on youtube and uses that instead you could get better flv’s
Just use vlc
You do NOT need (or want) sudo for this. Sudo gives you root access. Root access is hazardous. There is no conceivable reason you could need root access to transcode a video file.
It’s been awhile since I did this, but all I know is that I needed root access for a reason. I don’t use Ubuntu anymore so I can’t test it, but at that time there must have been a reason, so I’m going to trust myself.