include GetText
require 'rexml/document'
include REXML
+require 'timeout'
require 'html_merges'
end
end
+#- grab the results of a command but don't sleep forever on a runaway process
+def subproc_runaway_aware(command)
+ begin
+ timeout(5) {
+ return `#{command}`
+ }
+ rescue Timeout::Error
+ msg 1, _("forgetting runaway process (transcode sucks again?)")
+ #- todo should slay transcode but dunno how to do that
+ return nil
+ end
+end
+
def gen_thumbnails(orig, dests)
if !dests.detect { |dest| !File.exists?(dest['filename']) }
return true
if !File.exists?("#{dest_dir}/screenshot.jpg000004.jpg")
cmd = "transcode -a 0 -c 0-5 -i '#{orig}' -y jpg -o '#{dest_dir}/screenshot.jpg' 2>&1"
msg 2, cmd
- results = `#{cmd}`
- if results =~ /V: import format.*unknown/ || !File.exists?("#{dest_dir}/screenshot.jpg000004.jpg")
- msg 1, __("could not extract first image of video %s with transcode, will try first converting with mencoder", dest['filename'])
+ if subproc_runaway_aware(cmd) =~ /V: import format.*unknown/ || !File.exists?("#{dest_dir}/screenshot.jpg000004.jpg")
+ msg 2, __("* could not extract first image of video %s with transcode, will try first converting with mencoder", orig)
cmd = "mencoder '#{orig}' -nosound -ovc lavc -lavcopts vcodec=mpeg4 -o '#{dest_dir}/foo.avi' -frames 5 >/dev/null 2>/dev/null"
msg 2, cmd
system cmd
if File.exists?("#{dest_dir}/foo.avi")
cmd = "transcode -a 0 -c 0-5 -i '#{dest_dir}/foo.avi' -y jpg -o '#{dest_dir}/screenshot.jpg' 2>&1"
msg 2, cmd
- results = `#{cmd}`
+ results = subproc_runaway_aware(cmd)
system("rm -f '#{dest_dir}/foo.avi'")
if results =~ /V: import format.*unknown/ || !File.exists?("#{dest_dir}/screenshot.jpg000004.jpg")
msg 0, __("could not extract first image of video %s encoded by mencoder", "#{dest_dir}/foo.avi")