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
#- 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}'")
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") }
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\?~~[^~]+~~/, '')