paperclip-streamio-ffmpeg 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a7ef23fb2555a2b0a64dd1154209457f7bcee12
4
+ data.tar.gz: d5cfa19389c23fa083e7f798011eaa5e29569229
5
+ SHA512:
6
+ metadata.gz: d2ac72ab9a94ca31956d837c3c36b427a1fef7d9bc80cc6e1303b7ff442479859a9f68b9b463c0841500498e83ab857b8d9b11d6bb4581f14599482c8b262665
7
+ data.tar.gz: 154909dc3f6896dabc88d83f26438490e775fa6900d5cb97833ede9e1d32e2aedbd1e9633327d21d2be9562385a25d11a159977b4b85ce1c96e1ec0300ba94ef
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /spec/examples.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in paperclip-streamio-ffmpeg.gemspec
6
+ gemspec
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ paperclip-streamio-ffmpeg (0.1.0)
5
+ paperclip
6
+ streamio-ffmpeg (~> 3.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (5.2.0)
12
+ activesupport (= 5.2.0)
13
+ activesupport (5.2.0)
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ i18n (>= 0.7, < 2)
16
+ minitest (~> 5.1)
17
+ tzinfo (~> 1.1)
18
+ climate_control (0.2.0)
19
+ concurrent-ruby (1.0.5)
20
+ diff-lcs (1.3)
21
+ i18n (1.0.1)
22
+ concurrent-ruby (~> 1.0)
23
+ mime-types (3.1)
24
+ mime-types-data (~> 3.2015)
25
+ mime-types-data (3.2016.0521)
26
+ mimemagic (0.3.2)
27
+ minitest (5.11.3)
28
+ multi_json (1.13.1)
29
+ paperclip (6.0.0)
30
+ activemodel (>= 4.2.0)
31
+ activesupport (>= 4.2.0)
32
+ mime-types
33
+ mimemagic (~> 0.3.0)
34
+ terrapin (~> 0.6.0)
35
+ rake (10.5.0)
36
+ rspec (3.7.0)
37
+ rspec-core (~> 3.7.0)
38
+ rspec-expectations (~> 3.7.0)
39
+ rspec-mocks (~> 3.7.0)
40
+ rspec-core (3.7.1)
41
+ rspec-support (~> 3.7.0)
42
+ rspec-expectations (3.7.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.7.0)
45
+ rspec-mocks (3.7.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.7.0)
48
+ rspec-support (3.7.1)
49
+ streamio-ffmpeg (3.0.2)
50
+ multi_json (~> 1.8)
51
+ terrapin (0.6.0)
52
+ climate_control (>= 0.0.3, < 1.0)
53
+ thread_safe (0.3.6)
54
+ tzinfo (1.2.5)
55
+ thread_safe (~> 0.1)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ bundler (~> 1.16)
62
+ paperclip-streamio-ffmpeg!
63
+ rake (~> 10.0)
64
+ rspec (~> 3)
65
+
66
+ BUNDLED WITH
67
+ 1.16.0
@@ -0,0 +1,131 @@
1
+ # paperclip-streamio-ffmpeg
2
+
3
+ Video Transcoder for Paperclip using [streamio/streamio-ffmpeg](https://github.com/streamio/streamio-ffmpeg).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'paperclip-streamio-ffmpeg'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install paperclip-streamio-ffmpeg
20
+
21
+ ## Usage
22
+
23
+ Edit your paperclip model:
24
+
25
+ ``` ruby
26
+ # app/models/assets.rb
27
+
28
+ class Asset < ApplicationRecord
29
+ # paperclip style
30
+ has_attached_file :attachment,
31
+ processors: [:transcoder],
32
+ styles: {
33
+ thumb: {
34
+ geometry: "150x150>",
35
+ format: :jpeg,
36
+ screenshot: true,
37
+ },
38
+ preview: {
39
+ geometry: "1280x720>",
40
+ format: :mp4,
41
+ }
42
+ }
43
+
44
+ # streamio-ffmpeg style
45
+ has_attached_file :attachment2,
46
+ processors: [:transcoder],
47
+ styles: {
48
+ thumb: {
49
+ format: :jpeg,
50
+ convert_options: {
51
+ resolution: "150x150",
52
+ screenshot: true,
53
+ seek_time: 3,
54
+ }
55
+ transcoder_options: {
56
+ preserve_aspect_ratio: :width
57
+ }
58
+ },
59
+ preview: {
60
+ format: :mp4,
61
+ convert_options: {
62
+ resolution: "320x240",
63
+ video_codec: "libx264",
64
+ frame_rate: 10,
65
+ video_bitrate: 300,
66
+ }
67
+ }
68
+ }
69
+ end
70
+ ```
71
+
72
+ ### Options
73
+
74
+ **geometry**
75
+
76
+ If modifier is not specified, keep the aspect ratio.
77
+
78
+ ```
79
+ original file: 1280x720, geometry: 640x480, output: 640x360`
80
+ ```
81
+
82
+ If `!` Or `#` is specified, resizing is done ignoring the aspect ratio.
83
+
84
+ ```
85
+ original file: 1280x720, geometry: 640x480!, output: 640x480
86
+ ```
87
+
88
+ If `>` is specified, it will be resized only if the resolution of the original file is greater than specified. The aspect ratio is kept.
89
+
90
+ ```
91
+ original file: 1280x720, geometry: 640x480>, output: 640x360
92
+ original file: 1280x720, geometry: 1920x1080>, output: 1280x720
93
+ ```
94
+
95
+ If `<` is specified, it will be resized only if the resolution of the original file is less than specified. The aspect ratio is kept.
96
+
97
+ ```
98
+ original file: 1280x720, geometry: 640x480<, output: 1280x720
99
+ original file: 1280x720, geometry: 1920x1080<, output: 1920x1080
100
+ ```
101
+
102
+ Please specify the resolution with convert_options instead of geometry if you want to perform more detailed conversion, such as keeping the aspect in accordance with the vertical width.
103
+
104
+ **format**
105
+
106
+ Output file format. If you do not specify a format, it will be output in the same format as the original file.
107
+
108
+ **convert_options**
109
+
110
+ Specify conversion option of streamio-ffmpeg. See more https://github.com/streamio/streamio-ffmpeg#transcoding .
111
+
112
+ If string is specified, its value becomes an argument to ffmpeg.
113
+
114
+
115
+ **transcoder_options**
116
+
117
+ Specify transcoder option of streamio-ffmpeg. See more https://github.com/streamio/streamio-ffmpeg#transcoding .
118
+
119
+ **screenshot**
120
+
121
+ Shorthand for `convert_options: { screenshot: true, seek_time: 3 }`
122
+
123
+ ## Development
124
+
125
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
126
+
127
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
128
+
129
+ ## Contributing
130
+
131
+ Bug reports and pull requests are welcome on GitHub at https://github.com/daichirata/paperclip-streamio-ffmpeg.
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "paperclip/streamio/ffmpeg"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ require "paperclip-streamio-ffmpeg/version"
2
+ require "paperclip-streamio-ffmpeg/transcoder"
@@ -0,0 +1,55 @@
1
+ require "paperclip"
2
+ require "streamio-ffmpeg"
3
+
4
+ module Paperclip
5
+ class Transcoder < Processor
6
+ def initialize(file, options = {}, attachment = nil)
7
+ super
8
+
9
+ @movie = FFMPEG::Movie.new(file.path)
10
+
11
+ @target_geometry = options.fetch(:string_geometry_parser, Geometry).parse(options[:geometry])
12
+ @current_geometry = options.fetch(:file_geometry_parser, Geometry).parse(@movie.resolution)
13
+ @convert_options = options.fetch(:convert_options, {})
14
+ @convert_options = { custom: @convert_options.split(/\s+/) } if @convert_options.respond_to?(:split)
15
+ @transcoder_options = options.fetch(:transcoder_options, {})
16
+ @screenshot = options.fetch(:screenshot, false)
17
+ @whiny = options.fetch(:whiny, true)
18
+ @format = options[:format]
19
+ @current_format = File.extname(file.path)
20
+ @basename = File.basename(file.path, @current_format)
21
+ end
22
+
23
+ def make
24
+ unless @movie.valid?
25
+ Paperclip.log("[transcoder] Unsupported file: #{@file.path} #{@movie.metadata[:error][:string]}")
26
+ return @file
27
+ end
28
+
29
+ dst = Paperclip::TempfileFactory.new.generate(
30
+ [@basename, @format ? ".#{@format}" : @current_format].join
31
+ )
32
+
33
+ begin
34
+ options = {}
35
+ if @screenshot
36
+ options.merge!(screenshot: true, seek_time: 3)
37
+ end
38
+ if @current_geometry.present? && @target_geometry.present?
39
+ options.merge!(resolution: target_resolution)
40
+ end
41
+ @movie.transcode(dst.path, options.merge(@convert_options), @transcoder_options)
42
+ rescue FFMPEG::Error
43
+ raise Paperclip::Error, "There was an error processing the transcoder for #{@basename}" if @whiny
44
+ end
45
+
46
+ dst
47
+ end
48
+
49
+ private
50
+
51
+ def target_resolution
52
+ @current_geometry.resize_to(@target_geometry.to_s).to_s.gsub(/[#!<>)]/, '')
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module PaperclipStreamioFFMPEG
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "paperclip-streamio-ffmpeg/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "paperclip-streamio-ffmpeg"
7
+ spec.version = PaperclipStreamioFFMPEG::VERSION
8
+ spec.authors = ["Daichi HIRATA"]
9
+ spec.email = ["daichirata@gmail.com"]
10
+
11
+ spec.summary = "Video Transcoder for Paperclip using streamio-ffmpeg"
12
+ spec.description = "Video Transcoder for Paperclip using streamio-ffmpeg"
13
+ spec.homepage = "https://github.com/daichirata/paperclip-streamio-ffmpeg"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "paperclip"
23
+ spec.add_dependency "streamio-ffmpeg", "~> 3.0"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3"
28
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-streamio-ffmpeg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daichi HIRATA
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paperclip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: streamio-ffmpeg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3'
83
+ description: Video Transcoder for Paperclip using streamio-ffmpeg
84
+ email:
85
+ - daichirata@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/paperclip-streamio-ffmpeg.rb
100
+ - lib/paperclip-streamio-ffmpeg/transcoder.rb
101
+ - lib/paperclip-streamio-ffmpeg/version.rb
102
+ - paperclip-streamio-ffmpeg.gemspec
103
+ homepage: https://github.com/daichirata/paperclip-streamio-ffmpeg
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.6.11
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Video Transcoder for Paperclip using streamio-ffmpeg
126
+ test_files: []