paperclip-av-transcoder 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/lib/paperclip/av/transcoder/version.rb +7 -0
- data/lib/paperclip/av/transcoder.rb +3 -0
- data/lib/paperclip/paperclip_processors/transcoder.rb +81 -0
- data/paperclip-av-transcoder.gemspec +30 -0
- data/spec/schema.rb +9 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/support/assets/audio/audio1.spx +0 -0
- data/spec/support/assets/audio/audio2.spx +0 -0
- data/spec/support/assets/audio.zip +0 -0
- data/spec/support/assets/sample.mp4 +0 -0
- data/spec/transcoder/transcoder_spec.rb +17 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f2426bffe0d211d2a0ff0eec82a6cf88b0958e9
|
4
|
+
data.tar.gz: 9c5ad73b76d938d56fbea4efa4ef8ad54dfb562b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 27d427c4e59242ed2cd60299c58d79052cc8967745f8c741d2b72ce757ab670d3bd3e2a5ae6b051474cb57c9b9d144289088611cea1281831c25165fabae1ae3
|
7
|
+
data.tar.gz: e516cec8ac1c4c28ec9cd5d35b4a4f333fbd2167223b826baa76295cb3fe487b7d18252841c38a3e536fe35852c5e52afb73640008e0830cedd906b8d4dc9582
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
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
|
23
|
+
.DS_Store
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Paperclip::Av::Transcoder
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'paperclip-av-transcoder'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install paperclip-av-transcoder
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/paperclip-av-transcoder/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
|
data/Rakefile
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
module Paperclip
|
2
|
+
class Transcoder < Processor
|
3
|
+
attr_accessor :geometry, :format, :whiny, :convert_options
|
4
|
+
# Creates a Video object set to work on the +file+ given. It
|
5
|
+
# will attempt to transcode the video into one defined by +target_geometry+
|
6
|
+
# which is a "WxH"-style string. +format+ should be specified.
|
7
|
+
# Video transcoding will raise no errors unless
|
8
|
+
# +whiny+ is true (which it is, by default. If +convert_options+ is
|
9
|
+
# set, the options will be appended to the convert command upon video transcoding.
|
10
|
+
def initialize file, options = {}, attachment = nil
|
11
|
+
@file = file
|
12
|
+
@current_format = File.extname(@file.path)
|
13
|
+
@basename = File.basename(@file.path, @current_format)
|
14
|
+
@meta = ::Av.cli.identify(@file.path)
|
15
|
+
@whiny = options[:whiny].nil? ? true : options[:whiny]
|
16
|
+
|
17
|
+
@convert_options = options[:convert_options]
|
18
|
+
@format = options[:format]
|
19
|
+
|
20
|
+
@geometry = options[:geometry]
|
21
|
+
unless @geometry.nil?
|
22
|
+
modifier = @geometry[0]
|
23
|
+
@geometry[0] = '' if ['#', '<', '>'].includes? modifier
|
24
|
+
@width, @height = @geometry.split('x')
|
25
|
+
@keep_aspect = @width[0] == '!' || @height[0] == '!'
|
26
|
+
@pad_only = @keep_aspect && modifier == '#'
|
27
|
+
@enlarge_only = @keep_aspect && modifier == '<'
|
28
|
+
@shrink_only = @keep_aspect && modifier == '>'
|
29
|
+
end
|
30
|
+
|
31
|
+
@time = options[:time].nil? ? 3 : options[:time]
|
32
|
+
@auto_rotate = options[:auto_rotate].nil? ? false : options[:auto_rotate]
|
33
|
+
@pad_color = options[:pad_color].nil? ? "black" : options[:pad_color]
|
34
|
+
|
35
|
+
attachment.instance_write(:meta, @meta) if attachment
|
36
|
+
end
|
37
|
+
|
38
|
+
# Performs the transcoding of the +file+ into a thumbnail/video. Returns the Tempfile
|
39
|
+
# that contains the new image/video.
|
40
|
+
def make
|
41
|
+
::Av.cli.add_source @file
|
42
|
+
dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
|
43
|
+
dst.binmode
|
44
|
+
|
45
|
+
cli = ::Av.cli(quite: true)
|
46
|
+
cli.add_source(@file.path)
|
47
|
+
cli.add_destination(dst.path)
|
48
|
+
cli.reset_input_filters
|
49
|
+
if @convert_options[:input]
|
50
|
+
@convert_options[:input].each do |h|
|
51
|
+
cli.add_input_param h
|
52
|
+
end
|
53
|
+
end
|
54
|
+
if @convert_options[:output]
|
55
|
+
@convert_options[:output].each do |h|
|
56
|
+
cli.add_output_param h
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
begin
|
61
|
+
cli.run
|
62
|
+
log "Successfully transcoded #{@base} to #{dst}"
|
63
|
+
return dst # Things went fine, pass the file to paperclip for saving
|
64
|
+
rescue Cocaine::ExitStatusError => e
|
65
|
+
raise Paperclip::Error, "error while transcoding #{@basename}: #{e}" if @whiny
|
66
|
+
end
|
67
|
+
# If the file is not supported, just return it
|
68
|
+
@file
|
69
|
+
end
|
70
|
+
|
71
|
+
def log message
|
72
|
+
Paperclip.log "[transcoder] #{message}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class Attachment
|
77
|
+
def meta
|
78
|
+
instance_read(:meta)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'paperclip/av/transcoder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "paperclip-av-transcoder"
|
8
|
+
spec.version = Paperclip::Av::Transcoder::VERSION
|
9
|
+
spec.authors = ["Omar Abdel-Wahab"]
|
10
|
+
spec.email = ["owahab@gmail.com"]
|
11
|
+
spec.summary = %q{Audio/Video Transcoder for Paperclip using FFMPEG/Avconv}
|
12
|
+
spec.description = %q{Audio/Video Transcoder for Paperclip using FFMPEG/Avconv}
|
13
|
+
spec.homepage = "https://github.com/ruby-av/paperclip-av-transcoder"
|
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
|
+
spec.add_development_dependency "rails", ">= 4.0.0"
|
25
|
+
spec.add_development_dependency "sqlite3"
|
26
|
+
spec.add_development_dependency "debugger"
|
27
|
+
|
28
|
+
spec.add_dependency "paperclip", ">=2.5.2"
|
29
|
+
spec.add_dependency "av", ">= 0.0.1"
|
30
|
+
end
|
data/spec/schema.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'paperclip'
|
5
|
+
require 'paperclip/railtie'
|
6
|
+
# Prepare activerecord
|
7
|
+
require "active_record"
|
8
|
+
require 'paperclip/av/transcoder'
|
9
|
+
|
10
|
+
Bundler.require(:default)
|
11
|
+
# Connect to sqlite
|
12
|
+
ActiveRecord::Base.establish_connection("adapter" => "sqlite3", "database" => ":memory:")
|
13
|
+
|
14
|
+
ActiveRecord::Base.logger = Logger.new(nil)
|
15
|
+
load(File.join(File.dirname(__FILE__), 'schema.rb'))
|
16
|
+
|
17
|
+
Paperclip::Railtie.insert
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.run_all_when_everything_filtered = true
|
21
|
+
config.filter_run focus: true
|
22
|
+
end
|
23
|
+
|
24
|
+
class Document < ActiveRecord::Base
|
25
|
+
has_attached_file :original,
|
26
|
+
storage: :filesystem,
|
27
|
+
path: "./spec/tmp/:id.:extension",
|
28
|
+
url: "/spec/tmp/:id.:extension",
|
29
|
+
whiny: true,
|
30
|
+
styles: {
|
31
|
+
small: {
|
32
|
+
format: 'ogv',
|
33
|
+
convert_options: {
|
34
|
+
output: {
|
35
|
+
af: "volume=volume=10",
|
36
|
+
ab: '256k',
|
37
|
+
ar: 44100,
|
38
|
+
ac: 2
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
},
|
43
|
+
processors: [:transcoder]
|
44
|
+
do_not_validate_attachment_file_type :original
|
45
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'debugger'
|
3
|
+
|
4
|
+
describe Paperclip::Transcoder do
|
5
|
+
let(:subject) { Paperclip::Transcoder.new(source) }
|
6
|
+
let(:document) { Document.create(original: source) }
|
7
|
+
let(:source) { File.new(Dir.pwd + '/spec/support/assets/sample.mp4') }
|
8
|
+
let(:destination) { Pathname.new("#{Dir.tmpdir}/transcoder/") }
|
9
|
+
|
10
|
+
describe ".transcode" do
|
11
|
+
it do
|
12
|
+
puts "here"
|
13
|
+
document
|
14
|
+
end
|
15
|
+
# it { expect(File.exists?(document.original.path(:small))).to eq true }
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclip-av-transcoder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Omar Abdel-Wahab
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-10 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: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: debugger
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: paperclip
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.5.2
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.5.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: av
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.0.1
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.0.1
|
125
|
+
description: Audio/Video Transcoder for Paperclip using FFMPEG/Avconv
|
126
|
+
email:
|
127
|
+
- owahab@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- .gitignore
|
133
|
+
- .travis.yml
|
134
|
+
- Gemfile
|
135
|
+
- LICENSE.txt
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- lib/paperclip/av/transcoder.rb
|
139
|
+
- lib/paperclip/av/transcoder/version.rb
|
140
|
+
- lib/paperclip/paperclip_processors/transcoder.rb
|
141
|
+
- paperclip-av-transcoder.gemspec
|
142
|
+
- spec/schema.rb
|
143
|
+
- spec/spec_helper.rb
|
144
|
+
- spec/support/assets/audio.zip
|
145
|
+
- spec/support/assets/audio/audio1.spx
|
146
|
+
- spec/support/assets/audio/audio2.spx
|
147
|
+
- spec/support/assets/sample.mp4
|
148
|
+
- spec/transcoder/transcoder_spec.rb
|
149
|
+
homepage: https://github.com/ruby-av/paperclip-av-transcoder
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
metadata: {}
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 2.0.3
|
170
|
+
signing_key:
|
171
|
+
specification_version: 4
|
172
|
+
summary: Audio/Video Transcoder for Paperclip using FFMPEG/Avconv
|
173
|
+
test_files:
|
174
|
+
- spec/schema.rb
|
175
|
+
- spec/spec_helper.rb
|
176
|
+
- spec/support/assets/audio.zip
|
177
|
+
- spec/support/assets/audio/audio1.spx
|
178
|
+
- spec/support/assets/audio/audio2.spx
|
179
|
+
- spec/support/assets/sample.mp4
|
180
|
+
- spec/transcoder/transcoder_spec.rb
|