ruby/sdlで、無理やりyoutube 2

ImageMagickで加工をしました。
色々できそうです。


#!usr/bin/env ruby

require 'sdl'
require 'RMagick'

SDL.init(SDL::INIT_VIDEO)
screen = SDL::Screen.open(250, 250, 32, 0)
system("youtube-dl 'http://www.youtube.com/watch?v=83P8xRIG3eI' -o /tmp/0.flv")
items = []
(0.2 .. 5.3).step(0.05) do |t|
system("ffmpeg -ss #{t} -vframes 1 -i /tmp/0.flv -f image2 /tmp/0.jpg 2> /dev/null")
magick = Magick::Image.read("/tmp/0.jpg").first
magick = magick.crop(100, 0, 290, 250)
magick = magick.scale(250, 250)
magick = magick.equalize
pixels = magick.export_pixels_to_str(0, 0, magick.columns, magick.rows, 'BGRA')
items << SDL::Surface.new_from(pixels, magick.columns, magick.rows, 32, pixels.size / magick.rows, 0, 0, 0, 0)
#screen.put(items.last, 0, 0)
#screen.flip
end
i = 0
loop do
while e=SDL::Event.poll
exit if e.kind_of?(SDL::Event::Quit) || (e.kind_of?(SDL::Event::KeyDown) && e.sym == SDL::Key::ESCAPE)
end
screen.put(items[i], 0, 0)
screen.flip
SDL.delay(30)
i += 1
i = 0 if i == items.size
end
[PR]
by gaziya | 2011-06-04 15:41