-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjob.rb
More file actions
39 lines (30 loc) · 1.08 KB
/
job.rb
File metadata and controls
39 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'sinatra'
require './config/initialize.rb'
class Job < Sinatra::Base
register Sinatra::ConfigFile
config_file 'config.yml'
@queue = :default
def self.perform(id, path, session)
s3 = AwsApi.new(settings.aws_key, settings.aws_secret)
redis = Redis.new
@video = Video.new(path, id)
mp4 = "#{@video.name}.mp4"
webm = "#{@video.name}.webm"
mp4_options = "-c:v libx264 -crf 19 -preset slow -c:a aac -strict experimental -b:a 192k -ac 2"
webm_options = "-acodec libvorbis -ac 2 -b:a 96k -ar 44100 -b:v 345k -s 640x360"
FFMPEG.new(@video, mp4, "mp4", mp4_options).run
key = "#{session}/#{mp4}"
s3.upload(key, "tmp/#{mp4}", 'mp4')
@video.mp4 = s3.get("#{session}/#{mp4}")
redis.set(@video.id, @video.to_json)
FFMPEG.new(@video, webm, 'webm', webm_options).run
key = "#{session}/#{webm}"
s3.upload(key, "tmp/#{webm}", 'webm')
@video.webm = s3.get("#{session}/#{webm}")
@video.progress = 100
redis.set(@video.id, @video.to_json)
# clean up files
File.delete("tmp/#{mp4}")
File.delete("tmp/#{webm}")
end
end