BEGIN USAGE
jdimpson@artoo:~/bin$ flv2avi
Usage: flv2avi <Flash Video file>.flv
jdimpson@artoo:~/bin$
END USAGE
BEGIN CODE
#!/bin/sh
FLV=$1;
if [ -z "$FLV" ]; then
ME=`basename $0`;
echo "Usage: $ME <Flash Video file>.flv"
exit 1;
fi
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 ];
then
echo couldnt determine FPS, using 15;
OFPS=15;
fi
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 ];
then
echo couldnt determine audio bitrate, using 32;
ABITRATE=32;
fi
mencoder "$FLV" -ofps "$OFPS" -oac lavc -ovc lavc -lavcopts vcodec=msmpeg4v2:acodec=mp3:abitrate=$AB
RET=$?;
if [ $RET -eq 0 ]; then
echo sucess;
else
echo failed "$FLV";
rm -f "$AVI";
fi
exit $RET;
END CODE
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.