Skip to content

Instantly share code, notes, and snippets.

@DoodlingDev
Created April 4, 2021 00:01
Show Gist options
  • Save DoodlingDev/d698fab019c2a2b931bff8893f6dcdfa to your computer and use it in GitHub Desktop.
Save DoodlingDev/d698fab019c2a2b931bff8893f6dcdfa to your computer and use it in GitHub Desktop.
normalize_file = "./audio_normalize_results.txt"
system "touch #{normalize_file}"
files_list = Dir["./**/*"]
files_list = files_list.select do |n|
n.match(/\.mkv$/) ||
n.match(/\.mp4$/) ||
n.match(/\.avi$/)
end
files_list_total = files_list.length
puts "#{files_list_total} files to convert"
files_list = files_list.map do |n|
full_filename = n.gsub(" ", '\ ')
full_filename = full_filename.gsub("(", '\(')
full_filename = full_filename.gsub(")", '\)')
full_filename
end
files_list.each_with_index do |full_filename, index|
puts "converting file number #{index} of #{files_list_total}"
match_group = full_filename.match(/(^.+)\/([^\/]+)$/)
dirname = match_group[1]
filename = match_group[2]
temp_filename = "#{dirname}/_#{filename}"
puts "mv #{full_filename} #{temp_filename}"
system "mv #{full_filename} #{temp_filename}"
result = system "ffmpeg -i #{temp_filename} -af dynaudnorm -vcodec copy #{full_filename} -max_muxing_queue_size 9999"
if result
system "echo 'SUCCESS -> #{full_filename}' >> #{normalize_file}"
system "rm #{temp_filename}"
else
system "echo 'FAILURE -> #{full_filename}' >> #{normalize_file}"
end
end
system "cat #{normalize_file}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment