av 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18f4f0325d4b9af49abd34117b65e75813252fc5
4
- data.tar.gz: 82007c918c6dbed310a06ad87f666f8361007bac
3
+ metadata.gz: 22be43869ad466b354fc8b29a8a0e3e85cc47cad
4
+ data.tar.gz: 4a90b4d4fd1dd385dd44b322a5f903bfc36c4641
5
5
  SHA512:
6
- metadata.gz: 189b6844e75dbd5950c5ece010486bf6baa7ea69b5c69e4cf6e32919af8e9b95dc6ff4fd057a5952ccc78cafbf853fae0fbcbf1ca718d95840456dc284855057
7
- data.tar.gz: 48c0873c6e8d35f00e304d005e18ddc21c593ec6ff37b36461e0934b5358df384c7a426eb078af454262ed1b5336cf6a545c44336b3f2e2ff1344657fe89d5bc
6
+ metadata.gz: a9aba31db65e5f2adabd4d619923371ac1f1a4a2a1753a1fffc6933f1b75face639e884ded35e2ca665855be95fa058e383dbd20f235b9673dcd334d72191a4c
7
+ data.tar.gz: ab8d8cea8456ea0a89abf152e83524dfacbd7973ca63981355c7e6b0d38cd8917a4b91527c4e7263bdfb93cee36db0736561d1e9d11117d402bb56879795ea47
data/README.md CHANGED
@@ -8,7 +8,7 @@ A Ruby Programmable interface for FFmpeg and Libav.
8
8
  [![Coverage Status](https://coveralls.io/repos/ruby-av/av/badge.png?branch=master)](https://coveralls.io/r/ruby-av/av?branch=master)
9
9
  [![Code Climate](https://codeclimate.com/github/ruby-av/av/badges/gpa.svg)](https://codeclimate.com/github/ruby-av/av)
10
10
  [![Dependency Status](https://gemnasium.com/ruby-av/av.svg)](https://gemnasium.com/ruby-av/av)
11
-
11
+ [![Gem Version](https://badge.fury.io/rb/av.svg)](http://badge.fury.io/rb/av)
12
12
  ## Installation
13
13
 
14
14
  Add this line to your application's Gemfile:
@@ -15,18 +15,18 @@ module Av
15
15
 
16
16
  attr_accessor :source
17
17
  attr_accessor :destination
18
-
18
+
19
19
  def initialize(options = {})
20
20
  reset_input_filters
21
21
  reset_output_filters
22
22
  reset_default_filters
23
23
  @options = options
24
24
  end
25
-
25
+
26
26
  def add_source src
27
27
  @source = src
28
28
  end
29
-
29
+
30
30
  def add_destination dest
31
31
  # infer format from extension unless format has already been set
32
32
  if @output_format.nil?
@@ -34,21 +34,21 @@ module Av
34
34
  end
35
35
  @destination = dest
36
36
  end
37
-
37
+
38
38
  def reset_input_filters
39
39
  @input_params = ParamHash.new
40
40
  @audio_filters = ParamHash.new
41
41
  @video_filters = ParamHash.new
42
42
  end
43
-
43
+
44
44
  def reset_output_filters
45
45
  @output_params = ParamHash.new
46
46
  end
47
-
47
+
48
48
  def reset_default_filters
49
49
  @default_params = ParamHash.new
50
50
  end
51
-
51
+
52
52
  def add_input_param *param
53
53
  p = parse_param(param)
54
54
  ::Av.log "Adding input parameter #{p}"
@@ -56,11 +56,11 @@ module Av
56
56
  @input_params[p[0]] << p[1]
57
57
  self
58
58
  end
59
-
59
+
60
60
  def set_input_params hash
61
61
  @input_params = hash
62
62
  end
63
-
63
+
64
64
  def add_output_param *param
65
65
  p = parse_param(param)
66
66
  ::Av.log "Adding output parameter #{p}"
@@ -68,11 +68,11 @@ module Av
68
68
  @output_params[p[0]] << p[1]
69
69
  self
70
70
  end
71
-
71
+
72
72
  def set_output_params hash
73
73
  @output_params = hash
74
74
  end
75
-
75
+
76
76
  def run
77
77
  raise Av::CommandError if (@source.nil? && @destination.nil?) || @command_name.nil?
78
78
 
@@ -90,7 +90,7 @@ module Av
90
90
  command_line = parameters.flatten.compact.join(" ").strip.squeeze(" ")
91
91
  ::Av.run(command_line)
92
92
  end
93
-
93
+
94
94
  def identify path
95
95
  meta = {}
96
96
  command = %Q(#{@command_name} -i "#{File.expand_path(path)}" 2>&1)
@@ -104,7 +104,10 @@ module Av
104
104
  if line =~ /Video:(.*)/
105
105
  size = $1.to_s.match(/\d{3,5}x\d{3,5}/).to_s
106
106
  meta[:size] = size unless size.empty?
107
- meta[:aspect] = size.split('x').first.to_f / size.split('x').last.to_f if meta[:size]
107
+ if meta[:size]
108
+ meta[:width], meta[:height] = meta[:size].split('x').map(&:to_i)
109
+ meta[:aspect] = meta[:width].to_f / meta[:height].to_f
110
+ end
108
111
  end
109
112
  # Matching Stream #0.0: Audio: libspeex, 8000 Hz, mono, s16
110
113
  if line =~ /Audio:(.*)/
@@ -113,19 +116,20 @@ module Av
113
116
  # Matching Duration: 00:01:31.66, start: 0.000000, bitrate: 10404 kb/s
114
117
  if line =~ /Duration:(\s.?(\d*):(\d*):(\d*\.\d*))/
115
118
  meta[:length] = $2.to_s + ":" + $3.to_s + ":" + $4.to_s
119
+ meta[:duration] = $2.to_i * 3600 + $3.to_i * 60 + $4.to_f
116
120
  end
117
121
  if line =~ /rotate\s*:\s(\d*)/
118
122
  meta[:rotate] = $1.to_i
119
123
  end
120
124
  end
121
125
  if meta.empty?
122
- ::Av.log "Empty metadata from #{path}. Got the following output: #{out}"
126
+ ::Av.log "Empty metadata from #{path}. Got the following output: #{out}"
123
127
  else
124
128
  return meta
125
129
  end
126
130
  nil
127
131
  end
128
-
132
+
129
133
  def output_format format
130
134
  @output_format = format
131
135
  case format.to_s
@@ -145,12 +149,23 @@ module Av
145
149
  add_output_param 'strict', 'experimental'
146
150
  end
147
151
  end
148
-
152
+
149
153
  # Children should override the following methods
150
154
  def filter_rotate degrees
151
155
  raise ::Av::FilterNotImplemented, 'rotate'
152
156
  end
153
-
157
+
158
+ # Children should override the following methods
159
+ def filter_volume vol
160
+ raise ::Av::FilterNotImplemented, 'volume'
161
+ end
162
+
163
+ # ffmpeg and avconf both have the same seeking params
164
+ def filter_seek seek
165
+ add_input_param ss: seek
166
+ self
167
+ end
168
+
154
169
  def parse_param param
155
170
  list = []
156
171
  if param.count == 2
@@ -165,6 +180,6 @@ module Av
165
180
  end
166
181
  list
167
182
  end
168
- end
183
+ end
169
184
  end
170
185
  end
@@ -1,3 +1,3 @@
1
1
  module Av
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -3,23 +3,23 @@ require 'spec_helper'
3
3
  describe Av::Commands::Base do
4
4
  let(:subject) { Av.cli }
5
5
  let(:source) { File.new(Dir.pwd + '/spec/support/assets/sample.mp4').path }
6
-
6
+
7
7
  describe '.identify' do
8
8
  describe 'supported files' do
9
9
  let(:meta) { subject.identify source }
10
-
10
+
11
11
  it { expect(meta).to be_a Hash }
12
- it { expect(meta.keys).to include :size, :aspect }
12
+ it { expect(meta.keys).to include :size, :aspect, :width, :height, :length, :duration }
13
13
  end
14
14
 
15
15
  describe 'unsupported files' do
16
16
  let(:unsupported) { File.new(Dir.pwd + '/spec/support/assets/image.png').path }
17
17
  let(:meta) { subject.identify unsupported }
18
-
18
+
19
19
  it { expect(meta).to be_nil }
20
20
  end
21
21
  end
22
-
22
+
23
23
  describe '.add_input_param' do
24
24
  before do
25
25
  subject.add_input_param({k: 'value'})
@@ -49,7 +49,15 @@ describe Av::Commands::Base do
49
49
  it { expect(subject.output_params.to_s).to eq '-k value value1 value2 -x y' }
50
50
  end
51
51
  end
52
-
52
+
53
+ describe '.filter_seek' do
54
+ before do
55
+ subject.filter_seek('00:00:01.11')
56
+ end
57
+
58
+ it { expect(subject.input_params.to_s).to eq "-ss 00:00:01.11" }
59
+ end
60
+
53
61
  describe '.run' do
54
62
  before do
55
63
  subject.add_output_param(ar: 44100)
@@ -57,7 +65,7 @@ describe Av::Commands::Base do
57
65
  subject.add_destination(Tempfile.new(['one', '.ogv']).path)
58
66
  end
59
67
  it { expect { subject.run }.not_to raise_exception }
60
-
68
+
61
69
  end
62
70
  end
63
71
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: av
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Omar Abdel-Wahab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-11 00:00:00.000000000 Z
11
+ date: 2015-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler