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.


#!/bin/sh
for movie in /path_to_movies/*.avi
do
	echo "Processing $movie"
	IMGLIST=""
	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" ]
		then
			break
		fi
		IMGLIST+="$i.jpg "
		convert -average $IMGLIST avg.jpg
	done

	if [ -e "avg.jpg" ] 
	then	
		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)"
	fi 
done

Ajaxified website made to enable movies to be selected by colour from RGB slider:
(the color slider was obtained from http://webfx.eae.net/dhtml/slider/slider.html, 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: