Category Archives: Python

Better Closed Caption Decoding in Python

I’ve just pushed out an improved version of my Closed Caption decoder to GitHub. In addition to decoding closed captions to SRT or SCC formats, it includes the following improvements:

  • XDS packet decoding
  • Improved handling of noisy and non-standard video
  • More complete handling of esoteric characters
  • Much easy to use in embedded projects due to separation into core library
  • A few performance improvements
  • Pre-built command line version for windows (PyInstaller generated)

The software is entirely public domain – so feel free to use it in your own projects.

You’ll still need FFMpeg installed – but effortless static builds for windows can be found here. I’ll try and get an OSX binary built in the next few days.

I’d still like to move the project further forwards still – but I really need ‘real-world’ closed-caption samples to make it happen. If you are interested in decoding closed captions, and would like to see this tool improved, please reach out to me: we may be able to help each other.


PySmaz a Pure Python Small-String Compression Library Ported from SMAZ

PySmaz is a pure python port of the SMAZ small string compression library originally developed by Salvatore Sanfilippo. I thought I’d just jot down a few notes about the experience of porting the library from C to Python. In particular the challenges around optimizing both the absolute compression ratio of the algorithm, ensuring throughput is acceptable for its intended use, while preventing the code from descending into an unreadable mess.

Continue reading

Python: Pulling Apart IEEE Floats for Decimal conversion

While attempting to convert floats precisely to Decimals the other day I was caught out by the fact that Python 2.6’s print function defers to whatever the underlying C compiler’s printf function does. This meant that on Linux I got one result when I asked for ‘%.31f’ % math.pi, and on Windows – something completely different. This lack of portability is a pain, and I had to work around it.

Continue reading