paperclip-av-transcoder 0.1.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paperclip/av/transcoder/version.rb +1 -1
- data/lib/paperclip/paperclip_processors/transcoder.rb +26 -21
- data/paperclip-av-transcoder.gemspec +1 -1
- data/spec/schema.rb +8 -4
- data/spec/spec_helper.rb +15 -4
- data/spec/support/assets/image.png +0 -0
- data/spec/transcoder/transcoder_spec.rb +19 -5
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 858fffd20c3c059ebc73712eedfb4150b1297f2f
|
4
|
+
data.tar.gz: b74db6d2e7358e2b1654f0306774c6a25aacb907
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5adddefa0f940151502182a571de4f2d70dcf5ec44599a75207e25e9e9ff3890becb4d5fb6221b4fce233409a183fdb12bea9cf023224262952b705c1aaeab57
|
7
|
+
data.tar.gz: 397819cee502c272fc65243ae658f5fd40cbcae3cf9aad40e5d78a7876c4abb78c2c016d9d8c3b0477c2476ae219770700b76f014547778c18d077c3fb0c38d4
|
@@ -20,7 +20,7 @@ module Paperclip
|
|
20
20
|
@geometry = options[:geometry]
|
21
21
|
unless @geometry.nil?
|
22
22
|
modifier = @geometry[0]
|
23
|
-
@geometry[0] = '' if ['#', '<', '>'].
|
23
|
+
@geometry[0] = '' if ['#', '<', '>'].include? modifier
|
24
24
|
@width, @height = @geometry.split('x')
|
25
25
|
@keep_aspect = @width[0] == '!' || @height[0] == '!'
|
26
26
|
@pad_only = @keep_aspect && modifier == '#'
|
@@ -41,28 +41,33 @@ module Paperclip
|
|
41
41
|
::Av.cli.add_source @file
|
42
42
|
dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
|
43
43
|
dst.binmode
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
44
|
+
|
45
|
+
if @meta
|
46
|
+
log "Transocding supported file #{@file.path}"
|
47
|
+
cli = ::Av.cli(quite: true)
|
48
|
+
cli.add_source(@file.path)
|
49
|
+
cli.add_destination(dst.path)
|
50
|
+
cli.reset_input_filters
|
51
|
+
if @convert_options.present?
|
52
|
+
if @convert_options[:input]
|
53
|
+
@convert_options[:input].each do |h|
|
54
|
+
cli.add_input_param h
|
55
|
+
end
|
56
|
+
end
|
57
|
+
if @convert_options[:output]
|
58
|
+
@convert_options[:output].each do |h|
|
59
|
+
cli.add_output_param h
|
60
|
+
end
|
61
|
+
end
|
57
62
|
end
|
58
|
-
end
|
59
63
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
begin
|
65
|
+
cli.run
|
66
|
+
log "Successfully transcoded #{@base} to #{dst}"
|
67
|
+
return dst
|
68
|
+
rescue Cocaine::ExitStatusError => e
|
69
|
+
raise Paperclip::Error, "error while transcoding #{@basename}: #{e}" if @whiny
|
70
|
+
end
|
66
71
|
end
|
67
72
|
# If the file is not supported, just return it
|
68
73
|
@file
|
data/spec/schema.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
ActiveRecord::Schema.define version: 0 do
|
2
2
|
create_table "documents", force: true do |t|
|
3
3
|
t.string :owner
|
4
|
-
t.string :
|
5
|
-
t.string :
|
6
|
-
t.integer :
|
7
|
-
t.integer :
|
4
|
+
t.string :video_file_name
|
5
|
+
t.string :video_content_type
|
6
|
+
t.integer :video_updated_at
|
7
|
+
t.integer :video_file_size
|
8
|
+
t.string :image_file_name
|
9
|
+
t.string :image_content_type
|
10
|
+
t.integer :image_updated_at
|
11
|
+
t.integer :image_file_size
|
8
12
|
end
|
9
13
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,7 +11,7 @@ Bundler.require(:default)
|
|
11
11
|
# Connect to sqlite
|
12
12
|
ActiveRecord::Base.establish_connection("adapter" => "sqlite3", "database" => ":memory:")
|
13
13
|
|
14
|
-
ActiveRecord::Base.logger = Logger.new(
|
14
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
15
15
|
load(File.join(File.dirname(__FILE__), 'schema.rb'))
|
16
16
|
|
17
17
|
Paperclip::Railtie.insert
|
@@ -22,7 +22,7 @@ RSpec.configure do |config|
|
|
22
22
|
end
|
23
23
|
|
24
24
|
class Document < ActiveRecord::Base
|
25
|
-
has_attached_file :
|
25
|
+
has_attached_file :video,
|
26
26
|
storage: :filesystem,
|
27
27
|
path: "./spec/tmp/:id.:extension",
|
28
28
|
url: "/spec/tmp/:id.:extension",
|
@@ -32,7 +32,6 @@ class Document < ActiveRecord::Base
|
|
32
32
|
format: 'ogv',
|
33
33
|
convert_options: {
|
34
34
|
output: {
|
35
|
-
af: "volume=volume=10",
|
36
35
|
ab: '256k',
|
37
36
|
ar: 44100,
|
38
37
|
ac: 2
|
@@ -41,5 +40,17 @@ class Document < ActiveRecord::Base
|
|
41
40
|
}
|
42
41
|
},
|
43
42
|
processors: [:transcoder]
|
44
|
-
|
43
|
+
|
44
|
+
has_attached_file :image,
|
45
|
+
storage: :filesystem,
|
46
|
+
path: "./spec/tmp/:id.:extension",
|
47
|
+
url: "/spec/tmp/:id.:extension",
|
48
|
+
whiny: true,
|
49
|
+
styles: {
|
50
|
+
small: "100x100"
|
51
|
+
},
|
52
|
+
processors: [:transcoder, :thumbnail]
|
53
|
+
|
54
|
+
do_not_validate_attachment_file_type :video
|
55
|
+
do_not_validate_attachment_file_type :image
|
45
56
|
end
|
Binary file
|
@@ -1,12 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Paperclip::Transcoder do
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
|
4
|
+
let(:supported) { File.new(Dir.pwd + '/spec/support/assets/sample.mp4') }
|
5
|
+
let(:unsupported) { File.new(File.expand_path('spec/support/assets/image.png')) }
|
6
|
+
|
7
7
|
let(:destination) { Pathname.new("#{Dir.tmpdir}/transcoder/") }
|
8
8
|
|
9
|
-
describe "
|
10
|
-
|
9
|
+
describe "supported formats" do
|
10
|
+
let(:subject) { Paperclip::Chainer.new(supported) }
|
11
|
+
let(:document) { Document.create(video: Rack::Test::UploadedFile.new(supported, 'video/mp4')) }
|
12
|
+
|
13
|
+
describe ".transcode" do
|
14
|
+
it { expect(File.exists?(document.video.path(:small))).to eq true }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "unsupported formats" do
|
19
|
+
let(:subject) { Paperclip::Chainer.new(unsupported) }
|
20
|
+
let(:document) { Document.create(image: Rack::Test::UploadedFile.new(unsupported, 'image/png')) }
|
21
|
+
describe ".transcode" do
|
22
|
+
it { expect(File.exists?(document.image.path(:small))).to eq true }
|
23
|
+
end
|
11
24
|
end
|
25
|
+
|
12
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-av-transcoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Omar Abdel-Wahab
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.0
|
103
|
+
version: 0.4.0
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.0
|
110
|
+
version: 0.4.0
|
111
111
|
description: Audio/Video Transcoder for Paperclip using FFMPEG/Avconv
|
112
112
|
email:
|
113
113
|
- owahab@gmail.com
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- spec/support/assets/audio.zip
|
131
131
|
- spec/support/assets/audio/audio1.spx
|
132
132
|
- spec/support/assets/audio/audio2.spx
|
133
|
+
- spec/support/assets/image.png
|
133
134
|
- spec/support/assets/sample.mp4
|
134
135
|
- spec/transcoder/transcoder_spec.rb
|
135
136
|
homepage: https://github.com/ruby-av/paperclip-av-transcoder
|
@@ -162,5 +163,6 @@ test_files:
|
|
162
163
|
- spec/support/assets/audio.zip
|
163
164
|
- spec/support/assets/audio/audio1.spx
|
164
165
|
- spec/support/assets/audio/audio2.spx
|
166
|
+
- spec/support/assets/image.png
|
165
167
|
- spec/support/assets/sample.mp4
|
166
168
|
- spec/transcoder/transcoder_spec.rb
|