paperclip_video_processor 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.md +2 -0
- data/Rakefile +1 -0
- data/lib/paperclip_video_processor.rb +42 -0
- data/lib/paperclip_video_processor/version.rb +3 -0
- data/paperclip_video_processor.gemspec +24 -0
- metadata +52 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "paperclip_video_processor/version"
|
2
|
+
|
3
|
+
module Paperclip
|
4
|
+
class PaperclipVideoProcessor < Processor
|
5
|
+
def initialize(file, options = {}, attachment = nil)
|
6
|
+
super
|
7
|
+
# Set options
|
8
|
+
@aspect = options[:size].try(:gsub, /x/, ':') || '480:320'
|
9
|
+
@audio_bitrate = options[:audio_bitrate] || '64k'
|
10
|
+
@audio_codec = options[:audio_codec] || 'libfaac'
|
11
|
+
@bitrate = options[:bitrate] || '256k'
|
12
|
+
@codec = options[:codec] || 'libx264'
|
13
|
+
@current_format = File.extname(@file.path)
|
14
|
+
@basename = File.basename(@file.path, @current_format)
|
15
|
+
@file = file
|
16
|
+
@size = options[:size] || '960x600'
|
17
|
+
@format = options[:format] || 'flv'
|
18
|
+
end
|
19
|
+
|
20
|
+
def make
|
21
|
+
Paperclip.options[:log_command] = true
|
22
|
+
# Create temp file for output
|
23
|
+
dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
|
24
|
+
dst.binmode
|
25
|
+
|
26
|
+
# FFMpeg command
|
27
|
+
command = <<-command
|
28
|
+
-y -i #{File.expand_path(@file.path)} -acodec #{@audio_codec} -ar 48000 -ab #{@audio_bitrate} -s #{@size} -vcodec #{@codec} -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt #{@bitrate} -maxrate #{@bitrate} -bufsize #{@bitrate} -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect #{@aspect} -g 30 -ss 0 -t 90 -async 2 #{File.expand_path(dst.path)}
|
29
|
+
command
|
30
|
+
|
31
|
+
# Run command, raise error if there's a problem
|
32
|
+
begin
|
33
|
+
success = Paperclip.run('ffmpeg', command)
|
34
|
+
rescue PaperclipCommandLineError
|
35
|
+
raise PaperclipError, "There was an error converting the video #{@basename}"
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return converted file
|
39
|
+
dst
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "paperclip_video_processor/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "paperclip_video_processor"
|
7
|
+
s.version = PaperclipVideoProcessor::VERSION
|
8
|
+
s.authors = ["BenZhang"]
|
9
|
+
s.email = ["bzbnhang@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/BenZhang/paperclip_video_processor"
|
11
|
+
s.summary = %q{Paperclip Video Processor}
|
12
|
+
s.description = %q{Video Converter}
|
13
|
+
|
14
|
+
s.rubyforge_project = "paperclip_video_processor"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclip_video_processor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- BenZhang
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-18 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Video Converter
|
15
|
+
email:
|
16
|
+
- bzbnhang@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- lib/paperclip_video_processor.rb
|
26
|
+
- lib/paperclip_video_processor/version.rb
|
27
|
+
- paperclip_video_processor.gemspec
|
28
|
+
homepage: https://github.com/BenZhang/paperclip_video_processor
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project: paperclip_video_processor
|
48
|
+
rubygems_version: 1.8.10
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: Paperclip Video Processor
|
52
|
+
test_files: []
|