-
Notifications
You must be signed in to change notification settings - Fork 2
/
transcode
executable file
·95 lines (85 loc) · 2.75 KB
/
transcode
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env ruby
# Encodes an episode into various formats
# transcode some-video.mov
#
# References:
# https://raw.github.com/ryanb/railscasts-scripts/master/bin/rcencode
# http://diveintohtml5.info/video.html
# https://trac.handbrake.fr/wiki/BuiltInPresets
require "fileutils"
class Transcoder
def initialize(path)
@source = File.expand_path(path)
@name = File.basename(@source, ".*")
@out_dir = "#{File.dirname(@source)}/video"
end
def process
FileUtils.mkdir_p(@out_dir)
compress "mp4" do |input, output|
# Final line of parameters is 'iPhone & iPod Touch' preset without '-X 480'.
run %W[HandBrakeCLI --input '#{input}'
--output '#{output}'
--width 640
--vb 600
--two-pass
--turbo
--optimize
-e x264 -q 20.0 -a 1 -E faac -B 128 -6 dpl2 -R Auto -D 0.0 -f mp4 -m -x cabac=0:ref=2:me=umh:bframes=0:weightp=0:subme=6:8x8dct=0:trellis=0].join(' ')
end
compress "ogv" do |input, output|
run %W[ffmpeg2theora --videoquality 8
--audioquality 8
'#{input}'
--output '#{output}'].join(' ')
end
compress "webm" do |input, output|
run %W[ffmpeg -pass 1
-passlogfile '#{output}'
-threads 0
-keyint_min 0
-g 250
-skip_threshold 0
-qmin 1
-qmax 51
-i '#{input}'
-vcodec libvpx
-b:v 614400
-s 640x360
-aspect 16:9
-an
-f webm
-y
/dev/null].join(' ')
run %W[ffmpeg -pass 2
-passlogfile '#{output}'
-threads 0
-keyint_min 0
-g 250
-skip_threshold 0
-qmin 1
-qmax 51
-i '#{input}'
-vcodec libvpx
-b:v 614400
-s 640x360
-aspect 16:9
-acodec libvorbis
-y
'#{output}'].join(' ')
FileUtils.rm("#{output}-0.log")
end
end
def run(command)
puts "Running: #{command}"
system(command)
end
def compress(ext)
out_file = "#{@out_dir}/#{@name}.#{ext}"
if File.exist? out_file
puts "Skipping #{@name} because compressed file already exists."
else
yield(@source, out_file)
end
end
end
Transcoder.new($*.first).process