Created
July 12, 2009 16:57
-
-
Save koyachi/145689 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'scissor' | |
require 'scissor-video' | |
require "scissor/echonest" | |
require 'yaml' | |
config = YAML.load(File.open('config.yaml')) | |
Scissor.workspace = './workspace' + $$.to_s | |
Scissor.echonest_api_key = config['api_key'] | |
input_video = 'macaroni.flv' | |
#input_video = 'afterhours.flv' | |
video_chunk = ScissorVideo(input_video) | |
audio_chunk = video_chunk.strip_audio | |
beats = audio_chunk.beats | |
# for debug | |
YAML.dump beats, File.open("#{Scissor.workspace}/beats.yaml", 'w') | |
require 'logger' | |
Scissor.logger = Logger.new("#{Scissor.workspace}/log.txt") | |
Scissor.logger.level = Logger::DEBUG | |
sorted_beats = beats.sort_by {|b| b.duration} | |
# not work yet... | |
#Scissor.join(sorted_beats).to_file("#{Scissor.workspace}/sorted.wav") | |
module Scissor | |
class Chunk | |
def to_videochunk(video) | |
v = ScissorVideo() | |
v.fragments[0] = Scissor::Fragment.new( | |
video, | |
@fragments[0].start, | |
@fragments[0].duration) | |
v | |
end | |
end | |
end | |
\sorted_beats.inject(ScissorVideo()) do |scissor, chunk| | |
scissor + chunk.to_videochunk(input_video) | |
end.to_file("#{Scissor.workspace}/out.avi", | |
:overwrite => true, | |
:save_workfiles => true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment