-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakespectrums
executable file
·57 lines (47 loc) · 1.76 KB
/
makespectrums
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
#!/usr/bin/ruby
# frozen_string_literal: true
require 'fileutils'
TARGET_EXTENSION = 'wav'
file_inputs = []
spectrum_files = []
ARGV.each do |input|
input_normalized = input.gsub('\\','/')
# If input is directory, recursively add all files with target extension to target list
if File.directory?(input_normalized)
targets = Dir["#{input_normalized}/**/*.{#{TARGET_EXTENSION.upcase},#{TARGET_EXTENSION.downcase}}"]
targets.each do |file|
file_inputs << file
end
# If input is file, add it to target list (if extension matches target extension)
elsif File.extname(input_normalized).downcase == '.' + TARGET_EXTENSION.downcase && File.exist?(input)
file_inputs << input
else
puts "Input: #{input} not found!"
end
end
if file_inputs.empty?
puts 'No targets found!'
exit
end
file_inputs.sort!
file_inputs.each do |target|
spectrum_out = File.dirname(target) + "/" + File.basename(target,".*") + '.jpg'
spectrum_files << spectrum_out
filter = "highpass=f=8000,showspectrumpic=fscale=lin,drawtext=fontsize=56:fontcolor=white:text=#{File.basename(target)}"
system('ffmpeg', '-i',target,'-lavfi',filter,'-y',spectrum_out)
# if File.exist?(spectrum_out)
# pdf_page = spectrum_out + '.pdf'
# system('convert',spectrum_out,pdf_page)
# end
end
puts
timestamp = Time.now.strftime('%Y-%m-%d_%H-%M-%S')
output_location = ENV['HOME'] + "/Desktop/audioqc-spectrum-report_#{timestamp}.pdf"
spectrum_compile_command = 'convert '
spectrum_files.each {|spectrum_page| spectrum_compile_command += "'#{spectrum_page}' "}
spectrum_compile_command += output_location
#`convert #{spectrum_compile_list} 'test.pdf'`
#system('convert', spectrum_compile_list, 'test.pdf')
if `#{spectrum_compile_command}`
spectrum_files.each {|input| FileUtils.rm(input)}
end