video_thumbnailer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 40d212a14ca07fc157ae317f09003b54a544a3ec
4
+ data.tar.gz: 33492b0632ebc89eab0c341d47ed7acfc1616001
5
+ SHA512:
6
+ metadata.gz: f21b86920a0ed48184052dbfc6dd7dd477a860c49103c58b05a4b6887e83486393514bfd9b60b4c1659b3bde00540a339b3cacb15457f9035b17d69c8b6bee3a
7
+ data.tar.gz: 2f9364f60f71897734c78aa466c0b0f3a00227fe1d60a71a546b4c74c99e47944434a07a168f9d0a24e67db7e8d19a197b1323c78bdd0a5304d3da2125c662f9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in video_thumbnailer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 teena
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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014-2015
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # VideoThumbnailer
2
+
3
+ A thumbnailer plugin for Carrierwave. This can be used to generate thumbnails for videos uploaded with carrier-wave.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'video_thumbnailer'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install video_thumbnailer
20
+
21
+ ## Usage
22
+
23
+ In the Rails app/uploaders/filename.rb, call the generate_thumb function with options.
24
+ The options are passed as hash to this function, can be also empty.
25
+
26
+ The options are:
27
+
28
+ * size - The height x width of the thumbnail to be generated, by default will take the same size of that of the video.
29
+ * file_extension - Format of the file to be saved, by default the form at will be jpeg.
30
+ * rotate - Orientation of the thumbnail image generated(Can be 90/180/270).
31
+ * time_frame - The time in the video at which the thumbnail must be generated.
32
+ * quality - Quality of the file to be saved.
33
+
34
+ ## Examples
35
+
36
+ Here's a working example:
37
+
38
+ In your Rails app/uploaders/video_uploader.rb:
39
+
40
+ ```
41
+ class VideoUploader < CarrierWave::Uploader::Base
42
+ include CarrierWave::RMagick
43
+ include VideoThumbnailer
44
+ storage :file
45
+
46
+ version :thumb do
47
+ process generate_thumb:[{size:"200 x 200",:quality => "5", :time_frame => "00:0:04", :file_extension => "jpeg", :rotate => 180 }]
48
+ def full_filename for_file
49
+ png_name for_file, version_name, "jpeg"
50
+ end
51
+ end
52
+
53
+ def png_name for_file, version_name, format
54
+ %Q{#{version_name}_#{for_file.chomp(File.extname(for_file))}.#{format}}
55
+ end
56
+
57
+ def store_dir
58
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
59
+ end
60
+
61
+ def extension_white_list
62
+ %w( mp4 jpg jpeg gif png )
63
+ end
64
+
65
+ end
66
+ ```
67
+
68
+ ## Development
69
+
70
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
71
+
72
+ 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).
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/video_thumbnailer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
77
+
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "video_thumbnailer"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ require "video_thumbnailer/version"
2
+ require 'open3'
3
+ require "video_thumbnailer/generate_command"
4
+ require "video_thumbnailer/options"
5
+ require "video_thumbnailer/logger"
6
+
7
+ module VideoThumbnailer
8
+
9
+ def generate_thumb options = {}
10
+ options[:file_extension] ||= 'jpeg'
11
+ options[:logger] = Rails.logger
12
+ tmp_path = File.join( File.dirname(current_path), "tmpfile.#{options[:file_extension]}")
13
+ thumbnail = GenerateCommand.new(current_path, tmp_path)
14
+ cmd = thumbnail.generate_command(options)
15
+ logger = VideoThumbnailer::Logger.new(options).logger
16
+ logger.info("Running command: #{cmd}")
17
+ exit_code, error = nil
18
+ raise Errno::ENOENT unless File.exist?(current_path)
19
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
20
+ error = stderr.read
21
+ exit_code = wait_thr.value
22
+ end
23
+ handle_exit_code(exit_code, error, logger)
24
+ File.rename tmp_path, current_path
25
+ end
26
+
27
+ private
28
+
29
+ def handle_exit_code(exit_code, error, logger)
30
+ if exit_code == 0
31
+ logger.info "Success!"
32
+ else
33
+ logger.error "Failure due to following error: #{error}"
34
+ end
35
+ exit_code
36
+ end
37
+
38
+ end
@@ -0,0 +1,16 @@
1
+ module VideoThumbnailer
2
+ class GenerateCommand
3
+
4
+ attr_reader :input_path, :output_path
5
+
6
+ def initialize(in_path, out_path)
7
+ @input_path = in_path
8
+ @output_path = out_path
9
+ end
10
+
11
+ def generate_command options = {}
12
+ options = VideoThumbnailer::Options.new(options)
13
+ %Q(ffmpeg #{options.to_options} #{output_path} -i #{input_path})
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module VideoThumbnailer
2
+ class Logger
3
+ attr_reader :logger
4
+
5
+ def initialize options
6
+ if options.has_key? :logger
7
+ @logger = options[:logger]
8
+ else
9
+ @logger = Logger.new(STDOUT)
10
+ @logger.level = Logger::INFO
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,46 @@
1
+ module VideoThumbnailer
2
+ class Options
3
+
4
+ CLI_KEY = {
5
+ size: '-s',
6
+ time_frame: '-ss',
7
+ quality: '-q',
8
+ file_extension: '-c'
9
+ }
10
+
11
+ def initialize options
12
+ @ptions = options
13
+ end
14
+
15
+ def to_options
16
+ result = @ptions.map do |k, v|
17
+ send(k.to_s, v)
18
+ end
19
+ result << "-vframes 1"
20
+ result.join(' ')
21
+ end
22
+
23
+ def file_extension value
24
+ case value
25
+ when 'jpeg' then %Q(-c mjpeg)
26
+ when 'png' then %Q(-c png)
27
+ else
28
+ " "
29
+ end
30
+ end
31
+
32
+ def rotate value
33
+ case value
34
+ when 90 then %Q(-vf transpose=1)
35
+ when 180 then %Q(-vf vflip )
36
+ when 270 then %Q(-vf transpose=2)
37
+ else
38
+ " "
39
+ end
40
+ end
41
+
42
+ def method_missing(name, *args)
43
+ "#{CLI_KEY[name]} #{args[0]}" if CLI_KEY.has_key? name
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module VideoThumbnailer
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'video_thumbnailer/generate_command'
3
+
4
+ RSpec.describe "generate_command" do
5
+
6
+ it "runs with generate_command" do
7
+ generate_command = VideoThumbnailer::GenerateCommand.new("/home/teena/video_upload_app/public/uploads/tmp/1444973790-5947-8599/thumb_ff.mp4
8
+ ", "/home/teena/video_upload_app/public/uploads/tmp/1444973790-5947-8599/tmpfile.jpg")
9
+ expect(generate_command.generate_command).to eq("ffmpeg -vframes 1 /home/teena/video_upload_app/public/uploads/tmp/1444973790-5947-8599/tmpfile.jpg -i /home/teena/video_upload_app/public/uploads/tmp/1444973790-5947-8599/thumb_ff.mp4\n")
10
+ end
11
+
12
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'video_thumbnailer/options'
3
+
4
+ RSpec.describe "to_options" do
5
+
6
+ it "runs with options" do
7
+ options = VideoThumbnailer::Options.new({:size => "40"})
8
+ expect(options.to_options).to eq("-s 40 -vframes 1")
9
+ end
10
+
11
+ it "runs with options" do
12
+ options = VideoThumbnailer::Options.new({:time_frame => '00:00:04'})
13
+ expect(options.to_options).to eq( "-ss 00:00:04 -vframes 1")
14
+ end
15
+
16
+ it "runs with options" do
17
+ options = VideoThumbnailer::Options.new({:file_extension => "jpg"})
18
+ expect(options.to_options).to eq("-c jpg -vframes 1")
19
+ end
20
+
21
+ it "runs with options" do
22
+ options = VideoThumbnailer::Options.new({:rotate => 90})
23
+ expect(options.to_options).to eq("-vf transpose=1 -vframes 1")
24
+ end
25
+
26
+ it "runs with options" do
27
+ options = VideoThumbnailer::Options.new({:quality => 5})
28
+ expect(options.to_options).to eq("-q 5 -vframes 1")
29
+ end
30
+
31
+ it "runs with options" do
32
+ options = VideoThumbnailer::Options.new({:size => "40", :time_frame => '00:00:04', :file_extension => "jpg", :rotate => 90, :quality => 5})
33
+ expect(options.to_options).to eq("-s 40 -ss 00:00:04 -c jpg -vf transpose=1 -q 5 -vframes 1")
34
+ end
35
+
36
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'video_thumbnailer'
3
+
4
+ RSpec.describe "generate_thumb" do
5
+ include VideoThumbnailer
6
+
7
+ # it "runs with options" do
8
+ # generatethumb = generate_thumb({:size => "40" })
9
+ # expect(generatethumb).to eq("")
10
+ # end
11
+
12
+ end
@@ -0,0 +1,3 @@
1
+ require 'rspec'
2
+ require 'video_thumbnailer'
3
+ require 'video_thumbnailer/options'
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'video_thumbnailer/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "video_thumbnailer"
7
+ spec.version = VideoThumbnailer::VERSION
8
+ spec.authors = ["teena, radhika"]
9
+ spec.email = ["teena@qburst.com"]
10
+ spec.summary = ""
11
+ spec.description = ""
12
+ spec.files = `git ls-files`.split("\n") # ["lib/video_thumbnailer/version.rb", "lib/video_thumbnailer/logger.rb", "lib/video_thumbnailer/options.rb", "lib/video_thumbnailer.rb","lib/video_thumbnailer/generate_command.rb"]
13
+ spec.bindir = "exe"
14
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
15
+ spec.require_paths = ["lib"]
16
+ spec.add_development_dependency "carrierwave-video"
17
+ spec.add_development_dependency "rspec"," ~> 2.4"
18
+ spec.add_development_dependency "bundler", "~> 1.10"
19
+ spec.add_development_dependency "rake", "~> 10.0"
20
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: video_thumbnailer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - teena, radhika
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: carrierwave-video
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.4'
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.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
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
+ description: ''
70
+ email:
71
+ - teena@qburst.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - MIT-LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/video_thumbnailer.rb
87
+ - lib/video_thumbnailer/generate_command.rb
88
+ - lib/video_thumbnailer/logger.rb
89
+ - lib/video_thumbnailer/options.rb
90
+ - lib/video_thumbnailer/version.rb
91
+ - spec/lib/generate_command_spec.rb
92
+ - spec/lib/options_spec.rb
93
+ - spec/lib/video_thumbnailer_spec.rb
94
+ - spec/spec_helper.rb
95
+ - video_thumbnailer.gemspec
96
+ homepage:
97
+ licenses: []
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.7
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: ''
119
+ test_files: []