m4a to wav converter code example

Example: python m4a to wav

#!/usr/bin/env python

import os
import commands

import logging
import traceback

if __name__ == '__main__':
    outputdir = os.path.abspath(<path to output>)
    for root, dirs, files in os.walk('.'):
        for f in files:
            path = os.path.join(root, f)
            base, ext = os.path.splitext(f)
            outputpath = os.path.join(outputdir, base + ".wav")
            if ext == '.m4a':
                print 'converting %s to %s' % (path, outputpath)
                status, output = commands.getstatusoutput('ffmpeg -i "%s" "%s"' % (path, outputpath))
                if status:
                    logging.error (output)