av 0.0.1 → 0.0.2
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 +4 -4
 - data/lib/av.rb +2 -2
 - data/lib/av/commands/avconv.rb +5 -1
 - data/lib/av/commands/base.rb +31 -0
 - data/lib/av/commands/ffmpeg.rb +5 -1
 - data/lib/av/version.rb +1 -1
 - data/spec/av/avconv_spec.rb +10 -2
 - data/spec/av/base_spec.rb +14 -0
 - data/spec/av/ffmpeg_spec.rb +10 -2
 - metadata +3 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4eb96469037b44a476417432ba11e3487c8e5d48
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 1beaccbfdc03404ab940ec6f0a9dac36e2cfcd0c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 378c8cf269006953df35555e2c36438b2cd82a565fe5c1bf72a46aed469cbb92097519dbddbe26a9f728b8df98ac32bd915f5dea53c7818dc2d0dfb69ef5329b
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: bff6b5805a553aa1a62d2abf3e6ae365f124b0e75f12ecd476fe9f4fe8cc7f8fdf67d89f85c2326f0e31bca41bf4a6f9161d1b76d1a7f873f90553af2311f53b
         
     | 
    
        data/lib/av.rb
    CHANGED
    
    | 
         @@ -18,10 +18,10 @@ module Av 
     | 
|
| 
       18 
18 
     | 
    
         
             
                true
         
     | 
| 
       19 
19 
     | 
    
         
             
              end
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
              def run line
         
     | 
| 
      
 21 
     | 
    
         
            +
              def run line, codes = [0]
         
     | 
| 
       22 
22 
     | 
    
         
             
                Av.log("Running command: #{line}")
         
     | 
| 
       23 
23 
     | 
    
         
             
                begin
         
     | 
| 
       24 
     | 
    
         
            -
                  Cocaine::CommandLine.new(line).run
         
     | 
| 
      
 24 
     | 
    
         
            +
                  Cocaine::CommandLine.new(line, "", expected_outcodes: codes).run
         
     | 
| 
       25 
25 
     | 
    
         
             
                rescue Cocaine::ExitStatusError => e
         
     | 
| 
       26 
26 
     | 
    
         
             
                  raise Av::CommandError, "error while running command #{line}: #{e}"
         
     | 
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
    
        data/lib/av/commands/avconv.rb
    CHANGED
    
    | 
         @@ -10,10 +10,14 @@ module Av 
     | 
|
| 
       10 
10 
     | 
    
         
             
                    @default_params = %Q(-loglevel "quiet") if Av.quiet
         
     | 
| 
       11 
11 
     | 
    
         
             
                  end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                  def  
     | 
| 
      
 13 
     | 
    
         
            +
                  def filter_concat list
         
     | 
| 
       14 
14 
     | 
    
         
             
                    @input_params << %Q(-i concat:#{list.join('\|')} -c copy)
         
     | 
| 
       15 
15 
     | 
    
         
             
                    self
         
     | 
| 
       16 
16 
     | 
    
         
             
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
                  
         
     | 
| 
      
 18 
     | 
    
         
            +
                  def filter_volume vol
         
     | 
| 
      
 19 
     | 
    
         
            +
                    @input_params << "-af volume=volume=#{vol}"
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
       17 
21 
     | 
    
         
             
                end
         
     | 
| 
       18 
22 
     | 
    
         
             
              end
         
     | 
| 
       19 
23 
     | 
    
         
             
            end
         
     | 
    
        data/lib/av/commands/base.rb
    CHANGED
    
    | 
         @@ -46,6 +46,37 @@ module Av 
     | 
|
| 
       46 
46 
     | 
    
         
             
                  def run
         
     | 
| 
       47 
47 
     | 
    
         
             
                    Av.run(command_line)
         
     | 
| 
       48 
48 
     | 
    
         
             
                  end
         
     | 
| 
      
 49 
     | 
    
         
            +
                  
         
     | 
| 
      
 50 
     | 
    
         
            +
                  def identify path
         
     | 
| 
      
 51 
     | 
    
         
            +
                    meta = {}
         
     | 
| 
      
 52 
     | 
    
         
            +
                    command = %Q(#{@command_name} -i "#{File.expand_path(path)}" 2>&1)
         
     | 
| 
      
 53 
     | 
    
         
            +
                    out = Av.run(command, [0,1])
         
     | 
| 
      
 54 
     | 
    
         
            +
                    # rescue Av::CommandError
         
     | 
| 
      
 55 
     | 
    
         
            +
                    #   # Do nothing, we know ffmpeg/avconv will complain with:
         
     | 
| 
      
 56 
     | 
    
         
            +
                    #   # "At least one output file must be specified"
         
     | 
| 
      
 57 
     | 
    
         
            +
                    # end
         
     | 
| 
      
 58 
     | 
    
         
            +
                    out.split("\n").each do |line|
         
     | 
| 
      
 59 
     | 
    
         
            +
                      if line =~ /(([\d\.]*)\s.?)fps,/
         
     | 
| 
      
 60 
     | 
    
         
            +
                        meta[:fps] = $1.to_i
         
     | 
| 
      
 61 
     | 
    
         
            +
                      end
         
     | 
| 
      
 62 
     | 
    
         
            +
                      # Matching lines like:
         
     | 
| 
      
 63 
     | 
    
         
            +
                      # Video: h264, yuvj420p, 640x480 [PAR 72:72 DAR 4:3], 10301 kb/s, 30 fps, 30 tbr, 600 tbn, 600 tbc
         
     | 
| 
      
 64 
     | 
    
         
            +
                      if line =~ /Video:(.*)/
         
     | 
| 
      
 65 
     | 
    
         
            +
                         v = $1.to_s
         
     | 
| 
      
 66 
     | 
    
         
            +
                         size = v.match(/\d{3,5}x\d{3,5}/).to_s
         
     | 
| 
      
 67 
     | 
    
         
            +
                         meta[:size] = size
         
     | 
| 
      
 68 
     | 
    
         
            +
                         meta[:aspect] = size.split('x').first.to_f / size.split('x').last.to_f
         
     | 
| 
      
 69 
     | 
    
         
            +
                       end
         
     | 
| 
      
 70 
     | 
    
         
            +
                      # Matching Duration: 00:01:31.66, start: 0.000000, bitrate: 10404 kb/s
         
     | 
| 
      
 71 
     | 
    
         
            +
                      if line =~ /Duration:(\s.?(\d*):(\d*):(\d*\.\d*))/
         
     | 
| 
      
 72 
     | 
    
         
            +
                        meta[:length] = $2.to_s + ":" + $3.to_s + ":" + $4.to_s
         
     | 
| 
      
 73 
     | 
    
         
            +
                      end
         
     | 
| 
      
 74 
     | 
    
         
            +
                      if line =~ /rotate\s*:\s(\d*)/
         
     | 
| 
      
 75 
     | 
    
         
            +
                        meta[:rotate] = $1.to_i
         
     | 
| 
      
 76 
     | 
    
         
            +
                      end
         
     | 
| 
      
 77 
     | 
    
         
            +
                    end
         
     | 
| 
      
 78 
     | 
    
         
            +
                    meta
         
     | 
| 
      
 79 
     | 
    
         
            +
                  end
         
     | 
| 
       49 
80 
     | 
    
         
             
                end  
         
     | 
| 
       50 
81 
     | 
    
         
             
              end
         
     | 
| 
       51 
82 
     | 
    
         
             
            end
         
     | 
    
        data/lib/av/commands/ffmpeg.rb
    CHANGED
    
    | 
         @@ -10,7 +10,7 @@ module Av 
     | 
|
| 
       10 
10 
     | 
    
         
             
                    @command_name = "ffmpeg"
         
     | 
| 
       11 
11 
     | 
    
         
             
                  end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                  def  
     | 
| 
      
 13 
     | 
    
         
            +
                  def filter_concat list
         
     | 
| 
       14 
14 
     | 
    
         
             
                    index_file = Tempfile.new('ffmpeg-concat')
         
     | 
| 
       15 
15 
     | 
    
         
             
                    File.open(index_file, 'w') do |file|
         
     | 
| 
       16 
16 
     | 
    
         
             
                      list.each do |item|
         
     | 
| 
         @@ -20,6 +20,10 @@ module Av 
     | 
|
| 
       20 
20 
     | 
    
         
             
                    @input_params << "concat -i #{index_file.path}"
         
     | 
| 
       21 
21 
     | 
    
         
             
                    self
         
     | 
| 
       22 
22 
     | 
    
         
             
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
                  
         
     | 
| 
      
 24 
     | 
    
         
            +
                  def filter_volume vol
         
     | 
| 
      
 25 
     | 
    
         
            +
                    @input_params << "-af volume=#{vol}"
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
       23 
27 
     | 
    
         
             
                end
         
     | 
| 
       24 
28 
     | 
    
         
             
              end
         
     | 
| 
       25 
29 
     | 
    
         
             
            end
         
     | 
    
        data/lib/av/version.rb
    CHANGED
    
    
    
        data/spec/av/avconv_spec.rb
    CHANGED
    
    | 
         @@ -4,12 +4,20 @@ describe Av::Commands::Avconv do 
     | 
|
| 
       4 
4 
     | 
    
         
             
              let(:subject) { Av::Commands::Avconv.new }
         
     | 
| 
       5 
5 
     | 
    
         
             
              let(:list) { ['one', 'two'] }
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
              describe '. 
     | 
| 
      
 7 
     | 
    
         
            +
              describe '.filter_concat' do
         
     | 
| 
       8 
8 
     | 
    
         
             
                before do
         
     | 
| 
       9 
     | 
    
         
            -
                  subject. 
     | 
| 
      
 9 
     | 
    
         
            +
                  subject.filter_concat(list)
         
     | 
| 
       10 
10 
     | 
    
         
             
                end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                it { expect(subject.input_params.first).to include %Q(concat:one\\|two) }
         
     | 
| 
       13 
13 
     | 
    
         
             
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              describe '.filter_volume' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                before do
         
     | 
| 
      
 17 
     | 
    
         
            +
                  subject.filter_volume('0.5')
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
                
         
     | 
| 
      
 20 
     | 
    
         
            +
                it { expect(subject.input_params.first).to eq "-af volume=volume=0.5" }
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
       14 
22 
     | 
    
         
             
            end
         
     | 
| 
       15 
23 
     | 
    
         | 
| 
         @@ -0,0 +1,14 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Av::Commands::Base do
         
     | 
| 
      
 4 
     | 
    
         
            +
              let(:subject) { Av.cli }
         
     | 
| 
      
 5 
     | 
    
         
            +
              let(:source) { File.new(Dir.pwd + '/spec/support/assets/sample.mp4').path }
         
     | 
| 
      
 6 
     | 
    
         
            +
              
         
     | 
| 
      
 7 
     | 
    
         
            +
              describe '.identify' do
         
     | 
| 
      
 8 
     | 
    
         
            +
                let(:meta) { subject.identify source }
         
     | 
| 
      
 9 
     | 
    
         
            +
                
         
     | 
| 
      
 10 
     | 
    
         
            +
                it { expect(meta).to be_a Hash }
         
     | 
| 
      
 11 
     | 
    
         
            +
                it { expect(meta.keys).to include :size, :fps, :length, :aspect }
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
    
        data/spec/av/ffmpeg_spec.rb
    CHANGED
    
    | 
         @@ -4,11 +4,19 @@ describe Av::Commands::Ffmpeg do 
     | 
|
| 
       4 
4 
     | 
    
         
             
              let(:subject) { Av::Commands::Ffmpeg.new }
         
     | 
| 
       5 
5 
     | 
    
         
             
              let(:list) { ['one', 'two'] }
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
              describe '. 
     | 
| 
      
 7 
     | 
    
         
            +
              describe '.filter_concat' do
         
     | 
| 
       8 
8 
     | 
    
         
             
                before do
         
     | 
| 
       9 
     | 
    
         
            -
                  subject. 
     | 
| 
      
 9 
     | 
    
         
            +
                  subject.filter_concat(list)
         
     | 
| 
       10 
10 
     | 
    
         
             
                end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                it { expect(subject.input_params.first).to include %Q(concat -i) }
         
     | 
| 
       13 
13 
     | 
    
         
             
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              describe '.filter_volume' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                before do
         
     | 
| 
      
 17 
     | 
    
         
            +
                  subject.filter_volume('0.5')
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
                
         
     | 
| 
      
 20 
     | 
    
         
            +
                it { expect(subject.input_params.first).to eq "-af volume=0.5" }
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
       14 
22 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: av
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Omar Abdel-Wahab
         
     | 
| 
         @@ -87,6 +87,7 @@ files: 
     | 
|
| 
       87 
87 
     | 
    
         
             
            - lib/av/version.rb
         
     | 
| 
       88 
88 
     | 
    
         
             
            - spec/av/av_spec.rb
         
     | 
| 
       89 
89 
     | 
    
         
             
            - spec/av/avconv_spec.rb
         
     | 
| 
      
 90 
     | 
    
         
            +
            - spec/av/base_spec.rb
         
     | 
| 
       90 
91 
     | 
    
         
             
            - spec/av/ffmpeg_spec.rb
         
     | 
| 
       91 
92 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       92 
93 
     | 
    
         
             
            - spec/support/assets/sample.mp4
         
     | 
| 
         @@ -117,6 +118,7 @@ summary: Programmable Ruby interface for FFMPEG/Libav 
     | 
|
| 
       117 
118 
     | 
    
         
             
            test_files:
         
     | 
| 
       118 
119 
     | 
    
         
             
            - spec/av/av_spec.rb
         
     | 
| 
       119 
120 
     | 
    
         
             
            - spec/av/avconv_spec.rb
         
     | 
| 
      
 121 
     | 
    
         
            +
            - spec/av/base_spec.rb
         
     | 
| 
       120 
122 
     | 
    
         
             
            - spec/av/ffmpeg_spec.rb
         
     | 
| 
       121 
123 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       122 
124 
     | 
    
         
             
            - spec/support/assets/sample.mp4
         
     |