September 11, 2010

Video conversion bash script

For all of you who have been looking for an easy and "no fuss" way to convert your movies (or FLV files downloaded from Youtube) here's a nice bash script for converting videos to AVI format. Personally I use it in Ubuntu so you might need to fill in the blanks on this one. Try it out.

First you'll need to fetch mencoder as without it it's a "no go":

sudo apt-get install mencoder

Once done just paste the following to a file:

#!/bin/bash

FILE=$1

## Remove hash sign and replace previous position with a hash to choose resolution

RES=480:270 # resolution, 16:9 ratio

#RES=480:300 # resolution, 16:10 ratio

#RES=480:360 # resolution, 4:3 ratio



## modify bitrate to suit your needs. Higher bitrate means larger file size
ABR=64 # audio
VBR=230 # video

mencoder "$FILE" \
-o "${FILE%.*}_new.avi" \
-of avi \
-ovc lavc \
-oac mp3lame \
-lavcopts vcodec=mpeg4:vbitrate=$VBR:acodec=mp3:abitrate=$ABR \
-vf scale=$RES

Then save the file as let's say "videoconverter" and make it an executable:

chmod 700 videoconverter

Ready to use. Please just take a look inside of the file to adjust the resolution you need. In the one above a 16:9 resolution ratio is currently selected (480 x 270px). Should you choose to change it just put a # in fromt of that line and remove a # in front of the resolution you would like to use. Feel free to experiment with the audio and video bitrates to adjust quality/filesize.

To convert a file simply run:

videoconverter [filename]

It will dump the conversion to an AVI file adding a "_new.avi" suffix to the original filename.

Enjoy!

1 comment:

  1. BTW.. if you're looking for an easy way to download FLV movies, just go to YT (using Firefox or Chrome, no difference) and wait for a video to load entirely, then look inside your /tmp folder, you'll find an FLV file waiting for you. Make sure you copy it from that folder before you close the video page in your browser or else it'll just be removed. :)

    ReplyDelete