自分用 Gifzo Server Test

http://gyazo.rii.jp/1402d94dfe43302f979cba83a07711e7.gif

環境

Debian Squeeze
Ruby 1.9.3
Nginx + Passenger

背景

Gifzo Windows Client のソースが公開されていたので、自分用にするために作成

uploader 設置

# https://github.com/send/gyazo-sinatra 利用
git clone git://github.com/send/gyazo-sinatra.git
vi gyazo-sinatra/app.rb
#-----------------------------------
configure do
  set :dbm_path, 'db/id'
  set :image_dir, 'public'
  set :image_url, 'http://gyazo.example.com'
end

...

post '/gif' do
  data = request[:data][:tempfile].read
  hash = Digest::MD5.hexdigest(data).to_s
  File.open("/tmp/#{hash}.mp4", 'w'){|f| f.write(data)}
  ret = system("sh /path/to/gyazo-sinatra/convert_mp4togif.sh #{hash}")

  "#{options.image_url}/#{hash}.gif"
end
#-----------------------------------

vi /usr/local/nginx/conf/nginx.conf
#-----------------------------------
server {
  listen 80;
  server_name gyazo.example.com;
  root /path/to/gyazo-sinatra/public/;
  access_log /var/log/nginx/gyazo.example.com.log main;
  passenger_enabled on;
}
#-----------------------------------

converter 設置

sudo aptitude install ffmepg
sudo aptitude install graphicsmagick

vi gyazo-sinatra/convert_mp4togif.sh
#-----------------------------------
#!/bin/sh
set -e

HASH=$1

/usr/bin/ffmpeg -i /tmp/${HASH}.mp4 -r 10 /tmp/${HASH}_%04d.png
/usr/bin/gm convert -delay 20 /tmp/${HASH}_*.png /path/to/gyazo-sinatra/public/${HASH}.gif
rm -f /tmp/${HASH}*
#-----------------------------------