kelredd-pruview 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kelredd-pruview might be problematic. Click here for more details.
- data/lib/pruview/version.rb +1 -1
- data/lib/pruview/video.rb +24 -19
- metadata +3 -3
data/lib/pruview/version.rb
CHANGED
data/lib/pruview/video.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Pruview
|
2
2
|
|
3
3
|
class Video
|
4
|
-
|
4
|
+
|
5
5
|
# this class assumes you have 'ffmpeg' and 'flvtool2' installed and in your path
|
6
6
|
|
7
7
|
def initialize(source, target_dir, bitrate_mult = 1)
|
@@ -12,49 +12,54 @@ module Pruview
|
|
12
12
|
@target_dir = target_dir
|
13
13
|
@bitrate_multiplier = bitrate_mult
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def to_flv(name, width, height, scale_static = false)
|
17
17
|
target = to_base(name, width, height, '.flv', scale_static)
|
18
18
|
run("#{FLVTOOL} -U #{target}", "Unable to add meta-data for #{target}.")
|
19
19
|
return target
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def to_mov(name, width, height, scale_static = false)
|
23
23
|
target = to_base(name, width, height, '.mov', scale_static)
|
24
24
|
# TODO: run qt-faststart
|
25
25
|
return target
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
|
+
def info
|
29
|
+
yml_info_path = Tempfile.new("#{File.basename(@source)}.yml").path
|
30
|
+
self.get_info(yml_info_path)
|
31
|
+
end
|
32
|
+
|
28
33
|
protected
|
29
|
-
|
34
|
+
|
30
35
|
def to_base(name, width, height, extension, scale_static)
|
31
36
|
target = File.join(@target_dir, name.to_s + extension)
|
32
37
|
info_yml = File.join(@target_dir, name.to_s + '_info.yml')
|
33
38
|
run(build_command(@source, target, width, height, get_info(info_yml), scale_static), "Unable to convert #{@source} to #{target}.")
|
34
39
|
return target
|
35
40
|
end
|
36
|
-
|
41
|
+
|
37
42
|
def format_supported?(source)
|
38
43
|
file_ext = file_extension(source)
|
39
44
|
EXT.each { |extension| return true if file_ext == extension }
|
40
45
|
return false
|
41
46
|
end
|
42
|
-
|
47
|
+
|
43
48
|
def file_extension(source_file)
|
44
|
-
File.extname(source_file).downcase.chomp
|
49
|
+
File.extname(source_file).downcase.chomp
|
45
50
|
end
|
46
|
-
|
47
|
-
def get_info(
|
48
|
-
run("#{FFYML} #{@source} #{
|
49
|
-
YAML.load_file(
|
51
|
+
|
52
|
+
def get_info(yml_path)
|
53
|
+
run("#{FFYML} #{@source} #{yml_path}", "Unable to get video info")
|
54
|
+
YAML.load_file(yml_path)
|
50
55
|
end
|
51
|
-
|
56
|
+
|
52
57
|
def build_command(source, target, width, height, info, scale_static)
|
53
58
|
command = "#{FFMPEG} -i #{source}"
|
54
59
|
command += get_scale_command(info['width'], info['height'], width, height, scale_static)
|
55
60
|
scale_factor = get_scale_factor(info['width'], info['height'], width, height)
|
56
61
|
if file_extension(target) != '.flv' # use h264 codec with lower bitrate scaling factor
|
57
|
-
command += " -vcodec libx264"
|
62
|
+
command += " -vcodec libx264"
|
58
63
|
scale_factor /= 2.0
|
59
64
|
end
|
60
65
|
puts "scale factor: #{scale_factor.to_s}"
|
@@ -67,7 +72,7 @@ module Pruview
|
|
67
72
|
command += " -ar #{AUDIO_SAMPLING}"
|
68
73
|
command += " -y #{target}"
|
69
74
|
end
|
70
|
-
|
75
|
+
|
71
76
|
def get_scale_factor(source_width, source_height, scale_width, scale_height)
|
72
77
|
if source_width > source_height
|
73
78
|
return (scale_width.to_f / source_width.to_f)
|
@@ -75,7 +80,7 @@ module Pruview
|
|
75
80
|
return (scale_height.to_f / source_height.to_f)
|
76
81
|
end
|
77
82
|
end
|
78
|
-
|
83
|
+
|
79
84
|
def get_scale_command(source_width, source_height, scale_width, scale_height, static)
|
80
85
|
# this type of scaling assumes a static overall resolution with black padding added appropriately
|
81
86
|
# to keep the meaningful video area at the source aspect ratio
|
@@ -90,7 +95,7 @@ module Pruview
|
|
90
95
|
end
|
91
96
|
scale_command
|
92
97
|
end
|
93
|
-
|
98
|
+
|
94
99
|
def get_scaling_params(source_width, source_height, scale_width, scale_height)
|
95
100
|
params = {}
|
96
101
|
params[:left],params[:top],params[:right],params[:bottom] = 0,0,0,0
|
@@ -114,7 +119,7 @@ module Pruview
|
|
114
119
|
def run(command, error_message = "Unknown error.")
|
115
120
|
raise "Ffmpeg error: " + error_message + " - command: '#{command}'" if !system(command)
|
116
121
|
end
|
117
|
-
|
122
|
+
|
118
123
|
# Configurations
|
119
124
|
Video::FFYML = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'ffyml'))
|
120
125
|
Video::FFMPEG = 'ffmpeg'
|
@@ -122,7 +127,7 @@ module Pruview
|
|
122
127
|
Video::PAD_COLOR = "000000"
|
123
128
|
Video::AUDIO_BITRATE = '128' # kbps
|
124
129
|
Video::AUDIO_SAMPLING = '44100'
|
125
|
-
|
130
|
+
|
126
131
|
Video::EXT = ['.avi', '.flv', '.mov', '.mpg', '.mp4']
|
127
132
|
|
128
133
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 8
|
9
|
+
version: 0.1.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kelly Redding
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-07 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|