falcon 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +18 -0
- data/Gemfile +9 -0
- data/README.md +100 -0
- data/Rakefile +64 -36
- data/bin/falcon +28 -0
- data/falcon.gemspec +31 -0
- data/lib/falcon.rb +20 -57
- data/lib/falcon/command.rb +86 -0
- data/lib/falcon/server.rb +73 -0
- data/lib/falcon/version.rb +21 -1
- data/lib/rack/handler/falcon.rb +40 -0
- metadata +148 -77
- data/LICENSE +0 -19
- data/README.rdoc +0 -159
- data/app/models/falcon/encoding.rb +0 -5
- data/lib/falcon/base.rb +0 -98
- data/lib/falcon/encoder.rb +0 -235
- data/lib/falcon/engine.rb +0 -12
- data/lib/falcon/media.rb +0 -154
- data/lib/falcon/profile.rb +0 -96
- data/lib/falcon/profiles.rb +0 -9
- data/lib/generators/falcon/USAGE +0 -7
- data/lib/generators/falcon/install_generator.rb +0 -31
- data/lib/generators/falcon/templates/migrate/create_encodings.rb +0 -29
@@ -0,0 +1,73 @@
|
|
1
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'async/http/server'
|
22
|
+
|
23
|
+
module Falcon
|
24
|
+
class Server < Async::HTTP::Server
|
25
|
+
def initialize(app, *args)
|
26
|
+
super(*args)
|
27
|
+
|
28
|
+
@app = app
|
29
|
+
end
|
30
|
+
|
31
|
+
def handle_request(request, peer, address)
|
32
|
+
request_path, query_string = request.path.split('?', 2)
|
33
|
+
server_name, server_port = request.headers.fetch('HTTP_HOST', '').split(':', 2)
|
34
|
+
|
35
|
+
input = StringIO.new(request.body || '')
|
36
|
+
input.set_encoding(Encoding::BINARY)
|
37
|
+
|
38
|
+
env = {
|
39
|
+
'rack.version' => [2, 0, 0],
|
40
|
+
|
41
|
+
'rack.input' => input,
|
42
|
+
'rack.errors' => $stderr,
|
43
|
+
|
44
|
+
'rack.multithread' => true,
|
45
|
+
'rack.multiprocess' => true,
|
46
|
+
'rack.run_once' => false,
|
47
|
+
|
48
|
+
# The HTTP request method, such as “GET” or “POST”. This cannot ever be an empty string, and so is always required.
|
49
|
+
'REQUEST_METHOD' => request.method,
|
50
|
+
|
51
|
+
# The initial portion of the request URL's “path” that corresponds to the application object, so that the application knows its virtual “location”. This may be an empty string, if the application corresponds to the “root” of the server.
|
52
|
+
'SCRIPT_NAME' => '',
|
53
|
+
|
54
|
+
# The remainder of the request URL's “path”, designating the virtual “location” of the request's target within the application. This may be an empty string, if the request URL targets the application root and does not have a trailing slash. This value may be percent-encoded when originating from a URL.
|
55
|
+
'PATH_INFO' => request_path,
|
56
|
+
|
57
|
+
# The portion of the request URL that follows the ?, if any. May be empty, but is always required!
|
58
|
+
'QUERY_STRING' => query_string || '',
|
59
|
+
|
60
|
+
# The server protocol, e.g. HTTP/1.1
|
61
|
+
'SERVER_PROTOCOL' => request.version,
|
62
|
+
'rack.url_scheme' => 'http',
|
63
|
+
|
64
|
+
'SERVER_NAME' => server_name,
|
65
|
+
'SERVER_PORT' => server_port,
|
66
|
+
}.merge(request.headers)
|
67
|
+
|
68
|
+
return @app.call(env)
|
69
|
+
rescue
|
70
|
+
[500, {'Content-Type' => 'text/plain'}, [$!.inspect, "\n", $!.backtrace.join("\n\t")]]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/falcon/version.rb
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
1
21
|
module Falcon
|
2
|
-
|
22
|
+
VERSION = "0.2.0"
|
3
23
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
require 'rack/handler'
|
3
|
+
|
4
|
+
require_relative '../../falcon'
|
5
|
+
|
6
|
+
module Rack
|
7
|
+
module Handler
|
8
|
+
module Falcon
|
9
|
+
def self.run(app, **options)
|
10
|
+
command = ::Falcon::Command::Serve.new([])
|
11
|
+
|
12
|
+
process_count = command.options[:process]
|
13
|
+
|
14
|
+
pids = process_count.times.collect do
|
15
|
+
fork do
|
16
|
+
puts "Serving from pid #{Process.pid}"
|
17
|
+
command.run(app, options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
sleep
|
22
|
+
ensure
|
23
|
+
pids.each do |pid|
|
24
|
+
Process.kill(:TERM, pid) rescue nil
|
25
|
+
Process.wait(pid)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.valid_options
|
30
|
+
{
|
31
|
+
"host=HOST" => "Hostname to listen on (default: localhost)",
|
32
|
+
"port=PORT" => "Port to listen on (default: 8080)",
|
33
|
+
"verbose" => "Don't report each request (default: false)"
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
register :falcon, Falcon
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,98 +1,169 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: falcon
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 3
|
10
|
-
version: 0.1.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
-
|
14
|
-
- Pavlo Galeta
|
6
|
+
authors:
|
7
|
+
- Samuel Williams
|
15
8
|
autorequire:
|
16
9
|
bindir: bin
|
17
10
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
date: 2017-06-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: async-http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
23
20
|
type: :runtime
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 23
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 1
|
33
|
-
- 2
|
34
|
-
version: 1.1.2
|
35
|
-
name: web_video
|
36
|
-
version_requirements: *id001
|
37
21
|
prerelease: false
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: async-container
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: samovar
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: async-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.6'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.6'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description:
|
126
|
+
email:
|
127
|
+
- samuel.williams@oriontransfer.co.nz
|
128
|
+
executables:
|
129
|
+
- falcon
|
42
130
|
extensions: []
|
43
|
-
|
44
|
-
|
45
|
-
-
|
46
|
-
-
|
47
|
-
|
48
|
-
-
|
49
|
-
- README.
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".travis.yml"
|
136
|
+
- Gemfile
|
137
|
+
- README.md
|
50
138
|
- Rakefile
|
51
|
-
-
|
139
|
+
- bin/falcon
|
140
|
+
- falcon.gemspec
|
52
141
|
- lib/falcon.rb
|
53
|
-
- lib/falcon/
|
54
|
-
- lib/falcon/
|
55
|
-
- lib/falcon/engine.rb
|
56
|
-
- lib/falcon/media.rb
|
57
|
-
- lib/falcon/profile.rb
|
58
|
-
- lib/falcon/profiles.rb
|
142
|
+
- lib/falcon/command.rb
|
143
|
+
- lib/falcon/server.rb
|
59
144
|
- lib/falcon/version.rb
|
60
|
-
- lib/
|
61
|
-
|
62
|
-
- lib/generators/falcon/templates/migrate/create_encodings.rb
|
63
|
-
has_rdoc: true
|
64
|
-
homepage: https://github.com/galetahub/falcon
|
145
|
+
- lib/rack/handler/falcon.rb
|
146
|
+
homepage: https://github.com/socketry/falcon
|
65
147
|
licenses: []
|
66
|
-
|
148
|
+
metadata: {}
|
67
149
|
post_install_message:
|
68
150
|
rdoc_options: []
|
69
|
-
|
70
|
-
require_paths:
|
151
|
+
require_paths:
|
71
152
|
- lib
|
72
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
-
|
74
|
-
requirements:
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
75
155
|
- - ">="
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
version: "0"
|
81
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
|
-
requirements:
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
84
160
|
- - ">="
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
segments:
|
88
|
-
- 0
|
89
|
-
version: "0"
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
90
163
|
requirements: []
|
91
|
-
|
92
164
|
rubyforge_project:
|
93
|
-
rubygems_version:
|
165
|
+
rubygems_version: 2.6.10
|
94
166
|
signing_key:
|
95
|
-
specification_version:
|
96
|
-
summary:
|
167
|
+
specification_version: 4
|
168
|
+
summary: ''
|
97
169
|
test_files: []
|
98
|
-
|
data/LICENSE
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
Copyright (c) 2010-2011 Aimbulance.
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
5
|
-
in the Software without restriction, including without limitation the rights
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
8
|
-
furnished to do so, subject to the following conditions:
|
9
|
-
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
11
|
-
all copies or substantial portions of the Software.
|
12
|
-
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
data/README.rdoc
DELETED
@@ -1,159 +0,0 @@
|
|
1
|
-
= Falcon
|
2
|
-
|
3
|
-
Video encoding tool.
|
4
|
-
|
5
|
-
== Install
|
6
|
-
|
7
|
-
gem 'falcon'
|
8
|
-
|
9
|
-
rails generate falcon:install
|
10
|
-
|
11
|
-
rake db:migrate
|
12
|
-
|
13
|
-
== Usage
|
14
|
-
|
15
|
-
=== Create profiles
|
16
|
-
|
17
|
-
By default avariable two profiles "web_mp4" and "web_ogg":
|
18
|
-
|
19
|
-
Falcon::Profile.new("web_mp4", {:player => 'flash', :container => "mp4", :extname => 'mp4',
|
20
|
-
:width => 480, :height => 320, :video_codec => "libx264",
|
21
|
-
:command => "-vpre slow -crf 22", :video_bitrate => 500, :fps => 29.97,
|
22
|
-
:audio_codec => "libfaac", :audio_bitrate => 128, :audio_sample_rate => 48000})
|
23
|
-
|
24
|
-
Falcon::Profile.new("web_ogg", {:player => 'html5', :container => "ogg", :extname => 'ogv',
|
25
|
-
:width => 480, :height => 320, :video_codec => "libtheora", :command => '-g 300',
|
26
|
-
:video_bitrate => 1000, :fps => 29.97, :audio_codec => "libvorbis",
|
27
|
-
:audio_bitrate => 128, :audio_sample_rate => 48000})
|
28
|
-
|
29
|
-
=== Update profiles
|
30
|
-
|
31
|
-
Falcon::Profile['web_mp4'].update({:width => 800, :height => 600})
|
32
|
-
|
33
|
-
=== Model
|
34
|
-
|
35
|
-
Model has attachment file, we declare "falcon_encode" method and pass :source and :profiles options:
|
36
|
-
|
37
|
-
class VideoFile
|
38
|
-
has_attached_file :data,
|
39
|
-
:url => "/assets/video_files/:id/:filename",
|
40
|
-
:path => ":rails_root/public/assets/video_files/:id/:filename"
|
41
|
-
|
42
|
-
validates_attachment_presence :data
|
43
|
-
validates_attachment_size :data, :less_than => 200.megabytes
|
44
|
-
validates_attachment_content_type :data, :content_type => Falcon::CONTENT_TYPES
|
45
|
-
|
46
|
-
attr_accessible :data
|
47
|
-
|
48
|
-
falcon_encode 'media', :source => lambda { |file| file.data.path },
|
49
|
-
:profiles => ['web_mp4', 'web_ogg']
|
50
|
-
end
|
51
|
-
|
52
|
-
=== Metadata options
|
53
|
-
|
54
|
-
You can provide metadata options in your model, just set option "metadata":
|
55
|
-
|
56
|
-
class VideoFile
|
57
|
-
|
58
|
-
...
|
59
|
-
|
60
|
-
falcon_encode 'media', :source => lambda { |file| file.data.path },
|
61
|
-
:metadata => :media_metadata_options,
|
62
|
-
:profiles => ['web_mp4', 'web_ogg']
|
63
|
-
|
64
|
-
# A hash of metadatas for video:
|
65
|
-
#
|
66
|
-
# { :title => '', :author => '', :copyright => '',
|
67
|
-
# :comment => '', :description => '', :language => ''}
|
68
|
-
#
|
69
|
-
def media_metadata_options
|
70
|
-
{ :title => title, :author => user.name, :language => 'rus' }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
=== Background processing
|
75
|
-
|
76
|
-
Video encoding take a long time, so you must use background process. I recomended "delayed_job" or "resque".
|
77
|
-
To send encoding in background, just set option method "encode":
|
78
|
-
|
79
|
-
Resque example:
|
80
|
-
|
81
|
-
class VideoFile
|
82
|
-
|
83
|
-
...
|
84
|
-
|
85
|
-
falcon_encode 'media', :source => lambda { |file| file.data.path },
|
86
|
-
:metadata => :media_metadata_options,
|
87
|
-
:encode => lambda { |encoding| Resque.enqueue(JobEncoding, encoding.id) },
|
88
|
-
:profiles => ['web_mp4', 'web_ogg']
|
89
|
-
end
|
90
|
-
|
91
|
-
class JobEncoding
|
92
|
-
@queue = :encoding_queue
|
93
|
-
|
94
|
-
def self.perform(encoding_id)
|
95
|
-
encoding = Falcon::Encoding.find(encoding_id)
|
96
|
-
encoding.encode
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
For delayed_job:
|
101
|
-
|
102
|
-
class VideoFile
|
103
|
-
|
104
|
-
...
|
105
|
-
|
106
|
-
falcon_encode 'media', :source => lambda { |file| file.data.path },
|
107
|
-
:metadata => :media_metadata_options,
|
108
|
-
:encode => lambda { |encoding| encoding.delay.encode },
|
109
|
-
:profiles => ['web_mp4', 'web_ogg']
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
=== Callbacks
|
114
|
-
|
115
|
-
class VideoFile
|
116
|
-
|
117
|
-
...
|
118
|
-
|
119
|
-
falcon_encode 'media', :source => lambda { |file| file.data.path }
|
120
|
-
|
121
|
-
before_encode :method_name
|
122
|
-
before_media_encode :method_name
|
123
|
-
after_media_encode :method_name
|
124
|
-
after_encode :method_name
|
125
|
-
end
|
126
|
-
|
127
|
-
=== Screenshots
|
128
|
-
|
129
|
-
class VideoFile
|
130
|
-
has_many :screenshots, :dependent => :destroy
|
131
|
-
|
132
|
-
...
|
133
|
-
|
134
|
-
falcon_encode 'media', :source => lambda { |file| file.data.path }
|
135
|
-
|
136
|
-
after_media_encode :save_screenshots
|
137
|
-
|
138
|
-
def save_screenshots
|
139
|
-
media.screenshots do |filepath|
|
140
|
-
self.screenshots.create(:data => File.new(filepath))
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
=== Path and url
|
146
|
-
|
147
|
-
class VideoFile
|
148
|
-
falcon_encode 'media', :source => lambda { |file| file.data.path }
|
149
|
-
|
150
|
-
def media_url(profile_name)
|
151
|
-
media.url(profile_name)
|
152
|
-
end
|
153
|
-
|
154
|
-
def media_path(profile_name)
|
155
|
-
media.path(profile_name)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
Copyright © 2011 Aimbulance, released under the MIT license
|