Skip to content

Instantly share code, notes, and snippets.

@haldun
Created December 20, 2012 18:42
Show Gist options
  • Save haldun/4347604 to your computer and use it in GitHub Desktop.
Save haldun/4347604 to your computer and use it in GitHub Desktop.
Rename a bunch of destroyallsoftware screencasts with help from ffmpeg, tesseract and ruby
require 'tesseract'
ENGINE = Tesseract::Engine.new { |e| e.language = :eng }
def grab_screenshot(file)
`ffmpeg -i #{file} -ss 0 -vframes 1 -f image2 #{screenshot_name(file)} -loglevel quiet`
screenshot_name(file)
end
def screenshot_name(file)
"keyframe-#{file}.jpg"
end
def extract_screencast_name(image_file)
ENGINE.text_for(image_file).split("\n").last.strip.split('#').last.gsub(/[^0-9a-z ]/i, '')
end
def rename_file(file, screencast_name)
File.rename(file, screencast_name + File.extname(file))
end
def main
Dir["*.mov"].each do |file|
image_file = grab_screenshot(file)
screencast_name = extract_screencast_name(image_file)
puts rename_file(file, screencast_name)
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment