Class: Videoinfo::Video
- Inherits:
-
Object
- Object
- Videoinfo::Video
- Defined in:
- lib/videoinfo/video.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#name ⇒ Object
Returns the value of attribute name.
-
#result ⇒ Object
Returns the value of attribute result.
-
#screenshots ⇒ Object
Returns the value of attribute screenshots.
Instance Method Summary collapse
- #capture_screenshots ⇒ Object
-
#initialize(name, file, screenshots = 0) ⇒ Video
constructor
A new instance of Video.
- #populate_result! ⇒ Object
- #read_mediainfo ⇒ Object
Constructor Details
#initialize(name, file, screenshots = 0) ⇒ Video
Returns a new instance of Video.
6 7 8 9 10 |
# File 'lib/videoinfo/video.rb', line 6 def initialize(name, file, screenshots = 0) self.name = name self.file = file self.screenshots = screenshots end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/videoinfo/video.rb', line 4 def file @file end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/videoinfo/video.rb', line 4 def name @name end |
#result ⇒ Object
Returns the value of attribute result.
4 5 6 |
# File 'lib/videoinfo/video.rb', line 4 def result @result end |
#screenshots ⇒ Object
Returns the value of attribute screenshots.
4 5 6 |
# File 'lib/videoinfo/video.rb', line 4 def screenshots @screenshots end |
Instance Method Details
#capture_screenshots ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/videoinfo/video.rb', line 36 def capture_screenshots return [] unless screenshots > 0 raise Error, "#{file}: file not found" unless File.file?(file) duration = %x(#{Videoinfo.mediainfo_binary} --Inform="General;%Duration%" #{file.shellescape}).strip.to_f / 1000 raise Error, 'unable to determine video duration' unless $?.success? && duration > 0 images = [] stepsize = screenshots == 1 ? 100 : 60 / (screenshots - 1) (20..80).step(stepsize) do |percent| image = Tempfile.new(["ss_#{percent}.", '.png']) %x(#{Videoinfo.ffmpeg_binary} -y -ss #{duration * percent / 100} -i #{file.shellescape} -vframes 1 -f image2 #{image.path} -v quiet) if $?.success? images << image else raise Error, "ERROR: unable to capture screenshot at #{percent}% into the video" end end images end |
#populate_result! ⇒ Object
20 21 22 23 24 25 |
# File 'lib/videoinfo/video.rb', line 20 def populate_result! result.mediainfo = read_mediainfo result.screenshot_urls = capture_screenshots.map { |ss| Videoinfo.upload_screenshot(ss) } result end |
#read_mediainfo ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/videoinfo/video.rb', line 27 def read_mediainfo raise Error, "#{file}: file not found" unless File.file?(file) info = Dir.chdir(File.dirname(file)) { %x(#{Videoinfo.mediainfo_binary} #{File.basename(file).shellescape}) } raise Error, 'unable to read mediainfo' unless $?.success? info end |