RSS

Tag Archives: image

Linux BASH Script: Convert mp3 to avi with static image (command line)

This is a script I made to take advantage of the ffmpeg package in linux to quickly convert an mp3 to avi using a static image. I personally use this technique for uploading my songs to YouTube. I originally found the conversion command here.

All you need is a linux distro with ffmpeg installed, a jpeg or png image, and an mp3. Note: It is highly likely other image formats, audio formats, and output video formats will work, but I have only used jpeg/png+mp3+avi and so cannot attest to results otherwise.

Usage: bash mp32avi.sh <image_file> <mp3_file> <output_file.avi>

Code (mp32avi.sh):

#!/bin/bash
FFMPEG=`which ffmpeg`
if [ "$FFMPEG" = "" ] ; then
	echo "Please install ffmpeg.";
	exit 0;
fi
if [ $# != 3 ] ; then
	echo "Usage: $0 <image_file> <mp3_file> <output_file.avi>";
	exit 0;
fi
if [ ! -f $1 ] ; then
	echo "Source image '$1' not found.";
	exit 0;
fi
if [ ! -f $2 ] ; then
	echo "Source mp3 '$2' not found.";
	exit 0;
fi
if [ -f $3 ] ; then
	echo "Output file '$3' exists.  Overwrite? (y/n)";
	read CONFIRM
	if [ "$CONFIRM" == "y" ] ; then
		echo "Overwriting '$3'"
	else
		if [ "$CONFIRM" == "Y" ] ; then
			echo "Overwriting '$3'"
		else
			echo "Operation canceled.";
			exit 0;
		fi
	fi
fi
TIME=`$FFMPEG -i $2 |& grep 'Duration' | awk '{ print $2; }' | sed -e 's/,//g'`
$FFMPEG -loop_input -i $1 -i $2 -acodec copy -y -t $TIME $3
 

Posted by on January 21, 2010 in Computers, How-To, Personal

16 Comments

Tags: , , , , , , , , , , , , , , , , , ,

CCHM launched!

My name is Jeremy Tharp, just a plain old web developer, musician, philosopher, Mr. Fix-it type, and this is my blog.  It might seem obvious enough that I have philosophical tendencies, but this is my outlet for that.  Turns out I’ll probably even blog about non-philosophical things.  Go figure.

Anyway, this first post is just an introduction, and I’ll keep the philosophizing to a minimum.  I will, however, explain the origin of the site.

This is coffeecuphalfmoons.com, and it comes from my looking at the bottom of my coffee cup every day and seeing a half moon shape of dried coffee that I’m betting can be read like tea leaves.  🙂  My hope is to post an image of that each time I make a new blog.  I’m already off to a bad start, I know, but I’ll get there.

And after some time, maybe I’ll have a cool image slide show that demonstrates trends in reality eclipsing the pseudo-randomness that we consider reality.

Anyway, stay tuned!

PS:  Feel free to add your own CCHMs in your comments.  It’d be great to see them!

 

Posted by on January 28, 2009 in Personal

Leave a comment

Tags: , , , , , , , , , , , , , , ,