Class: Audiomator::Record
- Inherits:
-
Object
- Object
- Audiomator::Record
- Defined in:
- lib/audiomator/record.rb
Instance Attribute Summary collapse
-
#bitrate ⇒ Object
readonly
Returns the value of attribute bitrate.
-
#codec ⇒ Object
readonly
Returns the value of attribute codec.
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#creation_time ⇒ Object
readonly
Returns the value of attribute creation_time.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#rotation ⇒ Object
readonly
Returns the value of attribute rotation.
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #basename ⇒ Object
- #clip(start_time, end_time, output = nil, options = {}) ⇒ Object
-
#initialize(path) ⇒ Record
constructor
A new instance of Record.
- #size ⇒ Object
- #valid? ⇒ Boolean
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
#bitrate ⇒ Object (readonly)
Returns the value of attribute bitrate.
10 11 12 |
# File 'lib/audiomator/record.rb', line 10 def bitrate @bitrate end |
#codec ⇒ Object (readonly)
Returns the value of attribute codec.
11 12 13 |
# File 'lib/audiomator/record.rb', line 11 def codec @codec end |
#container ⇒ Object (readonly)
Returns the value of attribute container.
12 13 14 |
# File 'lib/audiomator/record.rb', line 12 def container @container end |
#creation_time ⇒ Object (readonly)
Returns the value of attribute creation_time.
10 11 12 |
# File 'lib/audiomator/record.rb', line 10 def creation_time @creation_time end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
10 11 12 |
# File 'lib/audiomator/record.rb', line 10 def duration @duration end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/audiomator/record.rb', line 10 def path @path end |
#rotation ⇒ Object (readonly)
Returns the value of attribute rotation.
10 11 12 |
# File 'lib/audiomator/record.rb', line 10 def rotation @rotation end |
#sample_rate ⇒ Object (readonly)
Returns the value of attribute sample_rate.
11 12 13 |
# File 'lib/audiomator/record.rb', line 11 def sample_rate @sample_rate end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
11 12 13 |
# File 'lib/audiomator/record.rb', line 11 def stream @stream end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
10 11 12 |
# File 'lib/audiomator/record.rb', line 10 def time @time end |
Instance Method Details
#basename ⇒ Object
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, = {}) = .merge!() output = output_file(start_time, end_time, ) unless output FileUtils.mkdir_p(File.dirname(output)) unless Dir.exist?(File.dirname(output)) opts = Options.new(start_time, end_time, [:bitrate], [:sample_rate], [: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.} \n: #{@output_error} \n" end Audiomator.logger.info("Audio processing finished\n") end |
#size ⇒ Object
33 34 35 |
# File 'lib/audiomator/record.rb', line 33 def size File.size(@path) end |
#valid? ⇒ Boolean
29 30 31 |
# File 'lib/audiomator/record.rb', line 29 def valid? !@invalid end |