carrierwave_streamio_ffmpeg 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/carrierwave_streamio_ffmpeg.gemspec +28 -0
- data/lib/carrierwave_streamio_ffmpeg.rb +23 -0
- data/lib/carrierwave_streamio_ffmpeg/options.rb +69 -0
- data/lib/carrierwave_streamio_ffmpeg/version.rb +3 -0
- data/spec/carrierwave_streamio_ffmpeg_spec.rb +2 -0
- data/spec/spec_helper.rb +11 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae25ed6753db25c448b8fb3130e6a542becf9be3
|
4
|
+
data.tar.gz: e485a824d8f51f0df98158923a04a636935a7ae4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6be2986f7ec59f9fc7410d1b341e139e5ba052f65eac6a9a46a1a663115544d3a95030975ea6415d878dd482bb0b424ef0e0c2672a4eff78d909e3eac6436d9
|
7
|
+
data.tar.gz: c21c83dc462411f648a8d5efed2c195cacfd3fc22d0c7f7bd2077d0ebeeaa60b92f269877f7e1984bd7aced78f9d23064cb899414a69f7206845af87d329bb22
|
data/.gitignore
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
# rspec failure tracking
|
12
|
+
.rspec_status
|
13
|
+
/.idea/.rakeTasks
|
14
|
+
/.idea/carrierwave_streamio_ffmpeg.iml
|
15
|
+
/.idea/misc.xml
|
16
|
+
/.idea/modules.xml
|
17
|
+
/.idea/workspace.xml
|
18
|
+
/carrierwave_streamio_ffmpeg-0.0.1.gem
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ssooraj7@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 ssooraj
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
## Installation
|
2
|
+
|
3
|
+
Add this line to your application's Gemfile:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
gem 'carrierwave_streamio_ffmpeg'
|
7
|
+
```
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install carrierwave_streamio_ffmpeg
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
In the Rails app/uploaders/filename.rb, call the encode function with options.
|
20
|
+
Example :
|
21
|
+
|
22
|
+
version :mp4 do
|
23
|
+
version :p480 do
|
24
|
+
process encode: [{format :mp4, resolution: :p480, quality: :low, preserve_aspect_ratio: :width}]
|
25
|
+
end
|
26
|
+
|
27
|
+
def full_filename(for_file)
|
28
|
+
super.chomp(File.extname(super)) + '.mp4'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
The options are passed as hash to this function, can be also empty.
|
33
|
+
|
34
|
+
The options are:
|
35
|
+
* format - format of the output video, possible options are mp4, webm and ogv
|
36
|
+
* resolution - resolution if output file, possible values are p240, p360, p480, p720, p1080 and p2160
|
37
|
+
* quality - Quality of the file to be saved, possible values are low, med, and high.
|
38
|
+
* preserve_aspect_ratio - value to be preserved when correcting aspect ration, possible values :width and :height.
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ssooraj/carrierwave_streamio_ffmpeg. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
43
|
+
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
48
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "carrierwave_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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'carrierwave_streamio_ffmpeg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'carrierwave_streamio_ffmpeg'
|
8
|
+
spec.version = CarrierwaveStreamioFfmpeg::VERSION
|
9
|
+
spec.authors = ['ssooraj']
|
10
|
+
spec.email = ['ssooraj7@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Carrierwave Video Processor using Streamio FFmpeg.'
|
13
|
+
spec.description = 'Generates a various versions for carrierwave uploaded videos,
|
14
|
+
versions can be generated giving options for quality, size, etc.'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split("\n")
|
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 'carrierwave'
|
23
|
+
spec.add_dependency 'streamio-ffmpeg'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
26
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'carrierwave_streamio_ffmpeg/version'
|
2
|
+
require 'carrierwave_streamio_ffmpeg/options'
|
3
|
+
|
4
|
+
module CarrierwaveStreamioFfmpeg
|
5
|
+
|
6
|
+
def encode(format, opts = {})
|
7
|
+
process encode: [ format, opts ]
|
8
|
+
end
|
9
|
+
|
10
|
+
def movie(path)
|
11
|
+
::FFMPEG::Movie.new path
|
12
|
+
end
|
13
|
+
|
14
|
+
def encode(format, opts = {})
|
15
|
+
tmp_path = File.join(File.dirname(current_path), "tmp_file.#{format}")
|
16
|
+
file = movie(current_path)
|
17
|
+
options = CarrierwaveStreamioFfmpeg::Options.new
|
18
|
+
file.transcode(tmp_path,
|
19
|
+
options.video_options(file, opts) ,
|
20
|
+
options.transcoder_options(opts))
|
21
|
+
File.rename(tmp_path, current_path)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module CarrierwaveStreamioFfmpeg
|
2
|
+
class Options
|
3
|
+
|
4
|
+
def video_options(file, opts = {})
|
5
|
+
opts[:resolution] = set_file_resolution(opts, file)
|
6
|
+
opts[:video_bitrate] = set_file_quality(opts, file)
|
7
|
+
opts[:threads] = 4
|
8
|
+
format = opts(:format)
|
9
|
+
opts = opts.except(:quality, :preserve_aspect_ratio, :format)
|
10
|
+
opts.merge!(codec(format))
|
11
|
+
end
|
12
|
+
|
13
|
+
def set_file_quality(opts, file)
|
14
|
+
case opts[:quality]
|
15
|
+
when :low
|
16
|
+
1250
|
17
|
+
when :med
|
18
|
+
5000
|
19
|
+
when :high
|
20
|
+
15000
|
21
|
+
else
|
22
|
+
(file.bitrate)/1024
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_file_resolution(opts, file)
|
27
|
+
case opts[:resolution]
|
28
|
+
when :p240
|
29
|
+
'352 x 240'
|
30
|
+
when :p360
|
31
|
+
'480 x 360'
|
32
|
+
when :p480
|
33
|
+
'858 x 480'
|
34
|
+
when :p720
|
35
|
+
'1280 x 720'
|
36
|
+
when :p1080
|
37
|
+
'1920 x 1080'
|
38
|
+
when :p2160
|
39
|
+
'3860 x 2160'
|
40
|
+
else
|
41
|
+
file.resolution
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def codec(format)
|
46
|
+
case format
|
47
|
+
when :mp4
|
48
|
+
{ video_codec: 'libx264',
|
49
|
+
audio_codec: 'libvo_aacenc' }
|
50
|
+
when :webm
|
51
|
+
{ video_codec: 'libvpx',
|
52
|
+
audio_codec: 'libvorbis' }
|
53
|
+
when :ogv
|
54
|
+
{ video_codec: 'libtheora',
|
55
|
+
audio_codec: 'libvorbis' }
|
56
|
+
else
|
57
|
+
raise CarrierWave::ProcessingError.new("Unsupported video format. Error: #{e}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def transcoder_options(opts)
|
62
|
+
if opts[:preserve_aspect_ratio]
|
63
|
+
{ preserve_aspect_ratio: opts[:preserve_aspect_ratio] }
|
64
|
+
else
|
65
|
+
{ preserve_aspect_ratio: :height }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "carrierwave_streamio_ffmpeg"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
config.expect_with :rspec do |c|
|
9
|
+
c.syntax = :expect
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave_streamio_ffmpeg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ssooraj
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: carrierwave
|
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: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.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.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.5'
|
83
|
+
description: |-
|
84
|
+
Generates a various versions for carrierwave uploaded videos,
|
85
|
+
versions can be generated giving options for quality, size, etc.
|
86
|
+
email:
|
87
|
+
- ssooraj7@gmail.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- CODE_OF_CONDUCT.md
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- carrierwave_streamio_ffmpeg.gemspec
|
103
|
+
- lib/carrierwave_streamio_ffmpeg.rb
|
104
|
+
- lib/carrierwave_streamio_ffmpeg/options.rb
|
105
|
+
- lib/carrierwave_streamio_ffmpeg/version.rb
|
106
|
+
- spec/carrierwave_streamio_ffmpeg_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
homepage:
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.6.8
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Carrierwave Video Processor using Streamio FFmpeg.
|
132
|
+
test_files: []
|