sidekiq-ffmpeg 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +6 -0
- data/ci/install_ffmpeg +5 -0
- data/lib/sidekiq/ffmpeg/base_job.rb +26 -0
- data/lib/sidekiq/ffmpeg/encoder/base.rb +93 -0
- data/lib/sidekiq/ffmpeg/encoder/mp4.rb +50 -0
- data/lib/sidekiq/ffmpeg/encoder/webm.rb +29 -0
- data/lib/sidekiq/ffmpeg/version.rb +5 -0
- data/lib/sidekiq/ffmpeg.rb +43 -0
- data/lib/sidekiq-ffmpeg.rb +1 -0
- data/sidekiq-ffmpeg.gemspec +27 -0
- data/spec/lib/sidekiq-ffmpeg_spec.rb +139 -0
- data/spec/samples/hoge's title.mp4 +0 -0
- data/spec/samples/sample.mp4 +0 -0
- data/spec/samples/sample_16_9.mp4 +0 -0
- data/spec/spec_helper.rb +21 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0fd84dc73609c31c9d821ccaf24fab60c772fdc2
|
4
|
+
data.tar.gz: b215f34ed14d491ffd9769aa16189125c3ef804f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 444051cd8fc1c8258d6e0f1425c1694370e8bbec207c55f4d005da552a474b95ecacab659de21eb52941072a511598f5e78fb4154855076eebc0af966e003c2f
|
7
|
+
data.tar.gz: eeac2274964aab091595b6b93abbdeada9d2841f63ffab63ccd546c1c97c48432679ac072217aa31d863f8f7e2d86548b025e2b2fe93f37036fa6b3031211920
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 joker1007
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Sidekiq::Ffmpeg
|
2
|
+
[![Build Status](https://travis-ci.org/joker1007/sidekiq-ffmpeg.svg?branch=master)](https://travis-ci.org/joker1007/sidekiq-ffmpeg)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/joker1007/sidekiq-ffmpeg/badge.png)](https://coveralls.io/r/joker1007/sidekiq-ffmpeg)
|
4
|
+
|
5
|
+
Sidekiq job definition for ffmpeg.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'sidekiq-ffmpeg', github: "joker1007/sidekiq-ffmpeg"
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
class EncodeJob < Sidekiq::Ffmpeg::BaseJob
|
21
|
+
|
22
|
+
def on_progress(progress, extra_data = {})
|
23
|
+
p progress
|
24
|
+
end
|
25
|
+
|
26
|
+
def on_complete(encoder, extra_data = {})
|
27
|
+
puts "complete"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
EncodeJob.perform_async(input_filename, output_filename, extra_data, :mp4)
|
32
|
+
```
|
33
|
+
|
34
|
+
Implemented Encoder class is following:
|
35
|
+
|
36
|
+
- mp4
|
37
|
+
- WebM
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it ( https://github.com/[my-github-username]/sidekiq-ffmpeg/fork )
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/ci/install_ffmpeg
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Ffmpeg
|
3
|
+
class BaseJob
|
4
|
+
include Sidekiq::Worker
|
5
|
+
|
6
|
+
def perform(input_filename, output_filename, extra_data = {}, format = :mp4)
|
7
|
+
case format.to_s
|
8
|
+
when "mp4"
|
9
|
+
encoder = Encoder::MP4.new
|
10
|
+
when "webm"
|
11
|
+
encoder = Encoder::WebM.new
|
12
|
+
end
|
13
|
+
|
14
|
+
if respond_to?(:on_progress)
|
15
|
+
encoder.on_progress = Proc.new {|progress| on_progress(progress, extra_data)}
|
16
|
+
end
|
17
|
+
|
18
|
+
if respond_to?(:on_complete)
|
19
|
+
encoder.on_complete = Proc.new {|enc| on_complete(enc, extra_data)}
|
20
|
+
end
|
21
|
+
|
22
|
+
encoder.do_encode(input_filename, output_filename)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "shellwords"
|
2
|
+
require "open3"
|
3
|
+
|
4
|
+
module Sidekiq
|
5
|
+
module Ffmpeg
|
6
|
+
module Encoder
|
7
|
+
class Base
|
8
|
+
attr_reader :size, :video_bitrate, :audio_bitrate, :audio_sample_rate, :other_options
|
9
|
+
attr_reader :input_filename, :output_filename
|
10
|
+
attr_reader :on_progress, :on_complete
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
raise ArgumentError unless options.is_a?(Hash)
|
14
|
+
merged_options = preset_options.merge(options)
|
15
|
+
@size = merged_options[:size]
|
16
|
+
@aspect = merged_options[:aspect]
|
17
|
+
@video_bitrate = merged_options[:video_bitrate]
|
18
|
+
@audio_bitrate = merged_options[:audio_bitrate]
|
19
|
+
@audio_sample_rate = merged_options[:audio_sample_rate]
|
20
|
+
@other_options = merged_options[:other_options]
|
21
|
+
end
|
22
|
+
|
23
|
+
def preset_options
|
24
|
+
{}
|
25
|
+
end
|
26
|
+
|
27
|
+
def format
|
28
|
+
raise NotImplementedError
|
29
|
+
end
|
30
|
+
|
31
|
+
def vcodec
|
32
|
+
raise NotImplementedError
|
33
|
+
end
|
34
|
+
|
35
|
+
def acodec
|
36
|
+
raise NotImplementedError
|
37
|
+
end
|
38
|
+
|
39
|
+
def aspect(filename = nil)
|
40
|
+
@aspect || Ffmpeg.get_aspect(filename)
|
41
|
+
end
|
42
|
+
|
43
|
+
def on_progress=(progress_proc)
|
44
|
+
raise ArgumentError unless progress_proc.is_a?(Proc)
|
45
|
+
@on_progress = progress_proc
|
46
|
+
end
|
47
|
+
|
48
|
+
def on_complete=(complete_proc)
|
49
|
+
raise ArgumentError unless complete_proc.is_a?(Proc)
|
50
|
+
@on_complete = complete_proc
|
51
|
+
end
|
52
|
+
|
53
|
+
def do_encode(input, output)
|
54
|
+
@input_filename = input
|
55
|
+
@output_filename = output
|
56
|
+
cmd = %W(#{Ffmpeg.ffmpeg_cmd} -y -i #{@input_filename} -f #{format} -s #{size} -aspect #{aspect(@input_filename)} -vcodec #{vcodec} -b:v #{video_bitrate} -acodec #{acodec} -ar #{audio_sample_rate} -b:a #{audio_bitrate})
|
57
|
+
cmd.concat(other_options.split(" "))
|
58
|
+
cmd.reject!(&:empty?)
|
59
|
+
cmd << @output_filename
|
60
|
+
|
61
|
+
if ENV["DEBUG"]
|
62
|
+
Ffmpeg.logger.debug(cmd.map(&:shellescape).join(" "))
|
63
|
+
end
|
64
|
+
|
65
|
+
duration = nil
|
66
|
+
time = nil
|
67
|
+
progress = nil
|
68
|
+
|
69
|
+
Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_th|
|
70
|
+
while line = stderr.gets("\r")
|
71
|
+
if line =~ /Duration:(\s.?(\d*):(\d*):(\d*)\.(\d*))/
|
72
|
+
duration = $2.to_i * 3600 + $3.to_i * 60 + $4.to_i
|
73
|
+
end
|
74
|
+
|
75
|
+
if line =~ /frame=.*time=(\s*(\d*):(\d*):(\d*)\.(\d*))/
|
76
|
+
time = $2.to_i * 3600 + $3.to_i * 60 + $4.to_i
|
77
|
+
end
|
78
|
+
|
79
|
+
if duration && time
|
80
|
+
progress = (time / duration.to_f)
|
81
|
+
on_progress.call(progress) if on_progress
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
wait_th.join
|
86
|
+
end
|
87
|
+
|
88
|
+
on_complete.call(self) if on_complete
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Ffmpeg
|
3
|
+
module Encoder
|
4
|
+
class MP4 < Base
|
5
|
+
def initialize(options = {})
|
6
|
+
super
|
7
|
+
@acodec = options[:acodec] || acodec_select
|
8
|
+
end
|
9
|
+
|
10
|
+
def preset_options
|
11
|
+
{
|
12
|
+
:size => "640x480",
|
13
|
+
:video_bitrate => "600k",
|
14
|
+
:audio_bitrate => "128k",
|
15
|
+
:audio_sample_rate => 44100,
|
16
|
+
:other_options => "-partitions all -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -maxrate 1000 -level 30 -async 2#{acodec_select == "libfdk_aac" ? " -cutoff 18000" : ""}"
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def vcodec
|
21
|
+
"libx264"
|
22
|
+
end
|
23
|
+
|
24
|
+
def acodec
|
25
|
+
@acodec
|
26
|
+
end
|
27
|
+
|
28
|
+
def format
|
29
|
+
"mp4"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def acodec_select
|
35
|
+
return @acodec if @acodec
|
36
|
+
@acodec = case `#{Ffmpeg.ffmpeg_cmd} -v quiet -codecs | grep aac`
|
37
|
+
when /libfdk_aac/
|
38
|
+
"libfdk_aac"
|
39
|
+
when /libfaac/
|
40
|
+
"libfaac"
|
41
|
+
when /aac/
|
42
|
+
"aac"
|
43
|
+
when /libvo_aacenc/
|
44
|
+
"libvo_aacenc"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Ffmpeg
|
3
|
+
module Encoder
|
4
|
+
class WebM < Base
|
5
|
+
def preset_options
|
6
|
+
{
|
7
|
+
:size => "640x480",
|
8
|
+
:video_bitrate => "600k",
|
9
|
+
:audio_bitrate => "128k",
|
10
|
+
:audio_sample_rate => 44100,
|
11
|
+
:other_options => "-aq 3 -partitions all -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -async 2"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def vcodec
|
16
|
+
"libvpx"
|
17
|
+
end
|
18
|
+
|
19
|
+
def acodec
|
20
|
+
"libvorbis"
|
21
|
+
end
|
22
|
+
|
23
|
+
def format
|
24
|
+
"webm"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "sidekiq/ffmpeg/version"
|
2
|
+
|
3
|
+
require "sidekiq"
|
4
|
+
|
5
|
+
module Sidekiq
|
6
|
+
module Ffmpeg
|
7
|
+
|
8
|
+
autoload :BaseJob, "#{File.dirname(__FILE__)}/ffmpeg/base_job"
|
9
|
+
|
10
|
+
module Encoder
|
11
|
+
autoload :Base, "#{File.dirname(__FILE__)}/ffmpeg/encoder/base"
|
12
|
+
autoload :MP4, "#{File.dirname(__FILE__)}/ffmpeg/encoder/mp4"
|
13
|
+
autoload :WebM, "#{File.dirname(__FILE__)}/ffmpeg/encoder/webm"
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def logger
|
18
|
+
@logger ||= Logger.new($stdout)
|
19
|
+
end
|
20
|
+
|
21
|
+
def logger=(logger)
|
22
|
+
@logger = logger
|
23
|
+
end
|
24
|
+
|
25
|
+
def ffmpeg_cmd
|
26
|
+
ENV["FFMPEG"] || "ffmpeg"
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_aspect(filename)
|
30
|
+
return nil unless filename
|
31
|
+
|
32
|
+
aspect = nil
|
33
|
+
ffmpeg = IO.popen("#{ffmpeg_cmd} -i #{filename.shellescape} 2>&1")
|
34
|
+
ffmpeg.each("\r") do |line|
|
35
|
+
if line =~ /Stream.*Video.*, (\d+)x(\d+)[,\s]/
|
36
|
+
aspect = "#{$1}/#{$2}".to_r
|
37
|
+
end
|
38
|
+
end
|
39
|
+
aspect
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "sidekiq/ffmpeg"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sidekiq/ffmpeg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sidekiq-ffmpeg"
|
8
|
+
spec.version = Sidekiq::Ffmpeg::VERSION
|
9
|
+
spec.authors = ["joker1007"]
|
10
|
+
spec.email = ["kakyoin.hierophant@gmail.com"]
|
11
|
+
spec.description = %q{easier way to use ffmpeg in sidekiq}
|
12
|
+
spec.summary = %q{easier way to use ffmpeg in sidekiq}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "sidekiq", ">= 2.1", "< 4"
|
22
|
+
spec.add_development_dependency "bundler", ">= 1.5"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "tapp"
|
26
|
+
spec.add_development_dependency "coveralls"
|
27
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "sidekiq/testing"
|
3
|
+
|
4
|
+
Sidekiq::Testing.fake!
|
5
|
+
|
6
|
+
describe Sidekiq::Ffmpeg do
|
7
|
+
describe ".get_aspect" do
|
8
|
+
subject { Sidekiq::Ffmpeg.get_aspect("#{sample_dir}/sample_16_9.mp4") }
|
9
|
+
|
10
|
+
it { should eq "16/9".to_r }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#do_encode" do
|
14
|
+
context "MP4" do
|
15
|
+
subject(:encoder) { Sidekiq::Ffmpeg::Encoder::MP4.new }
|
16
|
+
|
17
|
+
describe "on_progress callback" do
|
18
|
+
before do
|
19
|
+
encoder.on_progress = Proc.new {|progress| true }
|
20
|
+
end
|
21
|
+
|
22
|
+
it "on_progress receive call" do
|
23
|
+
expect(encoder.on_progress).to receive(:call).with(an_instance_of(Float)).at_least(5).and_call_original
|
24
|
+
encoder.do_encode("#{sample_dir}/sample.mp4", "#{sample_dir}/output.mp4")
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "shellescape" do
|
28
|
+
it "on_progress receive call" do
|
29
|
+
expect(encoder.on_progress).to receive(:call).with(an_instance_of(Float)).at_least(5).and_call_original
|
30
|
+
encoder.do_encode("#{sample_dir}/hoge's title.mp4", "#{sample_dir}/output.mp4")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "on_complete callback" do
|
36
|
+
before do
|
37
|
+
encoder.on_complete = Proc.new {|encoder| true }
|
38
|
+
end
|
39
|
+
|
40
|
+
it "on_complete receive call" do
|
41
|
+
expect(encoder.on_complete).to receive(:call).with(encoder).once
|
42
|
+
encoder.do_encode("#{sample_dir}/sample.mp4", "#{sample_dir}/output.mp4")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "debug log" do
|
47
|
+
before do
|
48
|
+
ENV["DEBUG"] = "1"
|
49
|
+
expect(Sidekiq::Ffmpeg.logger).to be_a(Logger)
|
50
|
+
end
|
51
|
+
|
52
|
+
after do
|
53
|
+
ENV["DEBUG"] = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should call logger.debug" do
|
57
|
+
expect(Sidekiq::Ffmpeg.logger).to receive(:debug)
|
58
|
+
encoder.do_encode("#{sample_dir}/sample.mp4", "#{sample_dir}/output.mp4")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "WebM" do
|
64
|
+
subject(:encoder) { Sidekiq::Ffmpeg::Encoder::WebM.new }
|
65
|
+
|
66
|
+
describe "on_progress callback" do
|
67
|
+
before do
|
68
|
+
encoder.on_progress = Proc.new {|progress| true }
|
69
|
+
end
|
70
|
+
|
71
|
+
it "on_progress receive call" do
|
72
|
+
expect(encoder.on_progress).to receive(:call).with(an_instance_of(Float)).at_least(5)
|
73
|
+
encoder.do_encode("#{sample_dir}/sample.mp4", "#{sample_dir}/output.webm")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "on_complete callback" do
|
78
|
+
before do
|
79
|
+
encoder.on_complete = Proc.new {|encoder| true }
|
80
|
+
end
|
81
|
+
|
82
|
+
it "on_complete receive call" do
|
83
|
+
expect(encoder.on_complete).to receive(:call).with(encoder).once
|
84
|
+
encoder.do_encode("#{sample_dir}/sample.mp4", "#{sample_dir}/output.webm")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe Sidekiq::Ffmpeg::BaseJob do
|
92
|
+
context "When job is performed" do
|
93
|
+
class ::TestJob < Sidekiq::Ffmpeg::BaseJob
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should receive do_encode" do
|
97
|
+
input_filename = "#{sample_dir}/sample.mp4"
|
98
|
+
output_filename = "#{sample_dir}/output.mp4"
|
99
|
+
expect_any_instance_of(Sidekiq::Ffmpeg::Encoder::MP4).to receive(:do_encode).with(input_filename, output_filename).once
|
100
|
+
TestJob.perform_async(input_filename, output_filename)
|
101
|
+
TestJob.drain
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "Job class has on_progress method" do
|
106
|
+
class ProgressJob < Sidekiq::Ffmpeg::BaseJob
|
107
|
+
|
108
|
+
def on_progress(progress, extra_data = {})
|
109
|
+
true
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should receive on_progress" do
|
114
|
+
input_filename = "#{sample_dir}/sample.mp4"
|
115
|
+
output_filename = "#{sample_dir}/output.mp4"
|
116
|
+
expect_any_instance_of(ProgressJob).to receive(:on_progress).with(an_instance_of(Float), {}).at_least(5)
|
117
|
+
ProgressJob.perform_async(input_filename, output_filename)
|
118
|
+
ProgressJob.drain
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "Job class has on_complete method" do
|
123
|
+
class CompleteJob < Sidekiq::Ffmpeg::BaseJob
|
124
|
+
|
125
|
+
def on_complete(encoder, extra_data = {})
|
126
|
+
true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should receive on_complete" do
|
131
|
+
input_filename = "#{sample_dir}/sample.mp4"
|
132
|
+
output_filename = "#{sample_dir}/output.mp4"
|
133
|
+
expect_any_instance_of(CompleteJob).to receive(:on_complete).with(an_instance_of(Sidekiq::Ffmpeg::Encoder::MP4), {"id" => 1}).once
|
134
|
+
CompleteJob.perform_async(input_filename, output_filename, {"id" => 1})
|
135
|
+
CompleteJob.drain
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
Binary file
|
Binary file
|
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'coveralls'
|
3
|
+
Coveralls.wear!
|
4
|
+
|
5
|
+
require 'sidekiq/ffmpeg'
|
6
|
+
|
7
|
+
require 'tapp'
|
8
|
+
|
9
|
+
$spec_dir = File.dirname(File.expand_path(__FILE__))
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.order = :random
|
13
|
+
|
14
|
+
config.before(:each) do
|
15
|
+
Sidekiq::Worker.clear_all
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def sample_dir
|
20
|
+
File.expand_path("../samples", __FILE__)
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-ffmpeg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- joker1007
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sidekiq
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.1'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.5'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.5'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: tapp
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: coveralls
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
description: easier way to use ffmpeg in sidekiq
|
104
|
+
email:
|
105
|
+
- kakyoin.hierophant@gmail.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- ".gitignore"
|
111
|
+
- ".rspec"
|
112
|
+
- ".travis.yml"
|
113
|
+
- Gemfile
|
114
|
+
- LICENSE.txt
|
115
|
+
- README.md
|
116
|
+
- Rakefile
|
117
|
+
- ci/install_ffmpeg
|
118
|
+
- lib/sidekiq-ffmpeg.rb
|
119
|
+
- lib/sidekiq/ffmpeg.rb
|
120
|
+
- lib/sidekiq/ffmpeg/base_job.rb
|
121
|
+
- lib/sidekiq/ffmpeg/encoder/base.rb
|
122
|
+
- lib/sidekiq/ffmpeg/encoder/mp4.rb
|
123
|
+
- lib/sidekiq/ffmpeg/encoder/webm.rb
|
124
|
+
- lib/sidekiq/ffmpeg/version.rb
|
125
|
+
- sidekiq-ffmpeg.gemspec
|
126
|
+
- spec/lib/sidekiq-ffmpeg_spec.rb
|
127
|
+
- spec/samples/hoge's title.mp4
|
128
|
+
- spec/samples/sample.mp4
|
129
|
+
- spec/samples/sample_16_9.mp4
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
homepage: ''
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.2.2
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: easier way to use ffmpeg in sidekiq
|
155
|
+
test_files:
|
156
|
+
- spec/lib/sidekiq-ffmpeg_spec.rb
|
157
|
+
- spec/samples/hoge's title.mp4
|
158
|
+
- spec/samples/sample.mp4
|
159
|
+
- spec/samples/sample_16_9.mp4
|
160
|
+
- spec/spec_helper.rb
|
161
|
+
has_rdoc:
|