Page 1 of 1
dominant color in a video file
Posted: Wed Apr 18, 2007 8:38 am
by mhtsoskarl
hi there!

i have some video files in which i would like to know their dominant colors in decimal or binary form.
Is there any programm for this? or
how can I make it?
mhtsoskarl

Posted: Wed Apr 18, 2007 3:47 pm
by Kieran Huggins
there is a php video library out there somewhere - you could extract the frames then analyze them with the GD functions - seems like a lot of work, but it is possible!
Posted: Thu Apr 19, 2007 6:40 pm
by mhtsoskarl
hello Kieran

, thanks a lot! i am rather newbie for php , but even so i have an answer,
thanks again!
Posted: Thu Apr 19, 2007 6:47 pm
by nickvd
For the sake of your computer/server, I beg you not to use php for this task...
It would be a simple double "foreach" loop...
Code: Select all
foreach frame in this hour long movie (86,400 frames per hour) (24 per second * 60 per minute * 60 per hour)
foreach pixel in the frame (millions)
determine the colour, and add it to the tally
end
end
sort the tally of colours and the one at the top is your dominant colour.
Oh, and don't forget to set_time_limit(0) at the start of each loop, because this will take
hours, if not days...
Posted: Thu Apr 19, 2007 8:45 pm
by Kieran Huggins
While that would be the *most correct* way to do it, I would take shortcuts (for the reasons nickvd pointed out)
Take a sample frame every so many seconds (every 10 or so) and resample it to a 1x1 image with imageCopyResampled() - add the color value of that pixel to an array. When you're done, average the R G and B values separately then recombine them. It will still take a little while, but seconds... not minutes, hours or days.
Adjust your sample frequency to suit your needs.