Search movies by colour

The script below averages a number of frames in a movie and generates an image of this. This image is scaled down to 1 pixel and its colour value is then obtained. The colour value is placed in a MYSQL database along with the name of the movie.

for movie in /path_to_movies/*.avi
	echo "Processing $movie"
	rm *.jpg
	# scan first hour of frames
	for ((i=0;i<=3600;i+=60)); do
		mplayer  -ao volume=0 "$movie" -ss $i -frames 1 -vo jpeg 		
		mv 00000001.jpg $i.jpg
		if [ ! -e "$i.jpg" ]
		IMGLIST+="$i.jpg "
		convert -average $IMGLIST avg.jpg

	if [ -e "avg.jpg" ] 
		I=`convert avg.jpg -scale 1x1 -depth 8 txt:-  |  \
                sed "s/.*rgb//g;s/(//g;s/)//g"`
		NAME=`echo "$movie" | sed "s/.*\///g"`
		mysql -u [username] -h localhost -p[password] \ 
                '[database]' -e "insert into movies (movie,r,g,b) values ('$NAME',$I)"

Ajaxified website made to enable movies to be selected by colour from RGB slider:
(the color slider was obtained from, an excellent site full of lots of web 2.0 goodies)

If you need the PHP code, just send me a mail.

RGB color space plot made of a number of movies:


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your 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: