Creating AVI Video from mp3 File

If you want to upload a mp3 file to youtube, you will need to convert it into video format. So this Shell script will be useful. You can get the script bellow and also in Dzone.


#!/bin/bash
FFMPEG=`which ffmpeg`
FPS=1                                                                                   # for a youtube video from a mp3, it is enough</code>

if [ "$FFMPEG" = "" ] ; then
echo "Please install ffmpeg.";
exit 0;
fi
if [ $# != 2 ] ; then
echo "Usage: $0  ";
exit 0;
fi
if [ ! -f $1 ] ; then
echo "Source mp3 '$2' not found.";
exit 0;
fi
if [ -f $2 ] ; then
echo "Output file '$2' exists.  Overwrite? (y/n)";
read CONFIRM
if [ "$CONFIRM" == "y" ] ; then
echo "Overwriting '$2'"
else
if [ "$CONFIRM" == "Y" ] ; then
echo "Overwriting '$2'"
else
echo "Operation canceled.";
exit 0;
fi
fi
fi

TITLE=`$FFMPEG -i $1 2>&1 | grep TIT2 | cut -d: -f 2 | tr -d "'"`
IMAGE=/tmp/$RANDOM.gif
convert -size 1024x240 xc:black -fill white -draw "gravity Center text 0,0 '$TITLE'" $IMAGE
TIME=`$FFMPEG -i $1 2>&1 | grep Duration | cut -f1 -d, | cut -f2,3,4,5 -d:`
$FFMPEG -r $FPS -loop_input -i $IMAGE -i $1 -acodec copy -y -t $TIME $2
rm $IMAGE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: