rff 0.2.10 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/audio_handler.rb +60 -33
- data/lib/video_handler.rb +57 -34
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b38d6c279ff97c480f6080521d8735c0b0b24920
|
4
|
+
data.tar.gz: a9a49f68e620cc49e1c7da8996b71cbba24147f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6211d05ec6fe7652482806841ab655705c05676b6e85a9a3cd40d44e3b633aec9489959ad1b4050e71f969739c8c2e5fb9c3cedfe33c4a6c733168ba16085ed2
|
7
|
+
data.tar.gz: 1447119e1dcc12b5b8d00fcbc4e8420d1c0bab41c0401dcd60f1a95b26ac985c16d7de0fb35ab849ebb5eaaf207427a3148a8ac6d5f670d037e2f0c680c8b00d
|
data/lib/audio_handler.rb
CHANGED
@@ -6,11 +6,11 @@ require 'fileutils'
|
|
6
6
|
# License:: Open Source Software
|
7
7
|
|
8
8
|
module RFF
|
9
|
-
|
9
|
+
|
10
10
|
# This class provides an "All audio to HTML5" conversion functionality. It takes every compatible with FFmpeg audio format and converts it to the three HTML5 audio formats - mp3, ogg and wav. If the input is already in one of these formats it is only converted to the two other formats and the original file is copied to the output directory, because it can be used as one of HTML5 sources.
|
11
|
-
|
11
|
+
|
12
12
|
class AudioHandler
|
13
|
-
|
13
|
+
|
14
14
|
# This constructor initializes the class with the following arguments:
|
15
15
|
# * _input_ <b>(required)</b> - the full path to the input file
|
16
16
|
# * <i>output_path</i> - a path to place the output file in. Defaults to nil, which means that the input' s directory path is used
|
@@ -18,7 +18,7 @@ module RFF
|
|
18
18
|
# * <i>recommended_audio_quality</i> - determines if recommended by FFmpeg community audio quality settings should be used. Defaults to true, which means audio conversion with good, recommended quality. Set to false if you are giving additional arguments that determine this quality.
|
19
19
|
# * <i>disable_subtitles_decoding</i> - in some formats subtitle decoding causes problems. This option disables this feature. Defaults to true to bypass problems by default.
|
20
20
|
# All of the arguments are passed on to underlying Processor instances. This method also determines input type, initializes processing percentage and creates needed Processor instances.
|
21
|
-
|
21
|
+
|
22
22
|
def initialize input, output_path=nil, custom_args=nil, recommended_audio_quality=true, disable_subtitles_decoding=true
|
23
23
|
@input = input
|
24
24
|
@input_type = File.basename(@input).split(".")[1]
|
@@ -39,10 +39,11 @@ module RFF
|
|
39
39
|
types.each do |type|
|
40
40
|
@processors << RFF::Processor.new(@input, type, @output_path, nil, @custom_args, recommended_audio_quality, disable_subtitles_decoding)
|
41
41
|
end
|
42
|
+
@handler_status = :ready
|
42
43
|
end
|
43
|
-
|
44
|
+
|
44
45
|
# This method fires all the Processor instances (conversion processes) in a separate thread at once. Then it counts the overall processing percentage from all the Processor instances as the process goes and sets it to 100% on finish
|
45
|
-
|
46
|
+
|
46
47
|
def fire_all
|
47
48
|
@processing_thread = Thread.new do |th|
|
48
49
|
begin
|
@@ -50,12 +51,13 @@ module RFF
|
|
50
51
|
proc.fire
|
51
52
|
#sleep(5)
|
52
53
|
end
|
54
|
+
@handler_status = :processing
|
53
55
|
status = :processing
|
54
56
|
while status != :done
|
55
57
|
donecount = 0
|
56
58
|
@processors.each do |proc|
|
57
59
|
#puts "Process status:" + proc.status.to_s
|
58
|
-
if proc.status == :completed || proc.status == :failed || proc.status == :aborted
|
60
|
+
if (!proc.command_exit_status.nil? && (proc.status == :completed || proc.status == :failed)) || proc.status == :aborted
|
59
61
|
donecount = donecount + 1
|
60
62
|
end
|
61
63
|
end
|
@@ -70,27 +72,38 @@ module RFF
|
|
70
72
|
end
|
71
73
|
@processing_percentage = (processing_percentage.to_f/@processors.count).to_i
|
72
74
|
end
|
75
|
+
@processors.each do |proc|
|
76
|
+
if proc.status != :completed
|
77
|
+
@handler_status = :failed
|
78
|
+
break
|
79
|
+
end
|
80
|
+
end
|
81
|
+
if @handler_status != :failed
|
82
|
+
@handler_status = :completed
|
83
|
+
end
|
73
84
|
@processing_percentage = 100
|
74
85
|
rescue => e
|
75
86
|
puts "Caught exception: " + e.to_s
|
76
87
|
puts "Backtrace:"
|
77
88
|
puts e.backtrace
|
78
|
-
|
89
|
+
status = :done
|
90
|
+
@handler_status = :failed
|
79
91
|
end
|
80
92
|
end
|
81
93
|
end
|
82
|
-
|
83
|
-
|
94
|
+
|
95
|
+
|
84
96
|
# This method fires all the Processor instances (conversion processes) in a separate thread sequentially - next Processor in the row is fired only after the Processor before finishes. It also counts the overall processing percentage from all the Processor instances as the process goes and sets it to 100% on finish
|
85
|
-
|
97
|
+
|
86
98
|
def fire_sequential
|
87
99
|
@processing_thread = Thread.new do |th|
|
88
100
|
begin
|
101
|
+
@handler_status = :processing
|
89
102
|
i = 0
|
90
103
|
@processors.each do |proc|
|
91
104
|
proc.fire
|
92
105
|
sleep(1)
|
93
|
-
while proc.status == :processing
|
106
|
+
while proc.command_exit_status.nil? || proc.status == :processing && proc.status != :aborted
|
94
107
|
if proc.processing_percentage != nil
|
95
108
|
@processing_percentage = (i*(100/@processors.count))+(proc.processing_percentage.to_f/@processors.count).to_i
|
96
109
|
end
|
@@ -98,27 +111,37 @@ module RFF
|
|
98
111
|
i = i+1
|
99
112
|
#sleep(5)
|
100
113
|
end
|
114
|
+
@processors.each do |proc|
|
115
|
+
if proc.status != :completed
|
116
|
+
@handler_status = :failed
|
117
|
+
break
|
118
|
+
end
|
119
|
+
end
|
120
|
+
if @handler_status != :failed
|
121
|
+
@handler_status = :completed
|
122
|
+
end
|
101
123
|
@processing_percentage = 100
|
102
124
|
rescue => e
|
103
125
|
puts "Caught exception: " + e.to_s
|
104
126
|
puts "Backtrace:"
|
105
127
|
puts e.backtrace
|
106
|
-
|
128
|
+
status = :done
|
129
|
+
@handler_status = :failed
|
107
130
|
end
|
108
131
|
end
|
109
132
|
end
|
110
|
-
|
133
|
+
|
111
134
|
# This method kills all the processes in Processor instances and its own processing thread
|
112
|
-
|
135
|
+
|
113
136
|
def killall
|
114
137
|
@processors.each do |proc|
|
115
138
|
proc.kill
|
116
139
|
end
|
117
140
|
@processing_thread.kill
|
118
141
|
end
|
119
|
-
|
142
|
+
|
120
143
|
# This method returns the "to MP3" Processor instance if it exists or nil otherwise
|
121
|
-
|
144
|
+
|
122
145
|
def mp3_processor
|
123
146
|
ret = nil
|
124
147
|
@processors.each do |proc|
|
@@ -128,9 +151,9 @@ module RFF
|
|
128
151
|
end
|
129
152
|
ret
|
130
153
|
end
|
131
|
-
|
154
|
+
|
132
155
|
# This method returns the "to OGG" Processor instance if it exists or nil otherwise
|
133
|
-
|
156
|
+
|
134
157
|
def ogg_processor
|
135
158
|
ret = nil
|
136
159
|
@processors.each do |proc|
|
@@ -140,9 +163,9 @@ module RFF
|
|
140
163
|
end
|
141
164
|
ret
|
142
165
|
end
|
143
|
-
|
166
|
+
|
144
167
|
# This method returns the "to WAV" Processor instance if it exists or nil otherwise
|
145
|
-
|
168
|
+
|
146
169
|
def wav_processor
|
147
170
|
ret = nil
|
148
171
|
@processors.each do |proc|
|
@@ -152,41 +175,45 @@ module RFF
|
|
152
175
|
end
|
153
176
|
ret
|
154
177
|
end
|
155
|
-
|
178
|
+
|
156
179
|
# This method returns full input path
|
157
|
-
|
180
|
+
|
158
181
|
def input
|
159
182
|
@input
|
160
183
|
end
|
161
|
-
|
184
|
+
|
162
185
|
# This method returns full output file name
|
163
|
-
|
186
|
+
|
164
187
|
def output_name
|
165
188
|
@output_name
|
166
189
|
end
|
167
|
-
|
190
|
+
|
168
191
|
# This method returns the path in which output file is saved
|
169
|
-
|
192
|
+
|
170
193
|
def output_path
|
171
194
|
@output_path
|
172
195
|
end
|
173
|
-
|
196
|
+
|
174
197
|
# This method returns custom arguments passed to FFmpeg
|
175
|
-
|
198
|
+
|
176
199
|
def custom_args
|
177
200
|
@custom_args
|
178
201
|
end
|
179
|
-
|
202
|
+
|
180
203
|
# This method returns percentage of process completion
|
181
|
-
|
204
|
+
|
182
205
|
def processing_percentage
|
183
206
|
@processing_percentage || 0
|
184
207
|
end
|
185
|
-
|
208
|
+
|
186
209
|
# This method returns percentage of process completion formatted for output
|
187
|
-
|
210
|
+
|
188
211
|
def format_processing_percentage
|
189
212
|
@processing_percentage.nil? ? "0%" : @processing_percentage.to_s + "%"
|
190
213
|
end
|
214
|
+
|
215
|
+
def handler_status
|
216
|
+
@handler_status
|
217
|
+
end
|
191
218
|
end
|
192
219
|
end
|
data/lib/video_handler.rb
CHANGED
@@ -2,11 +2,11 @@ require_relative 'processor'
|
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
module RFF
|
5
|
-
|
5
|
+
|
6
6
|
# This class provides an "All video to HTML5" conversion functionality. It takes every compatible with FFmpeg video format and converts it to the three HTML5 video formats - mp4, ogv and webm. If the input is already in one of these formats it is only converted to the two other formats and the original file is copied to the output directory, because it can be used as one of HTML5 sources.
|
7
|
-
|
7
|
+
|
8
8
|
class VideoHandler
|
9
|
-
|
9
|
+
|
10
10
|
# This constructor initializes the class with the following arguments:
|
11
11
|
# * _input_ <b>(required)</b> - the full path to the input file
|
12
12
|
# * <i>output_path</i> - a path to place the output file in. Defaults to nil, which means that the input' s directory path is used
|
@@ -15,7 +15,7 @@ module RFF
|
|
15
15
|
# * <i>recommended_audio_quality</i> - determines if recommended by FFmpeg community audio quality settings should be used. Defaults to true, which means audio conversion with good, recommended quality. Set to false if you are giving additional arguments that determine this quality.
|
16
16
|
# * <i>disable_subtitles_decoding</i> - in some formats subtitle decoding causes problems. This option disables this feature. Defaults to true to bypass problems by default.
|
17
17
|
# All of the arguments are passed on to underlying Processor instances. This method also determines input type, initializes processing percentage and creates needed Processor instances.
|
18
|
-
|
18
|
+
|
19
19
|
def initialize input, output_path=nil, quality="5000k", custom_args=nil, recommended_audio_quality=true, disable_subtitles_decoding=true
|
20
20
|
@input = input
|
21
21
|
@input_type = File.basename(@input).split(".")[1]
|
@@ -37,10 +37,11 @@ module RFF
|
|
37
37
|
types.each do |type|
|
38
38
|
@processors << RFF::Processor.new(@input, type, @output_path, @quality, @custom_args, recommended_audio_quality, disable_subtitles_decoding)
|
39
39
|
end
|
40
|
+
@handler_status = :ready
|
40
41
|
end
|
41
|
-
|
42
|
+
|
42
43
|
# This method fires all the Processor instances (conversion processes) in a separate thread at once. Then it counts the overall processing percentage from all the Processor instances as the process goes and sets it to 100% on finish
|
43
|
-
|
44
|
+
|
44
45
|
def fire_all
|
45
46
|
@processing_thread = Thread.new do |th|
|
46
47
|
begin
|
@@ -48,12 +49,13 @@ module RFF
|
|
48
49
|
proc.fire
|
49
50
|
#sleep(5)
|
50
51
|
end
|
52
|
+
@handler_status = :processing
|
51
53
|
status = :processing
|
52
54
|
while status != :done
|
53
55
|
donecount = 0
|
54
56
|
@processors.each do |proc|
|
55
57
|
#puts "Process status:" + proc.status.to_s
|
56
|
-
if proc.status == :completed || proc.status == :failed || proc.status == :aborted
|
58
|
+
if (!proc.command_exit_status.nil? && (proc.status == :completed || proc.status == :failed)) || proc.status == :aborted
|
57
59
|
donecount = donecount + 1
|
58
60
|
end
|
59
61
|
end
|
@@ -68,26 +70,37 @@ module RFF
|
|
68
70
|
end
|
69
71
|
@processing_percentage = (processing_percentage.to_f/@processors.count).to_i
|
70
72
|
end
|
73
|
+
@processors.each do |proc|
|
74
|
+
if proc.status != :completed
|
75
|
+
@handler_status = :failed
|
76
|
+
break
|
77
|
+
end
|
78
|
+
end
|
79
|
+
if @handler_status != :failed
|
80
|
+
@handler_status = :completed
|
81
|
+
end
|
71
82
|
@processing_percentage = 100
|
72
83
|
rescue => e
|
73
84
|
puts "Caught exception: " + e.to_s
|
74
85
|
puts "Backtrace:"
|
75
86
|
puts e.backtrace
|
76
|
-
|
87
|
+
status = :done
|
88
|
+
@handler_status = :failed
|
77
89
|
end
|
78
90
|
end
|
79
91
|
end
|
80
|
-
|
92
|
+
|
81
93
|
# This method fires all the Processor instances (conversion processes) in a separate thread sequentially - next Processor in the row is fired only after the Processor before finishes. It also counts the overall processing percentage from all the Processor instances as the process goes and sets it to 100% on finish
|
82
|
-
|
94
|
+
|
83
95
|
def fire_sequential
|
84
96
|
@processing_thread = Thread.new do |th|
|
85
97
|
begin
|
86
98
|
i = 0
|
99
|
+
@handler_status = :processing
|
87
100
|
@processors.each do |proc|
|
88
101
|
proc.fire
|
89
102
|
sleep(1)
|
90
|
-
while proc.status == :processing
|
103
|
+
while proc.command_exit_status.nil? || proc.status == :processing && proc.status != :aborted
|
91
104
|
if proc.processing_percentage != nil
|
92
105
|
@processing_percentage = (i*(100/@processors.count))+(proc.processing_percentage.to_f/@processors.count).to_i
|
93
106
|
end
|
@@ -95,27 +108,37 @@ module RFF
|
|
95
108
|
i = i+1
|
96
109
|
#sleep(5)
|
97
110
|
end
|
111
|
+
@processors.each do |proc|
|
112
|
+
if proc.status != :completed
|
113
|
+
@handler_status = :failed
|
114
|
+
break
|
115
|
+
end
|
116
|
+
end
|
117
|
+
if @handler_status != :failed
|
118
|
+
@handler_status = :completed
|
119
|
+
end
|
98
120
|
@processing_percentage = 100
|
99
121
|
rescue => e
|
100
122
|
puts "Caught exception: " + e.to_s
|
101
123
|
puts "Backtrace:"
|
102
124
|
puts e.backtrace
|
103
|
-
|
125
|
+
status = :done
|
126
|
+
@handler_status = :failed
|
104
127
|
end
|
105
128
|
end
|
106
129
|
end
|
107
|
-
|
130
|
+
|
108
131
|
# This method kills all the processes in Processor instances and its own processing thread
|
109
|
-
|
132
|
+
|
110
133
|
def killall
|
111
134
|
@processors.each do |proc|
|
112
135
|
proc.kill
|
113
136
|
end
|
114
137
|
@processing_thread.kill
|
115
138
|
end
|
116
|
-
|
139
|
+
|
117
140
|
# This method returns the "to MP4" Processor instance if it exists or nil otherwise
|
118
|
-
|
141
|
+
|
119
142
|
def mp4_processor
|
120
143
|
ret = nil
|
121
144
|
@processors.each do |proc|
|
@@ -125,9 +148,9 @@ module RFF
|
|
125
148
|
end
|
126
149
|
ret
|
127
150
|
end
|
128
|
-
|
151
|
+
|
129
152
|
# This method returns the "to OGV" Processor instance if it exists or nil otherwise
|
130
|
-
|
153
|
+
|
131
154
|
def ogv_processor
|
132
155
|
ret = nil
|
133
156
|
@processors.each do |proc|
|
@@ -137,9 +160,9 @@ module RFF
|
|
137
160
|
end
|
138
161
|
ret
|
139
162
|
end
|
140
|
-
|
163
|
+
|
141
164
|
# This method returns the "to WEBM" Processor instance if it exists or nil otherwise
|
142
|
-
|
165
|
+
|
143
166
|
def webm_processor
|
144
167
|
ret = nil
|
145
168
|
@processors.each do |proc|
|
@@ -149,45 +172,45 @@ module RFF
|
|
149
172
|
end
|
150
173
|
ret
|
151
174
|
end
|
152
|
-
|
175
|
+
|
153
176
|
# This method returns full input path
|
154
|
-
|
177
|
+
|
155
178
|
def input
|
156
179
|
@input
|
157
180
|
end
|
158
|
-
|
181
|
+
|
159
182
|
# This method returns full output file name
|
160
|
-
|
183
|
+
|
161
184
|
def output_name
|
162
185
|
@output_name
|
163
186
|
end
|
164
|
-
|
187
|
+
|
165
188
|
# This method returns the path in which output file is saved
|
166
|
-
|
189
|
+
|
167
190
|
def output_path
|
168
191
|
@output_path
|
169
192
|
end
|
170
|
-
|
193
|
+
|
171
194
|
# This method returns used video quality
|
172
|
-
|
195
|
+
|
173
196
|
def quality
|
174
197
|
@quality
|
175
198
|
end
|
176
|
-
|
199
|
+
|
177
200
|
# This method returns custom arguments passed to FFmpeg
|
178
|
-
|
201
|
+
|
179
202
|
def custom_args
|
180
203
|
@custom_args
|
181
204
|
end
|
182
|
-
|
205
|
+
|
183
206
|
# This method returns percentage of process completion
|
184
|
-
|
207
|
+
|
185
208
|
def processing_percentage
|
186
209
|
@processing_percentage || 0
|
187
210
|
end
|
188
|
-
|
211
|
+
|
189
212
|
# This method returns percentage of process completion formatted for output
|
190
|
-
|
213
|
+
|
191
214
|
def format_processing_percentage
|
192
215
|
@processing_percentage.nil? ? "0%" : @processing_percentage.to_s + "%"
|
193
216
|
end
|