paperclip-ffmpeg 1.0.1 → 1.2.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 +4 -4
- data/.gitignore +5 -0
- data/.travis.yml +6 -0
- data/Gemfile +1 -1
- data/README.md +30 -1
- data/Rakefile +4 -3
- data/lib/paperclip_processors/ffmpeg.rb +66 -2
- data/paperclip-ffmpeg.gemspec +8 -2
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/video.rb +38 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +28 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/db/migrate/20131209144030_create_videos.rb +8 -0
- data/spec/dummy/db/migrate/20131209145801_add_clip_to_vides.rb +9 -0
- data/spec/dummy/db/migrate/20131210102836_add_worng_clip_to_video.rb +9 -0
- data/spec/dummy/db/migrate/20131210144101_add_thumb_options_to_video.rb +8 -0
- data/spec/dummy/db/schema.rb +45 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/integration/paperclip-ffmpeg_spec.rb +42 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/1.mp4 +0 -0
- metadata +182 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1620e2af45e7e28ef8861e9373581f8dac0b0c5f
|
4
|
+
data.tar.gz: 907ea25e1fb77489b9d781376c43582d18014c6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33fb2b1dbf454b54416a569e770695eca092c99e542c0aad74f4830d779cbf4e62993a7a8bd273aca3c315f1a75d674b912cbb2f4eb1fac8e5ec70ca69e7541c
|
7
|
+
data.tar.gz: 7fedec9076d3c4a729019d5442016fd7fa7e3c3098b2c310ac1d695691b1817e5eb1077ff83129e995789d07de518c58b6573bff01d191d0825176da042eeb86
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@ This gem has been tested under Linux and Mac OS X, YMMV under Windows.
|
|
8
8
|
Requirements
|
9
9
|
------------
|
10
10
|
|
11
|
-
FFMPEG must be installed and Paperclip must have access to it. To ensure
|
11
|
+
FFMPEG or AVCONV must be installed and Paperclip must have access to it. To ensure
|
12
12
|
that it does, on your command line, run `which ffmpeg`.
|
13
13
|
This will give you the path where ffmpeg is installed. For
|
14
14
|
example, it might return `/usr/local/bin/ffmpeg`.
|
@@ -52,6 +52,8 @@ This will produce:
|
|
52
52
|
|
53
53
|
You may optionally add `<attachment>_meta` to your model and paperclip-ffmpeg will add information about the processed video.
|
54
54
|
|
55
|
+
You may optionally add `auto_rotate: true` to automatically straighten videos recoreded in a non-landscape mode.
|
56
|
+
|
55
57
|
Streaming Video
|
56
58
|
-------------------
|
57
59
|
|
@@ -69,6 +71,33 @@ end
|
|
69
71
|
|
70
72
|
See [danielgtaylor/qtfaststart](https://github.com/danielgtaylor/qtfaststart) for instructions on how to setup qtfaststart.
|
71
73
|
|
74
|
+
FFmpeg Options
|
75
|
+
-------------------
|
76
|
+
|
77
|
+
ffmpeg accepts a variety of options for video and audio like (-ac, -vn). To handle this, paperclip-ffmpeg accepts any options and passes them directly to the ffmpeg command via `convert_options` hash which includes the `input` and `output` options
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
class Lesson < ActiveRecord::Base
|
81
|
+
has_attached_file :media, :styles => {
|
82
|
+
:medium => { :geometry => "640x480", :format => 'flv', :convert_options => {:output => {:ar => 44100}} },
|
83
|
+
:large => { :geometry => "1024x576", :format => 'flv', :convert_options => {:output => {:ar => 44100}} },
|
84
|
+
}, :processors => [:ffmpeg]
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
Contribution
|
89
|
+
-------
|
90
|
+
Kudos goes to [all contributors](https://github.com/owahab/paperclip-ffmpeg/graphs/contributors) for their amazing work.
|
91
|
+
|
92
|
+
If you'd like to contribute a feature or bugfix: Thanks! To make sure your
|
93
|
+
fix/feature has a high chance of being included, please read the following
|
94
|
+
guidelines:
|
95
|
+
|
96
|
+
1. Post a new GitHub Issue[http://github.com/owahab/paperclip-ffmpeg/issues].
|
97
|
+
2. Make sure there are tests! We will not accept any patch that is not tested.
|
98
|
+
It's a rare time when explicit tests aren't needed.
|
99
|
+
|
100
|
+
|
72
101
|
License
|
73
102
|
-------
|
74
103
|
|
data/Rakefile
CHANGED
@@ -35,6 +35,7 @@ module Paperclip
|
|
35
35
|
@basename = File.basename(@file.path, @current_format)
|
36
36
|
@meta = identify
|
37
37
|
@pad_color = options[:pad_color].nil? ? "black" : options[:pad_color]
|
38
|
+
@auto_rotate = options[:auto_rotate].nil? ? false : options[:auto_rotate]
|
38
39
|
attachment.instance_write(:meta, @meta)
|
39
40
|
end
|
40
41
|
# Performs the transcoding of the +file+ into a thumbnail/video. Returns the Tempfile
|
@@ -122,6 +123,19 @@ module Paperclip
|
|
122
123
|
end
|
123
124
|
end
|
124
125
|
|
126
|
+
# If file has rotation, rotate it back to horizontal
|
127
|
+
if @auto_rotate && !@meta[:rotate].nil?
|
128
|
+
Ffmpeg.log("Adding rotation #{@meta[:rotate]}") if @whiny
|
129
|
+
case @meta[:rotate]
|
130
|
+
when 90
|
131
|
+
@convert_options[:output][:vf] = 'transpose=1'
|
132
|
+
when 180
|
133
|
+
@convert_options[:output][:vf] = 'vflip, hflip'
|
134
|
+
when 270
|
135
|
+
@convert_options[:output][:vf] = 'transpose=2'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
125
139
|
Ffmpeg.log("Adding Format") if @whiny
|
126
140
|
# Add format
|
127
141
|
case @format
|
@@ -155,7 +169,8 @@ module Paperclip
|
|
155
169
|
|
156
170
|
Ffmpeg.log(parameters)
|
157
171
|
begin
|
158
|
-
|
172
|
+
av_lib_version = Ffmpeg.detect_ffmpeg_or_avconv
|
173
|
+
success = Paperclip.run(av_lib_version, parameters, :source => "#{File.expand_path(src.path)}", :dest => File.expand_path(dst.path))
|
159
174
|
rescue Cocaine::ExitStatusError => e
|
160
175
|
raise Paperclip::Error, "error while processing video for #{@basename}: #{e}" if @whiny
|
161
176
|
end
|
@@ -165,7 +180,8 @@ module Paperclip
|
|
165
180
|
|
166
181
|
def identify
|
167
182
|
meta = {}
|
168
|
-
|
183
|
+
av_lib_version = Ffmpeg.detect_ffprobe_or_avprobe
|
184
|
+
command = "#{av_lib_version} \"#{File.expand_path(@file.path)}\" 2>&1"
|
169
185
|
Paperclip.log("[ffmpeg] #{command}")
|
170
186
|
ffmpeg = Cocaine::CommandLine.new(command).run
|
171
187
|
ffmpeg.split("\n").each do |line|
|
@@ -184,6 +200,9 @@ module Paperclip
|
|
184
200
|
if line =~ /Duration:(\s.?(\d*):(\d*):(\d*\.\d*))/
|
185
201
|
meta[:length] = $2.to_s + ":" + $3.to_s + ":" + $4.to_s
|
186
202
|
end
|
203
|
+
if line =~ /rotate\s*:\s(\d*)/
|
204
|
+
meta[:rotate] = $1.to_i
|
205
|
+
end
|
187
206
|
end
|
188
207
|
Paperclip.log("[ffmpeg] Command Success") if @whiny
|
189
208
|
meta
|
@@ -193,6 +212,51 @@ module Paperclip
|
|
193
212
|
def self.log message
|
194
213
|
Paperclip.log "[ffmpeg] #{message}"
|
195
214
|
end
|
215
|
+
|
216
|
+
def self.detect_ffmpeg_or_avconv
|
217
|
+
# Check whether ffmpeg or avconv is installed
|
218
|
+
result = Ffmpeg.detect_command("ffmpeg")
|
219
|
+
Ffmpeg.log("Result of command: #{result}") if @whiny
|
220
|
+
if result == true
|
221
|
+
Ffmpeg.log("Result of command: #{"ffmpeg"}") if @whiny
|
222
|
+
return "ffmpeg"
|
223
|
+
elsif result == false
|
224
|
+
Ffmpeg.log("Result of command: #{"avconv"}") if @whiny
|
225
|
+
return "avconv"
|
226
|
+
else
|
227
|
+
return "Error: no video conversion library detected. Please install ffmpeg or avconv."
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
def self.detect_ffprobe_or_avprobe
|
232
|
+
# Check whether ffprobe or avprobe is installed
|
233
|
+
result = Ffmpeg.detect_command("ffprobe")
|
234
|
+
Ffmpeg.log("Result of command: #{result}") if @whiny
|
235
|
+
if result == true
|
236
|
+
Ffmpeg.log("Result of command: #{"ffprobe"}") if @whiny
|
237
|
+
return "ffprobe"
|
238
|
+
elsif result == false
|
239
|
+
Ffmpeg.log("Result of command: #{"avprobe"}") if @whiny
|
240
|
+
return "avprobe"
|
241
|
+
else
|
242
|
+
return "Error: no video conversion library detected. Please install ffmpeg or avconv."
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
def self.detect_command(command)
|
247
|
+
command = "if command -v #{command} 2>/dev/null; then echo \"true\"; else echo \"false\"; fi"
|
248
|
+
Ffmpeg.log(command) if @whiny
|
249
|
+
result = Cocaine::CommandLine.new(command).run
|
250
|
+
Ffmpeg.log("Result of command: #{result}") if @whiny
|
251
|
+
case result
|
252
|
+
when /true/
|
253
|
+
return true
|
254
|
+
when /false/
|
255
|
+
return false
|
256
|
+
else
|
257
|
+
return nil
|
258
|
+
end
|
259
|
+
end
|
196
260
|
end
|
197
261
|
|
198
262
|
class Attachment
|
data/paperclip-ffmpeg.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "paperclip-ffmpeg"
|
6
|
-
s.version = '1.0
|
6
|
+
s.version = '1.2.0'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.licenses = 'MIT'
|
9
9
|
s.authors = ["Omar Abdel-Wahab"]
|
@@ -18,6 +18,12 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
|
-
|
21
|
+
|
22
|
+
s.add_dependency("rails")
|
22
23
|
s.add_dependency('paperclip', '>=2.5.2')
|
24
|
+
s.add_development_dependency('rspec-rails', '~> 2.14.2')
|
25
|
+
s.add_development_dependency("sqlite3")
|
26
|
+
s.add_development_dependency("database_cleaner")
|
27
|
+
s.add_development_dependency("shoulda")
|
28
|
+
s.add_development_dependency("image_size")
|
23
29
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Video < ActiveRecord::Base
|
2
|
+
|
3
|
+
has_attached_file :clip, :styles => {
|
4
|
+
:medium => { :geometry => "640x480", :format => 'flv', :convert_options => {:output => {:ar => 44100}} },
|
5
|
+
:large => { :geometry => "1024x576", :format => 'flv', :convert_options => {:output => {:ar => 44100}} }
|
6
|
+
}, :processors => [:ffmpeg]
|
7
|
+
validates_attachment_content_type :clip, content_type:['video/mp4','video/mpeg']
|
8
|
+
|
9
|
+
has_attached_file :wrongClip, :styles => {
|
10
|
+
:large => { :geometry => "1024x576", :format => 'flv', :convert_options => {:output => {:ar => 3000}} }
|
11
|
+
}, :processors => [:ffmpeg]
|
12
|
+
validates_attachment_content_type :wrongClip, content_type:['video/mp4','video/mpeg']
|
13
|
+
|
14
|
+
has_attached_file :clip_thumb_exceed, :styles => {
|
15
|
+
:large => { :geometry => "1024x576", :format => 'flv', :convert_options => {:output => {:ar => 44100}} },
|
16
|
+
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10}
|
17
|
+
}, :processors => [:ffmpeg]
|
18
|
+
validates_attachment_content_type :clip_thumb_exceed, content_type:['video/mp4','video/mpeg']
|
19
|
+
|
20
|
+
has_attached_file :clip_thumb_normal, :styles => {
|
21
|
+
:large => { :geometry => "1024x576", :format => 'flv', :convert_options => {:output => {:ar => 44100}} },
|
22
|
+
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 0}
|
23
|
+
}, :processors => [:ffmpeg]
|
24
|
+
validates_attachment_content_type :clip_thumb_normal, content_type:['video/mp4','video/mpeg']
|
25
|
+
|
26
|
+
has_attached_file :clip_thumb_negative, :styles => {
|
27
|
+
:large => { :geometry => "1024x576", :format => 'flv', :convert_options => {:output => {:ar => 44100}} },
|
28
|
+
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => -10}
|
29
|
+
}, :processors => [:ffmpeg]
|
30
|
+
validates_attachment_content_type :clip_thumb_negative, content_type:['video/mp4','video/mpeg']
|
31
|
+
|
32
|
+
has_attached_file :clip_thumb_bad_extension, :styles => {
|
33
|
+
:large => { :geometry => "1024x576", :format => 'flv', :convert_options => {:output => {:ar => 44100}} },
|
34
|
+
:thumb => { :geometry => "100x100#", :format => 'foo', :time => 0}
|
35
|
+
}, :processors => [:ffmpeg]
|
36
|
+
validates_attachment_content_type :clip_thumb_bad_extension, content_type:['video/mp4','video/mpeg']
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_mailer/railtie"
|
7
|
+
require "sprockets/railtie"
|
8
|
+
# require "rails/test_unit/railtie"
|
9
|
+
|
10
|
+
Bundler.require(*Rails.groups)
|
11
|
+
require "paperclip-ffmpeg"
|
12
|
+
|
13
|
+
module Dummy
|
14
|
+
class Application < Rails::Application
|
15
|
+
# Settings in config/environments/* take precedence over those specified here.
|
16
|
+
# Application configuration should go into files in config/initializers
|
17
|
+
# -- all .rb files in that directory are automatically loaded.
|
18
|
+
|
19
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
20
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
21
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
22
|
+
|
23
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
24
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
25
|
+
# config.i18n.default_locale = :de
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
development:
|
7
|
+
adapter: sqlite3
|
8
|
+
database: db/development.sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
# Warning: The database defined as "test" will be erased and
|
13
|
+
# re-generated from your development database when you run "rake".
|
14
|
+
# Do not set this db to the same as development or production.
|
15
|
+
test:
|
16
|
+
adapter: sqlite3
|
17
|
+
database: db/test.sqlite3
|
18
|
+
pool: 5
|
19
|
+
timeout: 5000
|
20
|
+
|
21
|
+
production:
|
22
|
+
adapter: sqlite3
|
23
|
+
database: db/production.sqlite3
|
24
|
+
pool: 5
|
25
|
+
timeout: 5000
|