forked from schmich/marinara
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Runfile
47 lines (41 loc) · 1.11 KB
/
Runfile
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
require 'securerandom'
require 'fileutils'
require 'tempfile'
def sound_name
SecureRandom.uuid.split('-').first
end
dir :pwd
run :rename do |file|
parts = file.split('.')
dir = File.dirname(file)
new_name = [sound_name(), *parts.slice(1, parts.length)].compact.join('.')
out = File.join(dir, new_name)
FileUtils.mv(file, out)
puts "#{file} -> #{out}"
end
dir :pwd
run :convert do |file|
name = sound_name()
out = "#{name}.mp3"
`ffmpeg -i "#{file}" -q:a 6 "#{out}"`
unless $?.success?
$stderr.puts 'Failed to convert.'
next
end
puts "#{file} -> #{out}"
end
dir :pwd
run :waveform do |file|
temp = Tempfile.new(["#{File.basename(file)}-", '.png'])
path = temp.path
temp.close(true)
`ffmpeg -i "#{file}" -filter_complex \
"[0:a]aformat=channel_layouts=mono, \
compand=gain=-6, \
showwavespic=s=600x120:colors=#9cf42f[fg]; \
color=s=600x120:color=#44582c, \
drawgrid=width=iw/10:height=ih/5:color=#[email protected][bg]; \
[bg][fg]overlay=format=rgb,drawbox=x=(iw-w)/2:y=(ih-h)/2:w=iw:h=1:color=#9cf42f" \
-vframes 1 "#{path}"`
`open "#{path}"` if $?.success?
end