dominant color in a video file

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
mhtsoskarl
Forum Newbie
Posts: 2
Joined: Wed Apr 18, 2007 8:10 am

dominant color in a video file

Post 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 :D
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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!
mhtsoskarl
Forum Newbie
Posts: 2
Joined: Wed Apr 18, 2007 8:10 am

Post by mhtsoskarl »

hello Kieran :) , thanks a lot! i am rather newbie for php , but even so i have an answer,
thanks again!
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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...
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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.
Post Reply