libis-format 0.9.38 → 0.9.39
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -13
- data/data/types.yml +85 -9
- data/lib/libis/format.rb +1 -0
- data/lib/libis/format/config.rb +2 -0
- data/lib/libis/format/converter/audio_converter.rb +181 -0
- data/lib/libis/format/converter/video_converter.rb +194 -0
- data/lib/libis/format/ffmpeg.rb +41 -0
- data/lib/libis/format/identifier.rb +1 -0
- data/lib/libis/format/pdf_to_pdfa.rb +1 -3
- data/lib/libis/format/pdfa_validator.rb +1 -1
- data/lib/libis/format/version.rb +1 -1
- data/libis-format.gemspec +1 -0
- data/spec/converter_spec.rb +116 -20
- data/spec/data/audio/carlin_disappointed.aac +0 -0
- data/spec/data/audio/carlin_disappointed.ac3 +0 -0
- data/spec/data/audio/carlin_disappointed.aiff +0 -0
- data/spec/data/audio/carlin_disappointed.au +0 -0
- data/spec/data/audio/carlin_disappointed.flac +0 -0
- data/spec/data/audio/carlin_disappointed.m4a +0 -0
- data/spec/data/audio/carlin_disappointed.mka +0 -0
- data/spec/data/audio/carlin_disappointed.mp3 +0 -0
- data/spec/data/audio/carlin_disappointed.ogg +0 -0
- data/spec/data/audio/carlin_disappointed.ra +0 -0
- data/spec/data/audio/carlin_disappointed.voc +0 -0
- data/spec/data/audio/carlin_disappointed.wav +0 -0
- data/spec/data/audio/carlin_disappointed.wma +0 -0
- data/spec/data/audio/greensleeves.aac +0 -0
- data/spec/data/audio/greensleeves.ac3 +0 -0
- data/spec/data/audio/greensleeves.aiff +0 -0
- data/spec/data/audio/greensleeves.au +0 -0
- data/spec/data/audio/greensleeves.flac +0 -0
- data/spec/data/audio/greensleeves.m4a +0 -0
- data/spec/data/audio/greensleeves.mka +0 -0
- data/spec/data/audio/greensleeves.mp3 +0 -0
- data/spec/data/audio/greensleeves.ogg +0 -0
- data/spec/data/audio/greensleeves.ra +0 -0
- data/spec/data/audio/greensleeves.voc +0 -0
- data/spec/data/audio/greensleeves.wav +0 -0
- data/spec/data/audio/greensleeves.wma +0 -0
- data/spec/data/audio/king_nonviolence.aac +0 -0
- data/spec/data/audio/king_nonviolence.ac3 +0 -0
- data/spec/data/audio/king_nonviolence.aiff +0 -0
- data/spec/data/audio/king_nonviolence.au +0 -0
- data/spec/data/audio/king_nonviolence.flac +0 -0
- data/spec/data/audio/king_nonviolence.m4a +0 -0
- data/spec/data/audio/king_nonviolence.mka +0 -0
- data/spec/data/audio/king_nonviolence.mp3 +0 -0
- data/spec/data/audio/king_nonviolence.ogg +0 -0
- data/spec/data/audio/king_nonviolence.ra +0 -0
- data/spec/data/audio/king_nonviolence.voc +0 -0
- data/spec/data/audio/king_nonviolence.wav +0 -0
- data/spec/data/audio/king_nonviolence.wma +0 -0
- data/spec/data/audio/top_gun_secret.aac +0 -0
- data/spec/data/audio/top_gun_secret.ac3 +0 -0
- data/spec/data/audio/top_gun_secret.aiff +0 -0
- data/spec/data/audio/top_gun_secret.au +0 -0
- data/spec/data/audio/top_gun_secret.flac +0 -0
- data/spec/data/audio/top_gun_secret.m4a +0 -0
- data/spec/data/audio/top_gun_secret.mka +0 -0
- data/spec/data/audio/top_gun_secret.mp3 +0 -0
- data/spec/data/audio/top_gun_secret.ogg +0 -0
- data/spec/data/audio/top_gun_secret.ra +0 -0
- data/spec/data/audio/top_gun_secret.voc +0 -0
- data/spec/data/audio/top_gun_secret.wav +0 -0
- data/spec/data/audio/top_gun_secret.wma +0 -0
- data/spec/data/video/SampleVideo_1080x720_2mb.flv +0 -0
- data/spec/data/video/SampleVideo_1080x720_2mb.mkv +0 -0
- data/spec/data/video/SampleVideo_1080x720_2mb.mp4 +0 -0
- data/spec/data/video/SampleVideo_176x144_2mb.3gp +0 -0
- data/spec/data/video/SampleVideo_320x240_2mb.3gp +0 -0
- data/spec/data/video/SampleVideo_360x240_2mb.flv +0 -0
- data/spec/data/video/SampleVideo_360x240_2mb.mkv +0 -0
- data/spec/data/video/SampleVideo_360x240_2mb.mp4 +0 -0
- data/spec/data/video/sample.avi +0 -0
- data/spec/data/video/sample.flv +0 -0
- data/spec/data/video/sample.mkv +0 -0
- data/spec/data/video/sample.mov +0 -0
- data/spec/data/video/sample.mp4 +0 -0
- data/spec/data/video/sample.mpg +0 -0
- data/spec/data/video/sample.swf +0 -0
- data/spec/data/video/sample.webm +0 -0
- data/spec/data/video/sample.wmv +0 -0
- data/spec/identifier_spec.rb +29 -39
- data/spec/spec_helper.rb +50 -1
- metadata +157 -2
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'libis/tools/extend/string'
|
2
|
+
require 'libis/tools/extend/empty'
|
3
|
+
require 'libis/tools/command'
|
4
|
+
|
5
|
+
require 'csv'
|
6
|
+
require 'libis/format/config'
|
7
|
+
|
8
|
+
module Libis
|
9
|
+
module Format
|
10
|
+
|
11
|
+
class FFMpeg
|
12
|
+
include Singleton
|
13
|
+
include ::Libis::Tools::Logger
|
14
|
+
|
15
|
+
def self.run(source, target, options = {})
|
16
|
+
self.instance.run source, target, options
|
17
|
+
end
|
18
|
+
|
19
|
+
def run(source, target, options = {})
|
20
|
+
opts = []
|
21
|
+
opts += options[:global] unless options[:global].empty?
|
22
|
+
opts += options[:input] unless options[:input].empty?
|
23
|
+
opts << '-i' << source
|
24
|
+
opts += options[:filter] unless options[:filter].empty?
|
25
|
+
opts += options[:output] unless options[:output].empty?
|
26
|
+
opts << target
|
27
|
+
result = Libis::Tools::Command.run(Libis::Format::Config[:ffmpeg_path], *opts)
|
28
|
+
|
29
|
+
unless result[:status] == 0
|
30
|
+
error "FFMpeg errors: #{(result[:err] + result[:out]).join("\n")}"
|
31
|
+
return false
|
32
|
+
end
|
33
|
+
warn "FFMpeg warnings: #{(result[:err] + result[:out]).join("\n")}" unless result[:err].empty?
|
34
|
+
|
35
|
+
result[:out]
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -22,12 +22,10 @@ module Libis
|
|
22
22
|
|
23
23
|
target ||= File.join(Dir.tmpdir, Dir::Tmpname.make_tmpname([File.basename(source, '.*'), '.pdf']))
|
24
24
|
|
25
|
-
data_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'data'))
|
26
|
-
|
27
25
|
icc_info = icc_options(options[:colorspace])
|
28
26
|
|
29
27
|
icc_file = File.join(Dir.tmpdir, "#{icc_info[:icc_name]}#{Random.new.bytes(12).unpack('H*').first}.icc")
|
30
|
-
FileUtils.cp(File.join(
|
28
|
+
FileUtils.cp(File.join(Libis::Format::DATA_DIR, "#{icc_info[:icc_name]}.icc"), icc_file)
|
31
29
|
|
32
30
|
def_filename = File.join(Dir.tmpdir, "PDFA_def_#{Random.new.bytes(12).unpack('H*').first}.ps")
|
33
31
|
File.open(def_filename, 'w') do |f|
|
@@ -41,7 +41,7 @@ module Libis
|
|
41
41
|
return false
|
42
42
|
end
|
43
43
|
else
|
44
|
-
jar = File.join(ROOT_DIR, 'tools', 'pdfbox', 'preflight-app-1.8.10.jar')
|
44
|
+
jar = File.join(Libis::Format::ROOT_DIR, 'tools', 'pdfbox', 'preflight-app-1.8.10.jar')
|
45
45
|
result = Libis::Tools::Command.run(
|
46
46
|
Libis::Format::Config[:java_path],
|
47
47
|
'-jar', jar,
|
data/lib/libis/format/version.rb
CHANGED
data/libis-format.gemspec
CHANGED
data/spec/converter_spec.rb
CHANGED
@@ -5,16 +5,8 @@ require 'libis/format/converter/image_converter'
|
|
5
5
|
require 'libis/format/converter/pdf_converter'
|
6
6
|
require 'libis/format/converter/office_converter'
|
7
7
|
require 'libis/format/converter/jp2_converter'
|
8
|
-
|
9
|
-
|
10
|
-
match do |actual_file_path|
|
11
|
-
expect(md5_hash(actual_file_path)).to eq md5_hash(exected_file_path)
|
12
|
-
end
|
13
|
-
|
14
|
-
def md5_hash(file_path)
|
15
|
-
Digest::MD5.hexdigest(File.read(file_path))
|
16
|
-
end
|
17
|
-
end
|
8
|
+
require 'libis/format/converter/audio_converter'
|
9
|
+
require 'libis/format/converter/video_converter'
|
18
10
|
|
19
11
|
describe 'Converters' do
|
20
12
|
|
@@ -22,15 +14,13 @@ describe 'Converters' do
|
|
22
14
|
let(:file_dir) {File.dirname(__FILE__)}
|
23
15
|
|
24
16
|
before(:all) {
|
25
|
-
Libis::Tools::Config.logger.level =
|
26
|
-
::Libis::Format::Config[:droid_path] = '/opt/droid/droid.sh'
|
27
|
-
::Libis::Format::Config[:fido_path] = '/usr/local/bin/fido'
|
17
|
+
Libis::Tools::Config.logger.level = 'off'
|
28
18
|
}
|
29
19
|
|
30
20
|
context 'Repository' do
|
31
21
|
|
32
22
|
it 'loads all converters' do
|
33
|
-
expect(repository.get_converters.size).to eq
|
23
|
+
expect(repository.get_converters.size).to eq 6
|
34
24
|
# noinspection RubyResolve
|
35
25
|
expect(repository.get_converters.map(&:to_s)).to include 'Libis::Format::Converter::ImageConverter'
|
36
26
|
# noinspection RubyResolve
|
@@ -39,6 +29,10 @@ describe 'Converters' do
|
|
39
29
|
expect(repository.get_converters.map(&:to_s)).to include 'Libis::Format::Converter::PdfConverter'
|
40
30
|
# noinspection RubyResolve
|
41
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'
|
42
36
|
end
|
43
37
|
|
44
38
|
it 'creates simple converter chain' do
|
@@ -120,7 +114,7 @@ describe 'Converters' do
|
|
120
114
|
compare.fuzz << '1%'
|
121
115
|
compare << diff_file
|
122
116
|
compare.call {|_, _, status| expect(status).to be 0}
|
123
|
-
|
117
|
+
FileUtils.rm tgt_file, force: true
|
124
118
|
end
|
125
119
|
|
126
120
|
it 'converts TIFF to PNG' do
|
@@ -153,7 +147,7 @@ describe 'Converters' do
|
|
153
147
|
compare.metric << 'AE'
|
154
148
|
compare.fuzz << '100%'
|
155
149
|
compare << diff_file
|
156
|
-
compare.call {|_,_,status|expect(status).to be 0}
|
150
|
+
compare.call {|_, _, status| expect(status).to be 0}
|
157
151
|
FileUtils.rm tgt_file, force: true
|
158
152
|
end
|
159
153
|
|
@@ -193,7 +187,7 @@ describe 'Converters' do
|
|
193
187
|
compare.metric << 'MAE'
|
194
188
|
compare.fuzz << '10%'
|
195
189
|
compare << diff_file
|
196
|
-
compare.call {|_,_,status| expect(status).to be 0}
|
190
|
+
compare.call {|_, _, status| expect(status).to be 0}
|
197
191
|
FileUtils.rm tgt_file, force: true
|
198
192
|
end
|
199
193
|
|
@@ -205,12 +199,13 @@ describe 'Converters' do
|
|
205
199
|
result = converter.convert(src_file, tgt_file, :JP2)
|
206
200
|
expect(result).to eq tgt_file
|
207
201
|
expect(File.exist?(tgt_file)).to be_truthy
|
202
|
+
FileUtils.rm tgt_file, force: true
|
208
203
|
end
|
209
204
|
|
210
205
|
|
211
206
|
end
|
212
207
|
|
213
|
-
context 'JP2 Converter' do
|
208
|
+
context 'JP2 Converter', if: File.exists?(Libis::Format::Config[:j2kdriver]) do
|
214
209
|
|
215
210
|
let(:converter) {Libis::Format::Converter::Jp2Converter.new}
|
216
211
|
let(:diff_file) {File.join('', 'tmp', 'diff.jpg')}
|
@@ -222,6 +217,7 @@ describe 'Converters' do
|
|
222
217
|
result = converter.convert(src_file, tgt_file, :JP2)
|
223
218
|
expect(result).to eq tgt_file
|
224
219
|
expect(File.exist?(tgt_file)).to be_truthy
|
220
|
+
FileUtils.rm tgt_file, force: true
|
225
221
|
end
|
226
222
|
|
227
223
|
it 'converts only first page of multipage TIFF to JP2' do
|
@@ -237,13 +233,13 @@ describe 'Converters' do
|
|
237
233
|
compare.metric << 'MAE'
|
238
234
|
compare.fuzz << '10%'
|
239
235
|
compare << diff_file
|
240
|
-
compare.call {|_,_,status| expect(status).to be 0}
|
236
|
+
compare.call {|_, _, status| expect(status).to be 0}
|
241
237
|
FileUtils.rm tgt_file, force: true
|
242
238
|
end
|
243
239
|
|
244
240
|
end
|
245
241
|
|
246
|
-
context 'Pdf Converter' do
|
242
|
+
context 'Pdf Converter', if: File.exists?(Libis::Format::Config[:ghostscript_path]) do
|
247
243
|
|
248
244
|
let(:converter) {Libis::Format::Converter::PdfConverter.new}
|
249
245
|
|
@@ -327,4 +323,104 @@ describe 'Converters' do
|
|
327
323
|
|
328
324
|
end
|
329
325
|
|
326
|
+
context 'Audio Converter' do
|
327
|
+
|
328
|
+
let(:converter) {Libis::Format::Converter::AudioConverter.new}
|
329
|
+
extensions = %w'aac aiff au flac m4a mka mp3 ra voc wav wma'
|
330
|
+
confidence = {
|
331
|
+
aac: 0.86,
|
332
|
+
aiff: 0.99,
|
333
|
+
au: 0.99,
|
334
|
+
flac: 0.99,
|
335
|
+
m4a: 0.93,
|
336
|
+
mka: 0.94,
|
337
|
+
mp3: 0.95,
|
338
|
+
ra: 0.92,
|
339
|
+
voc: 0.99,
|
340
|
+
wav: 0.99,
|
341
|
+
wma: 0.9
|
342
|
+
}
|
343
|
+
targets = %w'mp3 flac wav'
|
344
|
+
sources = %w'carlin_disappointed greensleeves king_nonviolence top_gun_secret'
|
345
|
+
quality = {
|
346
|
+
carlin_disappointed: 1.0,
|
347
|
+
greensleeves: 0.95,
|
348
|
+
king_nonviolence: 1.0,
|
349
|
+
top_gun_secret: 0.95
|
350
|
+
}
|
351
|
+
|
352
|
+
let(:data_dir) {File.join(file_dir, 'data', 'audio')}
|
353
|
+
|
354
|
+
context 'converts' do
|
355
|
+
sources.each do |source|
|
356
|
+
extensions.each do |ext|
|
357
|
+
next unless (File.exists?(File.join(File.dirname(__FILE__), 'data', 'audio', "#{source}.#{ext}")))
|
358
|
+
(targets - [ext]).each do |tgt|
|
359
|
+
it "#{source} #{ext} to #{tgt}" do
|
360
|
+
src_file = File.join(data_dir, "#{source}.#{ext}")
|
361
|
+
ref_file = File.join(data_dir, "#{source}.#{tgt}")
|
362
|
+
tgt_file = File.join('', 'tmp', "test.#{source}.#{ext}.#{tgt}")
|
363
|
+
FileUtils.remove tgt_file, force: true
|
364
|
+
FileUtils.mkdir_p File.dirname(tgt_file)
|
365
|
+
result = converter.convert(src_file, tgt_file, tgt.upcase.to_sym)
|
366
|
+
expect(result).to eq tgt_file
|
367
|
+
expect(result).to sound_like ref_file, confidence[ext.to_sym] * quality[source.to_sym], 11025, 1
|
368
|
+
FileUtils.remove tgt_file, force: true
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
end
|
376
|
+
|
377
|
+
context 'Video Converter' do
|
378
|
+
|
379
|
+
let(:converter) {Libis::Format::Converter::VideoConverter.new}
|
380
|
+
extensions = %w'3gp avi flv mkv mov mp4 mpg swf webm wmv'
|
381
|
+
targets = %w'avi flv mkv mov mp4 swf webm wmv gif'
|
382
|
+
# noinspection RubyLiteralArrayInspection
|
383
|
+
sources = [
|
384
|
+
'SampleVideo_176x144_2mb',
|
385
|
+
'SampleVideo_320x240_2mb',
|
386
|
+
'SampleVideo_360x240_2mb',
|
387
|
+
'SampleVideo_1080x720_2mb'
|
388
|
+
]
|
389
|
+
bad_converts = [
|
390
|
+
]
|
391
|
+
let(:data_dir) {File.join(file_dir, 'data', 'video')}
|
392
|
+
|
393
|
+
|
394
|
+
context 'converts' do
|
395
|
+
sources.each do |source|
|
396
|
+
context source do
|
397
|
+
extensions.each do |ext|
|
398
|
+
next unless (File.exists?(File.join(File.dirname(__FILE__), 'data', 'video', "#{source}.#{ext}")))
|
399
|
+
(targets - [ext]).each do |tgt|
|
400
|
+
next if bad_converts.include? [ext, tgt]
|
401
|
+
it "#{ext} to #{tgt}" do
|
402
|
+
src_file = File.join(data_dir, "#{source}.#{ext}")
|
403
|
+
tgt_file = File.join('', 'tmp', "test.#{source}.#{ext}.#{tgt}")
|
404
|
+
FileUtils.remove tgt_file, force: true
|
405
|
+
FileUtils.mkdir_p File.dirname(tgt_file)
|
406
|
+
converter.audio_channels(2) if %w'swf wmv'.include?(tgt)
|
407
|
+
# converter.constant_rate_factor(24) if %w'swf wmv'.include?(tgt)
|
408
|
+
converter.sampling_freq(44100) if tgt == 'swf'
|
409
|
+
if tgt == 'gif'
|
410
|
+
converter.start(1)
|
411
|
+
converter.duration(3)
|
412
|
+
end
|
413
|
+
result = converter.convert(src_file, tgt_file, tgt.upcase.to_sym)
|
414
|
+
expect(result).to eq tgt_file
|
415
|
+
expect(File.size(result)).to be > 2000
|
416
|
+
FileUtils.remove tgt_file, force: true
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
end
|
425
|
+
|
330
426
|
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|