Doug Sparling

Mobile/Web Developer

Month: January, 2016

Validate XML File with Python

by Doug Sparling


from xml.sax.handler import ContentHandler
from xml.sax import make_parser
from glob import glob
import sys

def parsefile(file):
    parser = make_parser()
    parser.setContentHandler(ContentHandler())
    parser.parse(file)

for arg in sys.argv[1:]:
    for filename in glob(arg):
        try:
            parsefile(filename)
            print "%s is well-formed" % filename
        except Exception, e:
            print "%s is NOT well-formed! %s" % (filename, e)

Convert mp3 bit rate and change from stereo to mono

by Doug Sparling

I listen to a lot of podcasts, and sometimes I like to keep the files around. However, often a simple audio podcast uses a high bit rate and often stereo, resulting in a large file size when it’s not really necessary. So unless I want the highest quality mp3 file possible, I stick with the BBC Future Media Standards and Guidelines. For podcasts, it’s something like the following:

  • MP3 Mono Speech: 64 kbps, 44.1 kHz, constant bit rate
  • MP3 Stereo Music: 128 kbps, 44.1 kHz, constant bit rate

Here’s a typical FFmpeg command I run to simultaneously convert a stereo file to mono, and to lower the bit rate to 64K: (Obviously, change the filenames as necessary.)

$ ffmpeg -i stereohighbitratefile.mp3 -ac 1 -ab 64k mono64kfile.mp3

HT to Richard Farrar.