Created
August 2, 2014 02:29
-
-
Save mxwell/5f637269315788286ab0 to your computer and use it in GitHub Desktop.
Convert M4A into MP3 (Linux)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby | |
# @ubuntu: depends on ffmpeg, libavcodec-extra-53 | |
output_dir = "output" | |
if File.exists? output_dir | |
id = 1 | |
while File.exists?(output_dir + id.to_s) && id < 10 | |
id += 1 | |
end | |
if id >= 10 | |
puts "error: can't figure out new output directory name" | |
exit 0 | |
end | |
output_dir = output_dir + id.to_s | |
end | |
Dir.mkdir output_dir | |
Dir.glob("*.m4a").each do | file | | |
puts "processing '#{file}'" | |
file.gsub! /\.m4a/, '' | |
cmd = 'ffmpeg -v 1 -i "' + file + '".m4a -f mp3 -b:a 320k "' + output_dir + "/" + file + '.mp3"' | |
puts " command: " + cmd | |
if not system(cmd) | |
puts " error" | |
else | |
puts " done." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment