Class: Audiomator::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/audiomator/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Record

Returns a new instance of Record.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/audiomator/record.rb', line 14

def initialize(path)
  fail Errno::ENOENT, "'#{path}' does not exist" unless File.exist?(path)
  @path = path

  # ffmpeg will output to stderr
  @output = Open3.popen3(ffmpeg_command) { |_stdin, _stdout, stderr| stderr.read }

  parse_container
  parse_duration
  parse_time
  parse_creation_time
  parse_stream_info
  validate
end

Instance Attribute Details

#bitrateObject (readonly)

Returns the value of attribute bitrate.



10
11
12
# File 'lib/audiomator/record.rb', line 10

def bitrate
  @bitrate
end

#codecObject (readonly)

Returns the value of attribute codec.



11
12
13
# File 'lib/audiomator/record.rb', line 11

def codec
  @codec
end

#containerObject (readonly)

Returns the value of attribute container.



12
13
14
# File 'lib/audiomator/record.rb', line 12

def container
  @container
end

#creation_timeObject (readonly)

Returns the value of attribute creation_time.



10
11
12
# File 'lib/audiomator/record.rb', line 10

def creation_time
  @creation_time
end

#durationObject (readonly)

Returns the value of attribute duration.



10
11
12
# File 'lib/audiomator/record.rb', line 10

def duration
  @duration
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/audiomator/record.rb', line 10

def path
  @path
end

#rotationObject (readonly)

Returns the value of attribute rotation.



10
11
12
# File 'lib/audiomator/record.rb', line 10

def rotation
  @rotation
end

#sample_rateObject (readonly)

Returns the value of attribute sample_rate.



11
12
13
# File 'lib/audiomator/record.rb', line 11

def sample_rate
  @sample_rate
end

#streamObject (readonly)

Returns the value of attribute stream.



11
12
13
# File 'lib/audiomator/record.rb', line 11

def stream
  @stream
end

#timeObject (readonly)

Returns the value of attribute time.



10
11
12
# File 'lib/audiomator/record.rb', line 10

def time
  @time
end

Instance Method Details

#basenameObject



37
38
39
# File 'lib/audiomator/record.rb', line 37

def basename
  File.basename(@path, '.*')
end

#clip(start_time, end_time, output = nil, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/audiomator/record.rb', line 41

def clip(start_time, end_time, output = nil, options = {})
  options = default_clip_options.merge!(options)
  output = output_file(start_time, end_time, options) unless output
  FileUtils.mkdir_p(File.dirname(output)) unless Dir.exist?(File.dirname(output))
  opts = Options.new(start_time,
                     end_time,
                     options[:bitrate],
                     options[:sample_rate],
                     options[:metadata])
  command = [ffmpeg_command, opts.to_s, output].join(' ')
  Audiomator.logger.info("Running audio processing...\n #{command}\n")
  @output_error = ''

  begin
    Timeout.timeout(Audiomator.timeout) do
      _stdout, stderr, status = Open3.capture3(command)
      @output_error = stderr
      unless status.success?
        fail Error, "Proecess Failed, Full output: #{stderr}"
      end
    end
  rescue Timeout::Error => e
    raise Error, "Proecess Timeout #{e.message} \n: #{@output_error} \n"
  end
  Audiomator.logger.info("Audio processing finished\n")
end

#sizeObject



33
34
35
# File 'lib/audiomator/record.rb', line 33

def size
  File.size(@path)
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/audiomator/record.rb', line 29

def valid?
  !@invalid
end