Class: VCSRuby::LibAV

Inherits:
Capturer show all
Defined in:
lib/libAV/libav.rb

Constant Summary collapse

HEADER =
10
ENCODING_SUPPORT =
2
VIDEO_CODEC =
3
NAME =
8

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Capturer

create, #format, #format=, #format_extension, initialize_capturers

Constructor Details

#initialize(video) ⇒ LibAV

Returns a new instance of LibAV.



19
20
21
22
23
24
25
# File 'lib/libAV/libav.rb', line 19

def initialize video
  @video = video
  @avconv = Command.new :libav, 'avconv'
  @avprobe = Command.new :libav, 'avprobe'

  detect_version if available?
end

Instance Attribute Details

#audio_streamsObject (readonly)

Returns the value of attribute audio_streams.



17
18
19
# File 'lib/libAV/libav.rb', line 17

def audio_streams
  @audio_streams
end

#infoObject (readonly)

Returns the value of attribute info.



17
18
19
# File 'lib/libAV/libav.rb', line 17

def info
  @info
end

#video_streamsObject (readonly)

Returns the value of attribute video_streams.



17
18
19
# File 'lib/libAV/libav.rb', line 17

def video_streams
  @video_streams
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/libAV/libav.rb', line 35

def available?
  @avconv.available? && @avprobe.available?
end

#available_formatsObject



54
55
56
# File 'lib/libAV/libav.rb', line 54

def available_formats
  @available_formats ||= available_formats_query
end

#available_formats_queryObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/libAV/libav.rb', line 58

def available_formats_query
  # Ordered by priority
  image_formats = ['png', 'tiff', 'bmp', 'mjpeg']
  formats = []

  list = @avprobe.execute "-codecs"
  list.lines.drop(HEADER).each do |codec|
    name, e, v = format_split(codec)
    formats << name if image_formats.include?(name) && e && v
  end

  image_formats.select{ |format| formats.include?(format) }.map(&:to_sym)
end

#detect_versionObject



40
41
42
43
44
45
46
# File 'lib/libAV/libav.rb', line 40

def detect_version
  info = @avconv.execute('-version')
  match = /avconv ([\d|\.|\-|:]*)/.match(info)
  if match
    @version = match[1]
  end
end

#file_valid?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/libAV/libav.rb', line 27

def file_valid?
  return probe_meta_information
end

#grab(time, image_path) ⇒ Object



50
51
52
# File 'lib/libAV/libav.rb', line 50

def grab time, image_path
  @avconv.execute "-y -ss #{time.total_seconds} -i \"#{@video.full_path}\" -an -dframes 1 -vframes 1 -vcodec #{format} -f rawvideo \"#{image_path}\""
end

#nameObject



31
32
33
# File 'lib/libAV/libav.rb', line 31

def name
  :libav
end

#to_sObject



72
73
74
# File 'lib/libAV/libav.rb', line 72

def to_s
  "LibAV #{@version}"
end