fastforward 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fastforward.gemspec
4
+ gemspec
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "fastforward"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "fastforward/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "fastforward"
7
+ s.version = FastForward::VERSION
8
+ s.authors = ["Ben Marini"]
9
+ s.email = ["bmarini@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A ruby cli wrapper for FFmpeg}
12
+ s.description = %q{A ruby cli wrapper for FFmpeg}
13
+
14
+ s.rubyforge_project = "fastforward"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec", "~> 2.8.0"
22
+
23
+ s.add_runtime_dependency "sh", "~> 0.0.2"
24
+ end
@@ -0,0 +1,15 @@
1
+ require "sh"
2
+ require "fastforward/version"
3
+ require "fastforward/builder"
4
+ require "fastforward/option"
5
+ require "fastforward/options"
6
+ require "fastforward/input_output_options"
7
+ require "fastforward/input"
8
+ require "fastforward/output"
9
+
10
+ module FastForward
11
+ # Your code goes here...
12
+ def self.build(&block)
13
+ Builder.new(&block)
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ module FastForward
2
+ class Builder
3
+ def initialize
4
+ @global_options = []
5
+ @inputs = []
6
+ @outputs = []
7
+
8
+ yield(self) if block_given?
9
+ end
10
+
11
+ def input(filename, &block)
12
+ @inputs.push Input.new(filename, &block)
13
+ end
14
+
15
+ def output(filename, &block)
16
+ @outputs.push Output.new(filename, &block)
17
+ end
18
+
19
+ def command
20
+ cmd = Sh::Cmd.new("ffmpeg") do |c|
21
+ @inputs.each do |input|
22
+ input.options.each do |option|
23
+ c.opt(option.name).arg(option.value)
24
+ end
25
+ c.opt("-i").arg(input.filename)
26
+ end
27
+
28
+ @outputs.each do |output|
29
+ output.options.each do |option|
30
+ c.opt(option.name).arg(option.value)
31
+ end
32
+ c.arg(output.filename)
33
+ end
34
+ end
35
+ end
36
+
37
+ def to_s
38
+ command.to_s
39
+ end
40
+ end
41
+ end
File without changes
@@ -0,0 +1,14 @@
1
+ module FastForward
2
+ class Input
3
+ include Options
4
+ include InputOutputOptions
5
+
6
+ attr_reader :filename, :options
7
+
8
+ def initialize(filename)
9
+ @filename = filename
10
+ @options = []
11
+ yield(self) if block_given?
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ module FastForward
2
+ module InputOutputOptions
3
+ def frame_rate(value)
4
+ add_option("r", value)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,42 @@
1
+ module FastForward
2
+ class Option
3
+ def initialize(name, value, opts={})
4
+ @name, @value, @opts = name, value, defaults.merge(opts)
5
+ @stream_type = nil
6
+ @stream_index = nil
7
+ end
8
+
9
+ def stream(type, index=nil)
10
+ @stream_type = type
11
+ @stream_index = index
12
+ self # For chaining
13
+ end
14
+
15
+ def defaults
16
+ { :stream_specifier_allowed => true }
17
+ end
18
+
19
+ def name
20
+ "-%s%s" % [ @name, stream_specifier ]
21
+ end
22
+
23
+ def value
24
+ @value
25
+ end
26
+
27
+ def stream_specifier
28
+ stream_type = case @stream_type
29
+ when "audio" then ":a"
30
+ when "video" then ":v"
31
+ else
32
+ ""
33
+ end
34
+
35
+ stream_type + ( @stream_index ? ":#{@stream_index}" : "" )
36
+ end
37
+
38
+ def to_s
39
+ "%s %s" % [ name, value]
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ module FastForward
2
+ module Options
3
+ def add_option(name, value)
4
+ Option.new(name, value).tap do |opt|
5
+ @options.push(opt)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module FastForward
2
+ class Output
3
+ include Options
4
+ include InputOutputOptions
5
+
6
+ attr_reader :filename, :options
7
+
8
+ def initialize(filename)
9
+ @filename = filename
10
+ @options = []
11
+ yield(self) if block_given?
12
+ end
13
+
14
+ def bitrate(value)
15
+ add_option("b", value)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module FastForward
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe FastForward::Builder do
4
+ subject { FastForward::Builder.new }
5
+ it "builds a command string for ffmpeg" do
6
+ subject.to_s.should == "ffmpeg"
7
+ end
8
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe FastForward do
4
+ it "has a convience method to initialize a builder object" do
5
+ builder = FastForward.build
6
+ builder.should be_kind_of(FastForward::Builder)
7
+ end
8
+
9
+ it "can set the video bitrate of the output file to 64kbit/s" do
10
+ builder = FastForward.build do |ff|
11
+ ff.input "input.avi"
12
+ ff.output "output.avi" do |o|
13
+ o.bitrate("64k").stream("video")
14
+ end
15
+ end
16
+
17
+ builder.to_s.should == "ffmpeg -i input.avi -b:v 64k output.avi"
18
+ end
19
+
20
+ it "can force the frame rate of the output file to 24 fps" do
21
+ builder = FastForward.build do |ff|
22
+ ff.input "input.avi"
23
+ ff.output "output.avi" do |o|
24
+ o.frame_rate(24)
25
+ end
26
+ end
27
+
28
+ builder.to_s.should == "ffmpeg -i input.avi -r 24 output.avi"
29
+ end
30
+
31
+ it "can force the frame rate of the input file (valid for raw formats only)\
32
+ to 1 fps and the frame rate of the output file to 24 fps" do
33
+ builder = FastForward.build do |ff|
34
+ ff.input "input.m2v" do |i|
35
+ i.frame_rate(1)
36
+ end
37
+ ff.output "output.avi" do |o|
38
+ o.frame_rate(24)
39
+ end
40
+ end
41
+
42
+ builder.to_s.should == "ffmpeg -r 1 -i input.m2v -r 24 output.avi"
43
+ end
44
+ end
@@ -0,0 +1,13 @@
1
+ require 'fastforward'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastforward
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Marini
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70270401709580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.8.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70270401709580
25
+ - !ruby/object:Gem::Dependency
26
+ name: sh
27
+ requirement: &70270401708720 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.0.2
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70270401708720
36
+ description: A ruby cli wrapper for FFmpeg
37
+ email:
38
+ - bmarini@gmail.com
39
+ executables:
40
+ - fastforward
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - .rspec
46
+ - Gemfile
47
+ - Rakefile
48
+ - bin/fastforward
49
+ - fastforward.gemspec
50
+ - lib/fastforward.rb
51
+ - lib/fastforward/builder.rb
52
+ - lib/fastforward/cli.rb
53
+ - lib/fastforward/input.rb
54
+ - lib/fastforward/input_output_options.rb
55
+ - lib/fastforward/option.rb
56
+ - lib/fastforward/options.rb
57
+ - lib/fastforward/output.rb
58
+ - lib/fastforward/version.rb
59
+ - spec/fastforward/builder_spec.rb
60
+ - spec/fastforward/fastforward_spec.rb
61
+ - spec/spec_helper.rb
62
+ homepage: ''
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project: fastforward
82
+ rubygems_version: 1.8.11
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A ruby cli wrapper for FFmpeg
86
+ test_files:
87
+ - spec/fastforward/builder_spec.rb
88
+ - spec/fastforward/fastforward_spec.rb
89
+ - spec/spec_helper.rb
90
+ has_rdoc: