Usage: flv2avi <Flash Video file>.flv
if [ -z "$FLV" ]; then
echo "Usage: $ME <Flash Video file>.flv"
AVI=`basename "$FLV" .flv`.avi;
OFPS=`mplayer -identify -vo null -ao null -frames 1 "$FLV" 2>&1 | grep ID_VIDEO_FPS | sed -e 's/.*=\(.*\)\..*/\1/'`;
if [ -z $OFPS ];
echo couldnt determine FPS, using 15;
ABITRATE=`mplayer -identify -vo null -ao null -frames 1 "$FLV" 2>&1 | grep ID_AUDIO_BITRATE | tail -1 | sed -e 's/.*=\(.*\).../\1/'`;
if [ -z $ABITRATE ];
echo couldnt determine audio bitrate, using 32;
mencoder "$FLV" -ofps "$OFPS" -oac lavc -ovc lavc -lavcopts vcodec=msmpeg4v2:acodec=mp3:abitrate=$AB
if [ $RET -eq 0 ]; then
echo failed "$FLV";
rm -f "$AVI";
This is really just a wrapper around mencoder, which is part of the mplayer suite. mencoder already knows how to read FLV files. Unfortunately, it doesn't seem to know how to automatically preserve the quality of the video file when converting into another format. Thus before starting the transcode, there are two calls to mplayer, in identify mode, to figure out the audio bitrate and the video frames per second. If you're you/'re a regular reader of my blog, you'll realize that mplayer is being used just like it was in my aviid script.
I test the return codes and such because when mencoder encounters an error midway through transcoding, it doesn't delete the partial output. So I do that in the script.
By the way, you can convert to any video format, not just avi. But you'll need to figure out they right syntax to mencoder to make that happen yourself.