av 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75444062e1b869f7ee104f74d2f4db4e3896ef92
4
+ data.tar.gz: dd8fad78bb0571d02cb27fbf95827909a3f0f577
5
+ SHA512:
6
+ metadata.gz: f55ff0bb7bec672f7643183db7e1de02367af251677e3f8bc75884b6f95112b87eee1c99ea7815d54facfac7b01111de0b83873b97a663a0ffb540015405895f
7
+ data.tar.gz: 24448d70ddabe3af39e21cbaebbbe3483475bda29ff8cd39018e2cab3f8948046ad8b060b9dff9a92ceb49c658abfa091fd9bce41e5a8178ea48315140dd2d0f
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in av.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Omar Abdel-Wahab
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Av
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'av'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install av
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/av/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'av/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "av"
8
+ spec.version = Av::VERSION
9
+ spec.authors = ["Omar Abdel-Wahab"]
10
+ spec.email = ["owahab@gmail.com"]
11
+ spec.summary = %q{Programmable Ruby interface for FFMPEG/Libav}
12
+ spec.description = %q{Programmable Ruby interface for FFMPEG/Libav}
13
+ spec.homepage = "https://github.com/ruby-av"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 3.0.0"
24
+
25
+ spec.add_dependency "cocaine"
26
+ end
@@ -0,0 +1,59 @@
1
+ require "av/version"
2
+ require "av/exceptions"
3
+ require "cocaine"
4
+ require "av/commands/ffmpeg"
5
+ require "av/commands/avconv"
6
+
7
+ module Av
8
+ extend self
9
+
10
+ def cli
11
+ return @cli if @cli
12
+ @cli = load_av_library
13
+ @cli
14
+ end
15
+
16
+ def quiet
17
+ return @quiet if @quiet
18
+ true
19
+ end
20
+
21
+ def run line
22
+ Av.log("Running command: #{line}")
23
+ begin
24
+ Cocaine::CommandLine.new(line).run
25
+ rescue Cocaine::ExitStatusError => e
26
+ raise Av::CommandError, "error while running command #{line}: #{e}"
27
+ end
28
+ end
29
+
30
+ def log message
31
+ puts "[AV] #{message}"
32
+ end
33
+
34
+ def detect_command(command)
35
+ command = "if command -v #{command} 2>/dev/null; then echo \"true\"; else echo \"false\"; fi"
36
+ result = Av.run(command)
37
+ case result
38
+ when /true/
39
+ return true
40
+ when /false/
41
+ return false
42
+ end
43
+ end
44
+
45
+ def load_av_library
46
+ found = []
47
+ found << 'ffmpeg' if detect_command('ffmpeg')
48
+ found << 'avconv' if detect_command('avprobe')
49
+ Av.log("Found: #{found.inspect}")
50
+ if found.empty?
51
+ raise Av::UnableToDetect, "Unable to detect any supported library"
52
+ else
53
+ found.each do |library|
54
+ @cli = Object.const_get('Av').const_get('Commands').const_get(library.capitalize).new
55
+ end
56
+ end
57
+ @cli
58
+ end
59
+ end
@@ -0,0 +1,19 @@
1
+ require 'av/commands/base'
2
+
3
+ module Av
4
+ module Commands
5
+ class Avconv < Base
6
+
7
+ def initialize
8
+ super
9
+ @command_name = "avconv"
10
+ @default_params = %Q(-loglevel "quiet") if Av.quiet
11
+ end
12
+
13
+ def input_concat list
14
+ @input_params << %Q(-i concat:#{list.join('\|')} -c copy)
15
+ self
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,51 @@
1
+ require 'tmpdir'
2
+
3
+ module Av
4
+ module Commands
5
+ # Common features across commands
6
+ class Base
7
+ attr_accessor :command_name
8
+ attr_accessor :input_params
9
+ attr_accessor :output_params
10
+ attr_accessor :default_params
11
+
12
+ attr_accessor :source
13
+ attr_accessor :destination
14
+
15
+ def initialize
16
+ @input_params = []
17
+ @output_params = []
18
+ @default_params = []
19
+ end
20
+
21
+ def add_source src
22
+ @source = src
23
+ end
24
+
25
+ def add_destination dest
26
+ @destination = dest
27
+ end
28
+
29
+ def command_line
30
+ raise Av::CommandError if (@source.nil? && @destination.nil?) || @command_name.nil?
31
+
32
+ parameters = []
33
+ parameters << @command_name
34
+ parameters << @default_params if @default_params
35
+ if @input_params
36
+ parameters << @input_params.join(' ')
37
+ end
38
+ parameters << %Q(-i "#{@source}") if @source
39
+ if @output_params
40
+ parameters << @output_params.join(' ')
41
+ end
42
+ parameters << %Q(-y "#{@destination}") if @destination
43
+ parameters.flatten.compact.join(" ").strip.squeeze(" ")
44
+ end
45
+
46
+ def run
47
+ Av.run(command_line)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,25 @@
1
+ require 'av/commands/base'
2
+ require 'tempfile'
3
+
4
+ module Av
5
+ module Commands
6
+ class Ffmpeg < Base
7
+
8
+ def initialize
9
+ super
10
+ @command_name = "ffmpeg"
11
+ end
12
+
13
+ def input_concat list
14
+ index_file = Tempfile.new('ffmpeg-concat')
15
+ File.open(index_file, 'w') do |file|
16
+ list.each do |item|
17
+ file.write("file '#{item}'\n")
18
+ end
19
+ end
20
+ @input_params << "concat -i #{index_file.path}"
21
+ self
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,6 @@
1
+ module Av
2
+ class UnableToDetect < Exception; end
3
+ class CommandError < Exception; end
4
+ class InvalidInputFile < Exception; end
5
+ class InvalidOutputFile < Exception; end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Av
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Av do
4
+ it { expect(Av.cli).to be_kind_of Av::Commands::Base }
5
+ it { expect { Av.cli.run }.to raise_error Av::CommandError }
6
+
7
+ describe 'run' do
8
+ let(:subject) { Av.cli }
9
+ let(:source) { File.new(Dir.pwd + '/spec/support/assets/sample.mp4').path }
10
+ let(:destination) { "#{Dir.tmpdir}/test.mp4" }
11
+
12
+ before do
13
+ subject.add_source File.new(Dir.pwd + '/spec/support/assets/sample.mp4')
14
+ end
15
+
16
+ describe 'with a valid output file' do
17
+ before do
18
+ subject.add_source source
19
+ subject.add_destination destination
20
+ subject.run
21
+ end
22
+
23
+ it { expect(File.exists?(destination)).to eq true }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Av::Commands::Avconv do
4
+ let(:subject) { Av::Commands::Avconv.new }
5
+ let(:list) { ['one', 'two'] }
6
+
7
+ describe '.input_concat' do
8
+ before do
9
+ subject.input_concat(list)
10
+ end
11
+
12
+ it { expect(subject.input_params.first).to include %Q(concat:one\\|two) }
13
+ end
14
+ end
15
+
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Av::Commands::Ffmpeg do
4
+ let(:subject) { Av::Commands::Ffmpeg.new }
5
+ let(:list) { ['one', 'two'] }
6
+
7
+ describe '.input_concat' do
8
+ before do
9
+ subject.input_concat(list)
10
+ end
11
+
12
+ it { expect(subject.input_params.first).to include %Q(concat -i) }
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ Bundler.require(:default)
5
+
6
+ RSpec.configure do |config|
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run focus: true
9
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: av
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Omar Abdel-Wahab
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: cocaine
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Programmable Ruby interface for FFMPEG/Libav
70
+ email:
71
+ - owahab@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - av.gemspec
82
+ - lib/av.rb
83
+ - lib/av/commands/avconv.rb
84
+ - lib/av/commands/base.rb
85
+ - lib/av/commands/ffmpeg.rb
86
+ - lib/av/exceptions.rb
87
+ - lib/av/version.rb
88
+ - spec/av/av_spec.rb
89
+ - spec/av/avconv_spec.rb
90
+ - spec/av/ffmpeg_spec.rb
91
+ - spec/spec_helper.rb
92
+ - spec/support/assets/sample.mp4
93
+ homepage: https://github.com/ruby-av
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Programmable Ruby interface for FFMPEG/Libav
117
+ test_files:
118
+ - spec/av/av_spec.rb
119
+ - spec/av/avconv_spec.rb
120
+ - spec/av/ffmpeg_spec.rb
121
+ - spec/spec_helper.rb
122
+ - spec/support/assets/sample.mp4