This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
rcencode
executable file
·49 lines (42 loc) · 1.77 KB
/
rcencode
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
#!/usr/bin/env ruby
# Encodes an episode into various formats
# rcencode 123-some-episode.mov
require "fileutils"
class RailsCastsEncoder
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|
run "HandBrakeCLI -i '#{input}' -o '#{output}' -e x264 -b 300 -a 1 -E ca_aac -B 96 -6 mono -R Auto -D 0.0 -f mp4 -r 30 --strict-anamorphic -O -x 'cabac=0:ref=2:me=umh:bframes=0:weightp=0:subq=6:8x8dct=0:trellis=0'"
end
compress "m4v" do |input, output|
run "HandBrakeCLI -i '#{input}' -o '#{output}' -e x264 -q 20.0 -a 1 -E ca_aac -B 96 -6 mono -R Auto -D 0.0 -f mp4 -X 640 -O -x 'cabac=0:ref=2:me=umh:bframes=0:weightp=0:subq=6:8x8dct=0:trellis=0'"
end
compress "ogv" do |input, output|
run "ffmpeg2theora -v 8 -C 1 '#{input}' -o '#{output}'"
end
compress "webm" do |input, output|
run "ffmpeg -pass 1 -passlogfile '#{output}' -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i '#{input}' -vcodec libvpx -b 358400 -an -f webm -y NUL -threads 0"
run "ffmpeg -pass 2 -passlogfile '#{output}' -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i '#{input}' -vcodec libvpx -b 358400 -acodec libvorbis -ab 98304 -ac 1 -threads 0 -y '#{output}'"
FileUtils.rm("NUL")
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
RailsCastsEncoder.new($*.first).process