-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompression_test.rb
More file actions
88 lines (69 loc) · 2.4 KB
/
compression_test.rb
File metadata and controls
88 lines (69 loc) · 2.4 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
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
# fix for annoying textmate issue when running from TM
$:.reject! { |e| e.include? 'TextMate' }
require 'rubygems'
require 'yaml'
require 'fileutils'
require 'activerecord'
require 'activesupport'
require 'benchmark'
require 'erb'
# my libs
require 'ffmpeg'
# TODO
# -split into CompressionTester and CompressionTest, like Migrator/Migration
class CompressionTest < ActiveRecord::Base
attr_accessible :label, :time, :size, :flags, :error
def self.run(label, input_path, output_dir, test_options)
initialize_db
FileUtils.mkdir_p(output_dir)
test_options.each do |test_option|
ct = CompressionTest.new
ct.label = label
ct.save
# setup file paths
output_path = "#{output_dir}/#{ct.filename}"
# special handling for multiple passes
time = Benchmark.realtime do
puts "FFMPEG: using options: #{test_option.inspect}"
Ffmpeg.run(input_path, output_path, {:r => 15}, test_option)
end
ct.error = "Could not find output file: #{output_path}" unless File.exists?(output_path)
ct.update_attributes!( :time => '%.2f' % time,
:size => '%.2f' % (File.size(output_path) / 1024.0 / 1024.0),
:flags => test_option)
end
# create html
# create_html(label, output_dir + '/side_by_side.html')
end
def self.initialize_db
# setup connection
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:dbfile => "db/compression_tests.sqlite"
)
# create tables if they don't exist
unless File.exists?('db/compression_tests.sqlite')
ActiveRecord::Schema.define do
create_table :compression_tests do |table|
table.column :time, :string
table.column :size, :string
table.column :flags, :string
table.column :error, :string
table.column :label, :string
end
end
end
end
def self.create_html(label, output_path)
# copy all source files over
FileUtils.cp(Dir['public/*'], File.dirname(output_path))
# generate html file
@@results = CompressionTest.find(:all, :conditions => ["label == ?", label])
rhtml = ERB.new( File.read('side_by_side.rhtml') )
File.open(output_path, 'w') {|f| f.write( rhtml.result(binding) ) }
end
def filename
"#{id}.mp4"
end
end