- use mencoder when transcode is not strong enough
authorgc <gc>
Sun, 6 Mar 2005 18:05:51 +0000 (18:05 +0000)
committergc <gc>
Sun, 6 Mar 2005 18:05:51 +0000 (18:05 +0000)
- handle no preview for videos

booh

diff --git a/booh b/booh
index 06e58dc5350a9d7f5660ddef4b14b1e1685ec7bc..946d81deeaf7ba85d823a8b4b3f2c6c3d3cdf1cc 100755 (executable)
--- a/booh
+++ b/booh
@@ -75,9 +75,9 @@ end
 def msg(verbose_level, msg)
     if verbose_level <= $verbose_level
         if verbose_level == 0
-            warn __("***ERROR***: %s", msg)
+            warn __("\t***ERROR***: %s\n", msg)
         elsif verbose_level == 1
-            warn __("Warning: %s", msg)
+            warn __("\tWarning: %s\n", msg)
         else
             puts msg
         end
@@ -321,16 +321,36 @@ def walk_source_dir
 
         #- create thumbnails for videos
         videos.each { |video|
+            thumbnail_ok = true
             for sizeobj in $images_size
                 size_thumbnails = sizeobj['thumbnails']
                 thumbnail_dest_img = dest_dir + '/' + video.sub(/\.[^\.]+$/, '') + "-#{size_thumbnails}.jpg"
                 thumbnail_videos[sizeobj['name']] << File.basename(thumbnail_dest_img)
-                if !File.exists?(thumbnail_dest_img)
+                if !File.exists?(thumbnail_dest_img) && thumbnail_ok
                     if !File.exists?("#{dest_dir}/screenshot.jpg000000.jpg")
-                        cmd = "transcode -a 0 -c 1 -i '#{dir}/#{video}' -y jpg -o '#{dest_dir}/screenshot.jpg' >/dev/null 2>/dev/null"
+                        cmd = "transcode -a 0 -c 1 -i '#{dir}/#{video}' -y jpg -o '#{dest_dir}/screenshot.jpg' 2>&1"
                         msg 2, cmd
-                        if !system(cmd)
-                            break
+                        results = `#{cmd}`
+                        if results =~ /V: import format.*unknown/ || !File.exists?("#{dest_dir}/screenshot.jpg000000.jpg")
+                            msg 1, __("could not extract first image of video %s with transcode, will try first converting with mencoder", "#{dir}/#{video}")
+                            cmd = "mencoder '#{dir}/#{video}' -nosound -ovc lavc -lavcopts vcodec=mpeg4 -o '#{dest_dir}/foo.avi' -frames 1 >/dev/null 2>/dev/null"
+                            msg 2, cmd
+                            system cmd
+                            if File.exists?("#{dest_dir}/foo.avi")
+                                cmd = "transcode -a 0 -c 1 -i '#{dest_dir}/foo.avi' -y jpg -o '#{dest_dir}/screenshot.jpg' 2>&1"
+                                msg 2, cmd
+                                results = `#{cmd}`
+                                system("rm -f '#{dest_dir}/foo.avi'")
+                                if results =~ /V: import format.*unknown/ || !File.exists?("#{dest_dir}/screenshot.jpg000000.jpg")
+                                    msg 0, __("could not extract first image of video %s encoded by mencoder", "#{dest_dir}/foo.avi")
+                                    thumbnail_ok = false
+                                    next
+                                end
+                            else
+                                msg 0, __("could not make mencoder to encode %s to mpeg4", "#{dir}/#{video}")
+                                thumbnail_ok = false
+                                next
+                            end
                         end
                     end
                     sys("#{$convert} -geometry #{size_thumbnails} #{dest_dir}/screenshot.jpg000000.jpg '#{thumbnail_dest_img}'")
@@ -340,10 +360,7 @@ def walk_source_dir
             if !File.exists?(destvideo)
                 psys("cp '#{dir}/#{video}' '#{destvideo}'")
             end
-            if File.exists?("#{dest_dir}/screenshot.jpg000000.jpg")
-                File.delete("#{dest_dir}/screenshot.jpg000000.jpg")
-            end
-            #mencoder $i -nosound -ovc lavc -lavcopts vcodec=mpeg4 -o foo.avi -frames 1
+            system("rm -f '#{dest_dir}/screenshot.jpg000000.jpg'")
         }
 
         sizenames = { 'small' => _("small"), 'medium' => _("medium"), 'large' => _("large") }
@@ -421,8 +438,13 @@ def walk_source_dir
                         html_thumbnails.gsub!(/~~ifvideo\?~~[^~]+~~/, '')
                     elsif type == 'video'
                         index = videos.index(file)
-                        html_thumbnails.gsub!(/~~image_iteration~~/,
-                                              '<a href="' + videos[index] + '"><img src="' + thumbnail_videos[sizeobj['name']][index] + '" border="0"/></a>')
+                        if File.exists?("#{dest_dir}/#{thumbnail_videos[sizeobj['name']][index]}")
+                            html_thumbnails.gsub!(/~~image_iteration~~/,
+                                                  '<a href="' + videos[index] + '"><img src="' + thumbnail_videos[sizeobj['name']][index] + '" border="0"/></a>')
+                        else
+                            html_thumbnails.gsub!(/~~image_iteration~~/,
+                                                  '<a href="' + videos[index] + '">' + _("(no preview)") + '</a>')
+                        end
                         html_thumbnails.gsub!(/~~caption_iteration~~/,
                                               find_caption_value("#{dir}/#{videos[index]}") || videos[index])
                         html_thumbnails.gsub!(/~~ifimage\?~~[^~]+~~/, '')