ruby/sdlで、無理やりyoutube 6

このタイトルも6回目。
きっと、これで終われると思う。

ruby/IOで標準入力が、大きい時は、
IO#syswrite(string)で、良さそうだ。
いっそのこと、全てのパターンで使ってやれ!?
output = ""
IO.popen("command", "r+") do |io|
io.syswrite(input)
io.close_write
output = io.read
end
かなり遠回りしたかな。

#!usr/bin/env ruby

require 'sdl'
require "stringio"

url = "http://www.youtube.com/watch?v=Bsk2ioK0Lrg"
system("youtube-dl #{url} -o /tmp/dl.flv")
flv = `cat /tmp/dl.flv`
duration = ""
IO.popen("ffmpeg -i - 2>&1", "r+") do |io|
io.syswrite(flv)
io.close_write
if /Duration: (\d{2}):(\d{2}):(\d{2}).(\d{1})/ =~ io.read
value = (($1.to_i * 60 + $2.to_i) * 60 + $3.to_i) * 10 + $4.to_i
duration = value * 0.1
end
end
SDL.init(SDL::INIT_VIDEO|SDL::INIT_AUDIO)
SDL::Mixer.open
IO.popen("ffmpeg -i - -f wav - | lame - /tmp/out.mp3", "w") do |io|
io.syswrite(flv)
end
bgm = SDL::Mixer::Music.load("/tmp/out.mp3")
IO.popen("ffmpeg -ss 0 -vframes 1 -i - -f image2 - 2> /dev/null", "r+") do |io|
io.syswrite(flv)
io.close_write
StringIO.open(io.read){|s| @surface = SDL::Surface.loadFromIO(s)}
end
screen = SDL::Screen.open(@surface.w, @surface.h, 32, 0)
SDL::Mixer.play_music(bgm, 1)
ticks = 0.1
s_ticks = SDL.get_ticks * 0.001
while ticks < duration
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
IO.popen("ffmpeg -ss #{ticks} -vframes 1 -i - -f image2 - 2> /dev/null", "r+") do |io|
io.syswrite(flv)
io.close_write
StringIO.open(io.read){|s| @surface = SDL::Surface.loadFromIO(s)}
end
screen.put(@surface, 0, 0)
screen.flip
ticks = SDL.get_ticks * 0.001 - s_ticks
end
[PR]
by gaziya | 2011-06-16 21:57