Question: I have a live video stream from FFMpeg, and I am having a hard time viewing the stream using my own custom Java application. Before someone tells me to use VLC or something like that I do want to use my own application. The stream I am trying to read is a H.264 encoded Mpeg-ts stream streamed over UDP. I do know how to decode the H.264 frames, but I am simply wondering about how to receive the Mpeg-ts stream.

Answer: 
If you are specifically targeting CPython\* 3.6 or later, then you can [just use regular dictionaries](https://docs.python.org/3.6/whatsnew/3.6.html#whatsnew36-compactdict) instead of `OrderedDict`. You'll miss out on a few [methods exclusive to `OrderedDict`](https://docs.python.org/3.6/library/collections.html#collections.OrderedDict), and this is not (yet) guaranteed to be portable to other Python implementations,\*\* but it is probably the simplest way to accomplish what you are trying to do.

\* CPython is the reference implementation of Python which may be downloaded from python.org.  

\*\* CPython [stole this idea from PyPy](https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html), so you can probably depend on it working there too.
I realize this is sort of necroposting, but I thought I'd post what I use. Its main virtue is that its aoutput can be read back into python, thus allowing, for instance, to shutlle between representations (which I use, for instance, on JSON files). Of course it breaks pprint encapsulation, by ripping some code off its inner \_format function.

```
#!/bin/env python
from __future__ import print_function

import pprint;
from collections import OrderedDict
import json
import sys

class MyPP (pprint.PrettyPrinter):
    def _format(self, object, stream, indent, allowance, context, level):
        if not isinstance(object, OrderedDict) :
            return pprint.PrettyPrinter._format(self, object, stream, indent, allowance, context, level)
        level = level + 1
        objid = id(object)
        if objid in context:
            stream.write(_recursion(object))
            self._recursive = True
            self._readable = False
            return
        write = stream.write
        _len=len
        rep = self._repr(object, context, level - 1)
        typ = type(object)
        sepLines = _len(rep) > (self._width - 1 - indent - allowance)

        if self._depth and level > self._depth:
            write(rep)
            return

        write('OrderedDict([\n%s'%(' '*(indent+1),))
        if self._indent_per_level > 1:
            write((self._indent_per_level - 1) * ' ')
        length = _len(object)
        #import pdb; pdb.set_trace()
        if length:
            context[objid] = 1
            indent = indent + self._indent_per_level
            items = object.items()
            key, ent = items[0]
            rep = self._repr(key, context, level)
            write('( ')
            write(rep)
            write(', ')
            self._format(ent, stream, indent + _len(rep) + 2,
                         allowance + 1, context, level)
            write(' )')
            if length > 1:
                for key, ent in items[1:]:
                    rep = self._repr(key, context, level)
                    if sepLines:
                        write(',\n%s( %s , ' % (' '*indent, rep))
                    else:
                        write(', ( %s , ' % rep)
                    self._format(ent, stream, indent + _len(rep) + 2,
                                 allowance + 1, context, level)
                    write(' )')

            indent = indent - self._indent_per_level
            del context[objid]
        write('])')
        return

pp = MyPP(indent=1)
handle=open(sys.argv[1],"r")
values=json.loads(handle.read(),object_pairs_hook=OrderedDict)
pp.pprint(values)

```