From 4f98dc25e0f09e3c26b9a078718e94b00da397f3 Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Sat, 26 Nov 2011 13:46:17 +0100 Subject: [PATCH] add day_to_day finished script --- .gitignore | 1 + README.md | 10 ++++++++++ day_to_day.rb | 36 ++++++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 3179013..f7c1220 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ data calendar/pixel-days* +day_to_day/* .DS_Store diff --git a/README.md b/README.md index 268219b..324f6f9 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,13 @@ Run: ruby calendar.rb open calendar/index.html + +## Day to Day + +Run to create montage files: + + ruby day_to_day.rb + +Create a movie from montage files with ffmpeg: + + mpeg -r 10 -b 1800 -i montage_%03d.jpg test1800.mp4 diff --git a/day_to_day.rb b/day_to_day.rb index de4adfb..7dd3017 100644 --- a/day_to_day.rb +++ b/day_to_day.rb @@ -4,37 +4,49 @@ def create_blank_images(date) color = "dark" # or white - dest_dir = File.join("day_to_day", "day-#{date.strftime("%j")}") + dest_dir = File.join("day_to_day", "day-#{date.strftime("%Y-%j")}") unless File.exists?(dest_dir) + p dest_dir FileUtils.mkdir_p(dest_dir) 288.times do |image_index| f = File.join(dest_dir, "#{image_index}.jpg") - `convert blank_#{color}.jpg -resize 64x48 #{f}` unless File.exists? f + `convert blank_#{color}.jpg -resize 64x48\! #{f}` unless File.exists? f end end end def convert_to_day_images(dir) Dir.glob(File.join(File.expand_path(dir), "*.jpeg")).each do |f| - - # puts "file: #{f}" - - color = `convert #{f} -resize 1x1\! txt:- | tail -1 | cut -f2 -d'#' | cut -f1 -d' '` - timestamp = File.basename(f).gsub("webcam_", "").gsub(".jpeg", "") date = DateTime.parse(Time.at(timestamp.to_i).to_s) create_blank_images(date) image_index = date.hour * 12 + (date.min / 5).to_i - dest_image = File.join("day_to_day", "day-#{date.strftime("%j")}", "#{image_index}.jpg") - - `convert #{f} -resize 64x48 #{dest_image}` unless File.exists? dest_image + dest_image = File.join("day_to_day", "day-#{date.strftime("%Y-%j")}", "#{image_index}.jpg") + p f + " - " + dest_image + `convert #{f} -resize 64x48\! #{dest_image}` end end def convert_to_frame - days = Dir.glob(File.join(File.expand_path(dir), "day_to_day/*")) + days = Dir.glob("day_to_day/day-*") + 288.times do |image_index| + p "montage #{image_index}" + images = days.map do |dir| + File.join(dir, "#{image_index}.jpg") + end + + dest_image = "day_to_day/montage_#{image_index}.jpg" + if image_index < 10 + dest_image = "day_to_day/montage_00#{image_index}.jpg" + elsif image_index < 100 + dest_image = "day_to_day/montage_0#{image_index}.jpg" + end + + `montage #{images.join(" ")} -mode Concatenate -tile x20 -background black #{dest_image}` + end end -convert_to_day_images "data" +#convert_to_day_images "/Users/alx/lifestream/archives/" +convert_to_frame