Skip to content

Instantly share code, notes, and snippets.

@rashivkp
Last active July 29, 2020 06:35
Show Gist options
  • Save rashivkp/7f0ad3dd75204aa5d4c4e15da6ef917c to your computer and use it in GitHub Desktop.
Save rashivkp/7f0ad3dd75204aa5d4c4e15da6ef917c to your computer and use it in GitHub Desktop.
Convert aac, amr files in a folder to ogg format with same name. And remove original file.
#! /usr/bin/python
import sys
from subprocess import call
import os.path
dest_ext = "ogg"
def convert(source):
print("Source: " + source)
extension = source[-3:]
dest = source[:-3] + dest_ext
if os.path.isfile(dest):
print("============ Already Converted: " + dest)
return
# return_code = call("ffmpeg -i '"+ source +"' -c:a libmp3lame -ac 2 -q:a 2 '"+dest+"'", shell=True)
return_code = call("ffmpeg -i '"+ source +"' -c libvorbis '"+dest+"'", shell=True)
if return_code == 0:
print(">>>>>>>>>>>> Converted: " + source)
call("rm '"+ source+"'", shell=True)
else:
print("============ Error on processing: " + source)
def convert_all(path = "."):
for filename in os.listdir(path):
if filename.endswith(".aac") or filename.endswith(".amr"):
convert(path + "/" +filename)
if __name__ == "__main__":
if len(sys.argv) > 1:
convert_all(sys.argv[1])
convert_all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment