libis-format 0.9.41 → 0.9.44
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.
- checksums.yaml +4 -4
- data/README.md +365 -0
- data/bin/droid +1 -1
- data/bin/fido +1 -1
- data/bin/pdf_copy +1 -1
- data/lib/libis/format/config.rb +1 -0
- data/lib/libis/format/converter/audio_converter.rb +1 -1
- data/lib/libis/format/converter/base.rb +2 -1
- data/lib/libis/format/converter/office_converter.rb +2 -2
- data/lib/libis/format/converter/pdf_converter.rb +6 -6
- data/lib/libis/format/converter/video_converter.rb +96 -2
- data/lib/libis/format/identifier.rb +12 -12
- data/lib/libis/format/tool/droid.rb +108 -0
- data/lib/libis/format/tool/extension_identification.rb +58 -0
- data/lib/libis/format/tool/ffmpeg.rb +43 -0
- data/lib/libis/format/tool/fido.rb +91 -0
- data/lib/libis/format/tool/file_tool.rb +78 -0
- data/lib/libis/format/tool/identification_tool.rb +175 -0
- data/lib/libis/format/tool/office_to_pdf.rb +54 -0
- data/lib/libis/format/tool/pdf_copy.rb +42 -0
- data/lib/libis/format/tool/pdf_merge.rb +43 -0
- data/lib/libis/format/tool/pdf_optimizer.rb +38 -0
- data/lib/libis/format/tool/pdf_split.rb +41 -0
- data/lib/libis/format/tool/pdf_to_pdfa.rb +78 -0
- data/lib/libis/format/tool/pdfa_validator.rb +63 -0
- data/lib/libis/format/tool.rb +23 -0
- data/lib/libis/format/version.rb +1 -1
- data/lib/libis/format.rb +1 -15
- data/libis-format.gemspec +1 -2
- data/spec/converter_audio_spec.rb +66 -0
- data/spec/converter_image_spec.rb +166 -0
- data/spec/converter_office_spec.rb +84 -0
- data/spec/converter_pdf_spec.rb +30 -0
- data/spec/converter_repository_spec.rb +91 -0
- data/spec/converter_video_spec.rb +97 -0
- data/spec/data/video/copyright.png +0 -0
- data/spec/identifier_spec.rb +3 -15
- metadata +32 -33
- data/lib/libis/format/droid.rb +0 -106
- data/lib/libis/format/extension_identification.rb +0 -55
- data/lib/libis/format/ffmpeg.rb +0 -41
- data/lib/libis/format/fido.rb +0 -89
- data/lib/libis/format/file_tool.rb +0 -76
- data/lib/libis/format/identification_tool.rb +0 -174
- data/lib/libis/format/office_to_pdf.rb +0 -52
- data/lib/libis/format/pdf_copy.rb +0 -40
- data/lib/libis/format/pdf_merge.rb +0 -41
- data/lib/libis/format/pdf_optimizer.rb +0 -36
- data/lib/libis/format/pdf_split.rb +0 -39
- data/lib/libis/format/pdf_to_pdfa.rb +0 -74
- data/lib/libis/format/pdfa_validator.rb +0 -61
- data/spec/converter_spec.rb +0 -433
data/spec/converter_spec.rb
DELETED
@@ -1,433 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
require 'libis/format/converter/image_converter'
|
5
|
-
require 'libis/format/converter/pdf_converter'
|
6
|
-
require 'libis/format/converter/office_converter'
|
7
|
-
require 'libis/format/converter/jp2_converter'
|
8
|
-
require 'libis/format/converter/audio_converter'
|
9
|
-
require 'libis/format/converter/video_converter'
|
10
|
-
|
11
|
-
describe 'Converters' do
|
12
|
-
|
13
|
-
let(:repository) {Libis::Format::Converter::Repository}
|
14
|
-
let(:file_dir) {File.dirname(__FILE__)}
|
15
|
-
|
16
|
-
before(:all) {
|
17
|
-
Libis::Tools::Config.logger.level = 'off'
|
18
|
-
}
|
19
|
-
|
20
|
-
context 'Repository' do
|
21
|
-
|
22
|
-
it 'loads all converters' do
|
23
|
-
expect(repository.get_converters.size).to eq 6
|
24
|
-
# noinspection RubyResolve
|
25
|
-
expect(repository.get_converters.map(&:to_s)).to include 'Libis::Format::Converter::ImageConverter'
|
26
|
-
# noinspection RubyResolve
|
27
|
-
expect(repository.get_converters.map(&:to_s)).to include 'Libis::Format::Converter::OfficeConverter'
|
28
|
-
# noinspection RubyResolve
|
29
|
-
expect(repository.get_converters.map(&:to_s)).to include 'Libis::Format::Converter::PdfConverter'
|
30
|
-
# noinspection RubyResolve
|
31
|
-
expect(repository.get_converters.map(&:to_s)).to include 'Libis::Format::Converter::Jp2Converter'
|
32
|
-
# noinspection RubyResolve
|
33
|
-
expect(repository.get_converters.map(&:to_s)).to include 'Libis::Format::Converter::AudioConverter'
|
34
|
-
# noinspection RubyResolve
|
35
|
-
expect(repository.get_converters.map(&:to_s)).to include 'Libis::Format::Converter::VideoConverter'
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'creates simple converter chain' do
|
39
|
-
chain = repository.get_converter_chain(:TIFF, :PDF)
|
40
|
-
expect(chain).to_not be nil
|
41
|
-
expect(chain.to_array.size).to eq 1
|
42
|
-
expect(chain.to_array).to match [{converter: Libis::Format::Converter::ImageConverter, input: :TIFF, output: :PDF}]
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'creates complex chain' do
|
46
|
-
chain = repository.get_converter_chain(:TIFF, :PDFA)
|
47
|
-
expect(chain).to_not be nil
|
48
|
-
expect(chain.to_array.size).to eq 2
|
49
|
-
expect(chain.to_array).to match [
|
50
|
-
{converter: Libis::Format::Converter::ImageConverter, input: :TIFF, output: :PDF},
|
51
|
-
{converter: Libis::Format::Converter::PdfConverter, input: :PDF, output: :PDFA},
|
52
|
-
]
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'creates converter chain with options' do
|
56
|
-
chain = repository.get_converter_chain(:TIFF, :PDF, {watermark: {}})
|
57
|
-
expect(chain).to_not be nil
|
58
|
-
expect(chain.to_array.size).to eq 1
|
59
|
-
expect(chain.to_array).to match [
|
60
|
-
{converter: Libis::Format::Converter::ImageConverter, input: :TIFF, output: :PDF, operations: [{method: :watermark, argument: {}}]}
|
61
|
-
]
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'perfers operations to the end of the chain' do
|
65
|
-
chain = repository.get_converter_chain(:TIFF, :PDFA, {watermark: {}})
|
66
|
-
expect(chain).to_not be nil
|
67
|
-
expect(chain.to_array.size).to eq 2
|
68
|
-
expect(chain.to_array).to match [
|
69
|
-
{converter: Libis::Format::Converter::ImageConverter, input: :TIFF, output: :PDF},
|
70
|
-
{converter: Libis::Format::Converter::PdfConverter, input: :PDF, output: :PDFA, operations: [{method: :watermark, argument: {}}]}
|
71
|
-
]
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'create chain for TIFF to JP2' do
|
75
|
-
|
76
|
-
it 'without operators' do
|
77
|
-
chain = repository.get_converter_chain(:TIFF, :JP2)
|
78
|
-
expect(chain).to_not be nil
|
79
|
-
expect(chain.to_array.size).to eq 1
|
80
|
-
expect(chain.to_array).to match [
|
81
|
-
{converter: Libis::Format::Converter::ImageConverter, input: :TIFF, output: :JP2}
|
82
|
-
]
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'with force operator' do
|
86
|
-
chain = repository.get_converter_chain(:TIFF, :JP2, {lossless: true})
|
87
|
-
expect(chain).to_not be nil
|
88
|
-
expect(chain.to_array.size).to eq 1
|
89
|
-
expect(chain.to_array).to match [
|
90
|
-
{converter: Libis::Format::Converter::Jp2Converter, input: :TIFF, output: :JP2, operations: [{method: :lossless, argument: true}]}
|
91
|
-
]
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'Image Converter' do
|
99
|
-
|
100
|
-
let(:converter) {Libis::Format::Converter::ImageConverter.new}
|
101
|
-
let(:diff_file) {File.join('', 'tmp', 'diff.jpg')}
|
102
|
-
|
103
|
-
it 'converts TIFF to JPEG' do
|
104
|
-
src_file = File.join(file_dir, 'data', 'test.tif')
|
105
|
-
ref_file = File.join(file_dir, 'data', 'test.jpg')
|
106
|
-
tgt_file = File.join('', 'tmp', 'test.jpg')
|
107
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
108
|
-
converter.delete_date
|
109
|
-
result = converter.convert(src_file, tgt_file, :JPG)
|
110
|
-
expect(result).to eq tgt_file
|
111
|
-
compare = MiniMagick::Tool::Compare.new
|
112
|
-
compare << ref_file << tgt_file
|
113
|
-
compare.metric << 'MAE'
|
114
|
-
compare.fuzz << '1%'
|
115
|
-
compare << diff_file
|
116
|
-
compare.call {|_, _, status| expect(status).to be 0}
|
117
|
-
FileUtils.rm tgt_file, force: true
|
118
|
-
FileUtils.rm diff_file, force: true
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'converts TIFF to PNG' do
|
122
|
-
src_file = File.join(file_dir, 'data', 'test.tif')
|
123
|
-
ref_file = File.join(file_dir, 'data', 'test.png')
|
124
|
-
tgt_file = File.join('', 'tmp', 'test.png')
|
125
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
126
|
-
converter.delete_date
|
127
|
-
converter.page(0)
|
128
|
-
result = converter.convert(src_file, tgt_file, :PNG)
|
129
|
-
expect(result).to eq tgt_file
|
130
|
-
compare = MiniMagick::Tool::Compare.new
|
131
|
-
compare << ref_file << tgt_file
|
132
|
-
compare.metric << 'MAE'
|
133
|
-
compare << diff_file
|
134
|
-
compare.call {|_, _, status| expect(status).to be 0}
|
135
|
-
FileUtils.rm tgt_file, force: true
|
136
|
-
FileUtils.rm diff_file, force: true
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'converts PDF to TIFF' do
|
140
|
-
src_file = File.join(file_dir, 'data', 'test.pdf')
|
141
|
-
ref_file = File.join(file_dir, 'data', 'test.pdf.tif')
|
142
|
-
tgt_file = File.join('', 'tmp', 'test.pdf.tif')
|
143
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
144
|
-
converter.delete_date
|
145
|
-
result = converter.convert(src_file, tgt_file, :TIFF)
|
146
|
-
expect(result).to eq tgt_file
|
147
|
-
compare = MiniMagick::Tool::Compare.new
|
148
|
-
compare << ref_file << tgt_file
|
149
|
-
compare.metric << 'AE'
|
150
|
-
compare.fuzz << '100%'
|
151
|
-
compare << diff_file
|
152
|
-
compare.call {|_, _, status| expect(status).to be 0}
|
153
|
-
FileUtils.rm tgt_file, force: true
|
154
|
-
FileUtils.rm diff_file, force: true
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'converts TIFF to PNG with many options' do
|
158
|
-
src_file = File.join(file_dir, 'data', 'test.tif')
|
159
|
-
ref_file = File.join(file_dir, 'data', 'test-options.png')
|
160
|
-
tgt_file = File.join('', 'tmp', 'test-options.png')
|
161
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
162
|
-
converter.watermark(text: 'RSPEC', size: 5, opacity: 0.1, rotation: 15, gap: 0.5, composition: 'modulate')
|
163
|
-
converter.delete_date
|
164
|
-
result = converter.convert(src_file, tgt_file, :PNG, options: {scale: '150%'})
|
165
|
-
expect(result).to eq tgt_file
|
166
|
-
compare = MiniMagick::Tool::Compare.new
|
167
|
-
compare << ref_file << tgt_file
|
168
|
-
compare.metric << 'AE'
|
169
|
-
compare.fuzz << '100%'
|
170
|
-
compare << diff_file
|
171
|
-
compare.call do |_stdin, _stdout, status|
|
172
|
-
expect(status).to be 0
|
173
|
-
end
|
174
|
-
FileUtils.rm tgt_file, force: true
|
175
|
-
FileUtils.rm diff_file, force: true
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'converts only first page of multipage TIFF to JP2' do
|
179
|
-
src_file = File.join(file_dir, 'data', 'multipage.tif')
|
180
|
-
ref_file = File.join(file_dir, 'data', 'multipage.tif.jp2')
|
181
|
-
tgt_file = File.join('', 'tmp', 'test.jp2')
|
182
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
183
|
-
converter.delete_date
|
184
|
-
converter.quiet(true)
|
185
|
-
converter.page(0)
|
186
|
-
result = converter.convert(src_file, tgt_file, :JP2)
|
187
|
-
expect(result).to eq tgt_file
|
188
|
-
expect(File.exist?(tgt_file)).to be_truthy
|
189
|
-
compare = MiniMagick::Tool::Compare.new
|
190
|
-
compare << ref_file << tgt_file
|
191
|
-
compare.metric << 'MAE'
|
192
|
-
compare.fuzz << '10%'
|
193
|
-
compare << diff_file
|
194
|
-
compare.call {|_, _, status| expect(status).to be 0}
|
195
|
-
FileUtils.rm tgt_file, force: true
|
196
|
-
FileUtils.rm diff_file, force: true
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'converts TIFF to JP2' do
|
200
|
-
src_file = File.join(file_dir, 'data', 'test.tif')
|
201
|
-
tgt_file = File.join('', 'tmp', 'test.jp2')
|
202
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
203
|
-
converter.delete_date
|
204
|
-
result = converter.convert(src_file, tgt_file, :JP2)
|
205
|
-
expect(result).to eq tgt_file
|
206
|
-
expect(File.exist?(tgt_file)).to be_truthy
|
207
|
-
FileUtils.rm tgt_file, force: true
|
208
|
-
end
|
209
|
-
|
210
|
-
|
211
|
-
end
|
212
|
-
|
213
|
-
context 'JP2 Converter', if: File.exists?(Libis::Format::Config[:j2kdriver]) do
|
214
|
-
|
215
|
-
let(:converter) {Libis::Format::Converter::Jp2Converter.new}
|
216
|
-
let(:diff_file) {File.join('', 'tmp', 'diff.jpg')}
|
217
|
-
|
218
|
-
it 'converts TIFF to JP2' do
|
219
|
-
src_file = File.join(file_dir, 'data', 'test.tif')
|
220
|
-
tgt_file = File.join('', 'tmp', 'test.jp2')
|
221
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
222
|
-
result = converter.convert(src_file, tgt_file, :JP2)
|
223
|
-
expect(result).to eq tgt_file
|
224
|
-
expect(File.exist?(tgt_file)).to be_truthy
|
225
|
-
FileUtils.rm tgt_file, force: true
|
226
|
-
end
|
227
|
-
|
228
|
-
it 'converts only first page of multipage TIFF to JP2' do
|
229
|
-
src_file = File.join(file_dir, 'data', 'multipage.tif')
|
230
|
-
ref_file = File.join(file_dir, 'data', 'multipage.tif.jp2')
|
231
|
-
tgt_file = File.join('', 'tmp', 'test.jp2')
|
232
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
233
|
-
result = converter.convert(src_file, tgt_file, :JP2)
|
234
|
-
expect(result).to eq tgt_file
|
235
|
-
expect(File.exist?(tgt_file)).to be_truthy
|
236
|
-
compare = MiniMagick::Tool::Compare.new
|
237
|
-
compare << ref_file << tgt_file
|
238
|
-
compare.metric << 'MAE'
|
239
|
-
compare.fuzz << '10%'
|
240
|
-
compare << diff_file
|
241
|
-
compare.call {|_, _, status| expect(status).to be 0}
|
242
|
-
FileUtils.rm tgt_file, force: true
|
243
|
-
FileUtils.rm diff_file, force: true
|
244
|
-
end
|
245
|
-
|
246
|
-
end
|
247
|
-
|
248
|
-
context 'Pdf Converter', if: File.exists?(Libis::Format::Config[:ghostscript_path]) do
|
249
|
-
|
250
|
-
let(:converter) {Libis::Format::Converter::PdfConverter.new}
|
251
|
-
|
252
|
-
it 'converts PDF to PDF/A' do
|
253
|
-
src_file = File.join(file_dir, 'data', 'test.pdf')
|
254
|
-
tgt_file = File.join('', 'tmp', 'test_pdfa.pdf')
|
255
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
256
|
-
result = converter.convert(src_file, tgt_file, :PDFA)
|
257
|
-
expect(result).to eq tgt_file
|
258
|
-
FileUtils.rm tgt_file, force: true
|
259
|
-
end
|
260
|
-
|
261
|
-
end
|
262
|
-
|
263
|
-
context 'Office Converter' do
|
264
|
-
|
265
|
-
let(:converter) {Libis::Format::Converter::OfficeConverter.new}
|
266
|
-
|
267
|
-
it 'converts Word document to PDF' do
|
268
|
-
src_file = File.join(file_dir, 'data', 'test.doc')
|
269
|
-
tgt_file = File.join(file_dir, 'work', 'test_doc.pdf')
|
270
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
271
|
-
result = converter.convert(src_file, tgt_file, :PDF)
|
272
|
-
expect(result).to eq tgt_file
|
273
|
-
FileUtils.rm tgt_file, force: true
|
274
|
-
end
|
275
|
-
|
276
|
-
it 'converts Word 2010 document to PDF' do
|
277
|
-
src_file = File.join(file_dir, 'data', 'test.docx')
|
278
|
-
tgt_file = File.join(file_dir, 'work', 'test_docx.pdf')
|
279
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
280
|
-
result = converter.convert(src_file, tgt_file, :PDF)
|
281
|
-
expect(result).to eq tgt_file
|
282
|
-
FileUtils.rm tgt_file, force: true
|
283
|
-
end
|
284
|
-
|
285
|
-
it 'converts OpenOffice document to PDF' do
|
286
|
-
src_file = File.join(file_dir, 'data', 'test.odt')
|
287
|
-
tgt_file = File.join(file_dir, 'work', 'test_odt.pdf')
|
288
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
289
|
-
result = converter.convert(src_file, tgt_file, :PDF)
|
290
|
-
expect(result).to eq tgt_file
|
291
|
-
FileUtils.rm tgt_file, force: true
|
292
|
-
end
|
293
|
-
|
294
|
-
it 'converts RTF document to PDF' do
|
295
|
-
src_file = File.join(file_dir, 'data', 'test.rtf')
|
296
|
-
tgt_file = File.join(file_dir, 'work', 'test_rtf.pdf')
|
297
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
298
|
-
result = converter.convert(src_file, tgt_file, :PDF)
|
299
|
-
expect(result).to eq tgt_file
|
300
|
-
FileUtils.rm tgt_file, force: true
|
301
|
-
end
|
302
|
-
|
303
|
-
it 'converts TXT document to PDF' do
|
304
|
-
src_file = File.join(file_dir, 'data', 'test.txt')
|
305
|
-
tgt_file = File.join(file_dir, 'work', 'test_txt.pdf')
|
306
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
307
|
-
result = converter.convert(src_file, tgt_file, :PDF)
|
308
|
-
expect(result).to eq tgt_file
|
309
|
-
FileUtils.rm tgt_file, force: true
|
310
|
-
end
|
311
|
-
|
312
|
-
it 'converts Excel to PDF' do
|
313
|
-
src_file = File.join(file_dir, 'data', 'test.xls')
|
314
|
-
tgt_file = File.join(file_dir, 'work', 'test_xls.pdf')
|
315
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
316
|
-
result = converter.convert(src_file, tgt_file, :PDF)
|
317
|
-
expect(result).to eq tgt_file
|
318
|
-
FileUtils.rm tgt_file, force: true
|
319
|
-
end
|
320
|
-
|
321
|
-
it 'converts Excel 2011 to PDF' do
|
322
|
-
src_file = File.join(file_dir, 'data', 'test.xlsx')
|
323
|
-
tgt_file = File.join(file_dir, 'work', 'test_xlsx.pdf')
|
324
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
325
|
-
result = converter.convert(src_file, tgt_file, :PDF)
|
326
|
-
expect(result).to eq tgt_file
|
327
|
-
FileUtils.rm tgt_file, force: true
|
328
|
-
end
|
329
|
-
|
330
|
-
end
|
331
|
-
|
332
|
-
context 'Audio Converter' do
|
333
|
-
|
334
|
-
let(:converter) {Libis::Format::Converter::AudioConverter.new}
|
335
|
-
extensions = %w'aac aiff au flac m4a mka mp3 ra voc wav wma'
|
336
|
-
confidence = {
|
337
|
-
aac: 0.86,
|
338
|
-
aiff: 0.99,
|
339
|
-
au: 0.99,
|
340
|
-
flac: 0.99,
|
341
|
-
m4a: 0.93,
|
342
|
-
mka: 0.94,
|
343
|
-
mp3: 0.95,
|
344
|
-
ra: 0.92,
|
345
|
-
voc: 0.99,
|
346
|
-
wav: 0.99,
|
347
|
-
wma: 0.9
|
348
|
-
}
|
349
|
-
targets = %w'mp3 flac wav'
|
350
|
-
sources = %w'carlin_disappointed greensleeves king_nonviolence top_gun_secret'
|
351
|
-
quality = {
|
352
|
-
carlin_disappointed: 1.0,
|
353
|
-
greensleeves: 0.95,
|
354
|
-
king_nonviolence: 1.0,
|
355
|
-
top_gun_secret: 0.95
|
356
|
-
}
|
357
|
-
|
358
|
-
let(:data_dir) {File.join(file_dir, 'data', 'audio')}
|
359
|
-
|
360
|
-
context 'converts' do
|
361
|
-
sources.each do |source|
|
362
|
-
extensions.each do |ext|
|
363
|
-
next unless (File.exists?(File.join(File.dirname(__FILE__), 'data', 'audio', "#{source}.#{ext}")))
|
364
|
-
(targets - [ext]).each do |tgt|
|
365
|
-
it "#{source} #{ext} to #{tgt}" do
|
366
|
-
src_file = File.join(data_dir, "#{source}.#{ext}")
|
367
|
-
ref_file = File.join(data_dir, "#{source}.#{tgt}")
|
368
|
-
tgt_file = File.join('', 'tmp', "test.#{source}.#{ext}.#{tgt}")
|
369
|
-
FileUtils.remove tgt_file, force: true
|
370
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
371
|
-
result = converter.convert(src_file, tgt_file, tgt.upcase.to_sym)
|
372
|
-
expect(result).to eq tgt_file
|
373
|
-
expect(result).to sound_like ref_file, confidence[ext.to_sym] * quality[source.to_sym], 11025, 1
|
374
|
-
FileUtils.remove tgt_file, force: true
|
375
|
-
end
|
376
|
-
end
|
377
|
-
end
|
378
|
-
end
|
379
|
-
end
|
380
|
-
|
381
|
-
end
|
382
|
-
|
383
|
-
context 'Video Converter' do
|
384
|
-
|
385
|
-
let(:converter) {Libis::Format::Converter::VideoConverter.new}
|
386
|
-
extensions = %w'3gp avi flv mkv mov mp4 mpg swf webm wmv'
|
387
|
-
targets = %w'avi flv mkv mov mp4 swf webm wmv gif'
|
388
|
-
# noinspection RubyLiteralArrayInspection
|
389
|
-
sources = [
|
390
|
-
'SampleVideo_176x144_2mb',
|
391
|
-
'SampleVideo_320x240_2mb',
|
392
|
-
'SampleVideo_360x240_2mb',
|
393
|
-
'SampleVideo_1080x720_2mb'
|
394
|
-
]
|
395
|
-
bad_converts = [
|
396
|
-
]
|
397
|
-
let(:data_dir) {File.join(file_dir, 'data', 'video')}
|
398
|
-
|
399
|
-
|
400
|
-
context 'converts' do
|
401
|
-
sources.each do |source|
|
402
|
-
context source do
|
403
|
-
extensions.each do |ext|
|
404
|
-
next unless (File.exists?(File.join(File.dirname(__FILE__), 'data', 'video', "#{source}.#{ext}")))
|
405
|
-
(targets - [ext]).each do |tgt|
|
406
|
-
next if bad_converts.include? [ext, tgt]
|
407
|
-
it "#{ext} to #{tgt}" do
|
408
|
-
src_file = File.join(data_dir, "#{source}.#{ext}")
|
409
|
-
tgt_file = File.join('', 'tmp', "test.#{source}.#{ext}.#{tgt}")
|
410
|
-
FileUtils.remove tgt_file, force: true
|
411
|
-
FileUtils.mkdir_p File.dirname(tgt_file)
|
412
|
-
converter.audio_channels(2) if %w'swf wmv'.include?(tgt)
|
413
|
-
# converter.constant_rate_factor(24) if %w'swf wmv'.include?(tgt)
|
414
|
-
converter.sampling_freq(44100) if tgt == 'swf'
|
415
|
-
if tgt == 'gif'
|
416
|
-
converter.start(1)
|
417
|
-
converter.duration(3)
|
418
|
-
converter.scale('100x100')
|
419
|
-
end
|
420
|
-
result = converter.convert(src_file, tgt_file, tgt.upcase.to_sym)
|
421
|
-
expect(result).to eq tgt_file
|
422
|
-
expect(File.size(result)).to be > 2000
|
423
|
-
FileUtils.remove tgt_file, force: true
|
424
|
-
end
|
425
|
-
end
|
426
|
-
end
|
427
|
-
end
|
428
|
-
end
|
429
|
-
end
|
430
|
-
|
431
|
-
end
|
432
|
-
|
433
|
-
end
|