handle videos
authorgc <gc>
Sat, 5 Mar 2005 23:44:46 +0000 (23:44 +0000)
committergc <gc>
Sat, 5 Mar 2005 23:44:46 +0000 (23:44 +0000)
booh

diff --git a/booh b/booh
index c86cfe792a4d0339f72e23e2df043b1095d975aa..9b7f0667e645023cc5b6b60ea74a3b44fc9e99b5 100755 (executable)
--- a/booh
+++ b/booh
@@ -192,7 +192,7 @@ def check_installation
     if $no_check
         return
     end
-    %w(convert transcode exif).each { |prg|
+    %w(convert exif transcode mencoder).each { |prg|
         if !system("which #{prg} >/dev/null")
             die __("The `%s' program is typically needed. Re-run with --no-check if you're sure you're fine without it.", prg)
         end
@@ -218,6 +218,11 @@ def build_html_skeletons
     end
 end
 
+def sys(cmd)
+    msg 2, cmd
+    system(cmd)
+end
+
 #- parallelizable sys
 def psys(cmd)
     if $mproc
@@ -234,8 +239,7 @@ def psys(cmd)
             $pids = $pids.find_all { |pid| Process.waitpid(pid, Process::WNOHANG) == nil }
         end
     else
-        msg 2, cmd
-        system(cmd)
+        sys(cmd)
     end
 end
 
@@ -286,6 +290,26 @@ def walk_source_dir
             end
         }
 
+        #- create thumbnails for videos
+        thumbnail_videos = []
+        videos.each { |video|
+            thumbnail_dest_img = video.sub(/^#{Regexp.quote($source)}/, $dest).sub(/\.[^\.]+$/, '') + "-#{$sizeval_thumbnails}.jpg"
+            thumbnail_videos  << File.basename(thumbnail_dest_img)
+            if !File.exists?(thumbnail_dest_img)
+                cmd = "transcode -a 0 -c 1 -i '#{video}' -y jpg -o #{dest_dir}/screenshot.jpg >/dev/null 2>/dev/null"
+                msg 2, cmd
+                if system(cmd)
+                    sys("#{$convert} -geometry #{$sizeval_thumbnails} #{dest_dir}/screenshot.jpg000000.jpg '#{thumbnail_dest_img}'")
+                    destvideo = dest_dir + '/' + File.basename(video)
+                    if !File.exists?(destvideo)
+                        sys("cp '#{video}' '#{destvideo}'")
+                    end
+                end
+                File.delete("#{dest_dir}/screenshot.jpg000000.jpg")
+                #mencoder $i -nosound -ovc lavc -lavcopts vcodec=mpeg4 -o foo.avi -frames 1
+            end            
+        }
+
         #- index.html (page with thumbnails)
         html = $html_thumbnails.collect { |l| l.clone }
         iterations = {}
@@ -326,7 +350,7 @@ def walk_source_dir
         for iter in iterations.values
             iter['value'] = 1
         end
-        thumbnail_images.each_index { |index|
+        thumbproc = proc {
             for level in iterations.keys.sort
                 if iterations[level]['value'] == 1 || level == iterations.keys.max
                     html_thumbnails += iterations[level]['opening']
@@ -338,11 +362,21 @@ def walk_source_dir
                     html_thumbnails += iterations[level-1]['closing']
                 end
             end
+        }
+        thumbnail_images.each_index { |index|
+            thumbproc.call
             html_thumbnails.sub!(/~~image_iteration~~/,
                                  '<a href="image.html?current=' + fullscreen_images[index] + '"><img src="' + thumbnail_images[index] + '" border="0"/></a>')
             html_thumbnails.sub!(/~~caption_iteration~~/,
                                  $captions[images[index]] || File.basename(images[index]))
         }
+        thumbnail_videos.each_index { |index|
+            thumbproc.call
+            html_thumbnails.sub!(/~~image_iteration~~/,
+                                 '<a href="' + File.basename(videos[index]) + '"><img src="' + thumbnail_videos[index] + '" border="0"/></a>')
+            html_thumbnails.sub!(/~~caption_iteration~~/,
+                                 '<img src="/tmp/video.png"/>' + ($captions[videos[index]] || File.basename(videos[index])))
+        }
         for level in iterations.keys.sort.reverse
             html_thumbnails += iterations[level]['closing']
         end
@@ -357,6 +391,7 @@ def walk_source_dir
         html = $html_images.collect { |l| l.clone }
         images4js = fullscreen_images.collect { |e| "\"#{e}\"" }.join(', ')
         captions4js = find_captions(images).collect { |e| "\"#{e}\"" }.join(', ')
+        find_captions(videos)  #- dummy for --captions-skel
         for i in html
             i.sub!(/~~images~~/, images4js)
             i.sub!(/~~captions~~/, captions4js)