Learning Python my journey and top tips!

Over the last year or so, I've finally got the hang of object orientated programming. An unsurprising enabler was learning python.

Lots of people have seen me on the journey and have asked me for some links and tips.

And the good news is you can learn all this stuff for free! Gratis…. no money….However! I will be giving Corey and Engineer man some money via Patreon, because I learned so much more than with Lynda or Linkedin learning etc.. and I give them £30pm

At a high level

  1. Set up your dev environment

  2. Learn quickly

  3. Learn deeper

  4. Learn git

  5. Get into flask, flask-rest,SQLAlchemy, openAPI

  6. Learn Docker and show off your warez

Setting up your dev environment.

Visual Studio Code ... watch this video (pc/mac). Everything you need to know about setting up a Windows / Mac python dev environment in python




I like using vagrant for portable dev enviroments, docker for me comes later in the cycle.


Learn Quickly

Engineer man, 10 videos

Learn Deep

Corey Schafer is your man

Learn git

Coery to the rescue here

Get into Flask, Flask-rest, SQLAlchemy, openAPI

Would you know it



Learn docker


Python RTP rewrite using scappy

I recently had to re-stripe some RTP headers for a 2022-2 transport stream.

Here’s the python code I wrote to do it as scappy and RTP is not very well documented.

### Python 2.7 Script by Neil Bernard neil@themoog.org
## This script is for editing RTP header information in PCAP files to manipulate RTP timestamp and SSRC
## for testing hardware transport stream devices and testing SMPTE 2022-2 handling

## There is some error checking for scapy network layers but try to keep capture as clean as possible
## also try to keep captures under 260Mb for performance, can take a good 20mins on an intel i7 / 16GB ram

#### Basic Scapy Tutorial

# *https://www.youtube.com/watch?v=ADDYo6CgeQY

#### Scapy cheat sheet

# https://blogs.sans.org/pen-testing/files/2016/04/ScapyCheatSheet_v0.2.pdf

#### Scapy RTP Library https://fossies.org/linux/scapy/scapy/layers/rtp.py

# import scapy
from scapy.all import rdpcap
from scapy.all import wrpcap
from scapy.all import RTP
from scapy.all import *

infile = "ericsson_rtp.pcap"
# infile = "ip6.pcap" # Used for testing error handlind has some ipv6 and other errors from cap file
# infile = "ericsson_rtp_split_00302_20180830165700.pcap" # Used for testing as a very small file
outfile = "modified_" + infile
dest_port = 2000 # usefull to make sure you only action packets that are RTP

# load packet capture
print "Loading Packet Capture Keep <200Mb - Might take a few mins....."
pl = rdpcap(infile)
print "Loading complete!"

# print number of packets
# # print rtp timestamp
# print(RTP(pl[0][UDP].payload).timestamp)
numberofpckts = len(pl)

print numberofpckts

for pkt in range(numberofpckts):

    # You cant use the [RTP] layer on a list index so you have to put it in a
    # variable first. Also need to make sure its a UDP packet with .haslayer(UDP):
    # https://stackoverflow.com/questions/48763072/scapy-getting-trailer-field-in-the-dissector

    if pl[pkt].haslayer(UDP):
        packet = pl[pkt][UDP]

        print "Probably Not a UDP / RTP Packet# {0}".format(pkt)

    # You need to do the line below to force RTP detection and manipulation
    # https://stackoverflow.com/questions/44724186/decode-rtp-over-udp-with-scapy

    if pl[pkt].haslayer(UDP):
        if packet["UDP"].dport==2000: # Make sure its actually RTP
            packet["UDP"].payload = RTP(packet["Raw"].load)

        #### un-commment and change lines below to manipulate headers

            # packet[RTP].version = 0
            # packet[RTP].padding = 0
            # packet[RTP].extension = 0
            # packet[RTP].numsync = 0
            # packet[RTP].marker = 0
            # packet[RTP].payload_type = 0
            # packet[RTP].sequence = 0

            # packet[RTP].timestamp = 2989837974 # known good test timestamp
            packet[RTP].timestamp = 7929856 ## Colours Tamil bug
            # packet[RTP].timestamp = 0

            packet[RTP].sourcesync = 0
            # packet[RTP].sync = 0

            ### Calculate UDP Checksum or they will now be wrong!


            checksum_scapy_original = packet[UDP].chksum

            # set up and calculate some stuff

            packet[UDP].chksum = None ## Need to set chksum to None before starting recalc
            packetchk = IP(raw(packet))  # Build packet (automatically done when sending)
            checksum_scapy = packet[UDP].chksum
            packet_raw = raw(packetchk)
            udp_raw = packet_raw[20:]
            # in4_chksum is used to automatically build a pseudo-header
            chksum = in4_chksum(socket.IPPROTO_UDP, packetchk[IP], udp_raw)  # For more infos, call "help(in4_chksum)"

            # Set the new checksum in the packet

            packet[UDP].chksum = checksum_scapy # <<<< Make sure you use the variable in checksum_scapy

            # needed below to test layers before printing newts/newsourcesync etc to console

            if pl[pkt].haslayer(UDP):
                newts = RTP(pl[pkt][UDP].payload).timestamp
                newsourcesync = RTP(pl[pkt][UDP].payload).sourcesync

                newts = 999
                newsourcesync = 999

            print("Changing packet {0} of {3} to new timestamp {1} SSRC {2} Old UDP chksum {4} >> New UDP chksum ???").format(pkt+1,newts,newsourcesync,numberofpckts,hex(checksum_scapy_original))

            print "Probably Not a UDP / RTP Packet# {0}".format(pkt)

# Write out new capture file
wrpcap(outfile, pl)

Electrical CU/DB Cable grouping combs, 3D concept prints

After watching sparky ninjas video on “Cable Grouping and the impact on electrical installations” I was a bit bored and thought I would concept some management combs and 3D print them. General idea being that you can still strive for workmanship, but guide compliance. Anyway…..

Here’s sparkynijas video

And here’s some cable management ideas, not sure if anyone is interested? Just basic concepts. Can be refined and reviewed if anyone has any feedback.

3D printed concepts

3D printed concepts

EDIT: Was thinking last night you could make the plastic combs from a termochromatic plastic (one that changes colour based on temperature) could be an indicator?



Raspberry Pi3 Test Node - Low cost network testing - Howto

Recently I had a contract where I did a stint as unix admin. Now I still consider myself a broadcast engineer, but it really was useful to deep dive unix for a few months.

Skip forward to my current role where I have to troubleshoot network problems for contribution video and control. Having nearly 50 remote sites to support can prove challenging. What we really needed was some of the unix networking test tools I had built experience of.

Step forward the Raspberry Pi Version 3 Model B. Normally i'm not a fan of using these in enterprise environments, TBH most of the people I work for can afford the very best gucci tools.

On this occasion though, and with so many sites, as long as we carefully document, build and install them it would certainly provide a massive advantage for a monitoring and troubleshooting tool.

The requirements

  • Provide a low cost linux based platform for deployment on each network leg.
  • Install a number of networking troubleshooting and test tools.
  • Provide serial connections (via a USB to Serial Convertor) to provide out of band management to other ip enabled remote devices.
  • Ability to mount storage / support USB drives for the occasional remote media task.
    What follows is my notes for setting up an image for the Raspberry Pi 3, using https://www.raspbian.org/ as the base OS. At each stage where relevant I have credited the link I got the information from, this will also include far more detail than my notes.

We are going to use this pi headless (no Keyboard, Video or Mouse (KVM)) but we do need to briefly set it up on KVM and obtain an ip-address.

Initial Config

 Connect the pi to  KVM and login with the GUI. In the Raspberry Pi configuration >> Config

Set the following.

- Boot to CLI
- Enable SSH
- Auto Login OFF


sudo ifconfig

and note down the ip-address for


sudo reboot

Now use a client like terminal for MacOSX or putty for windows and SSH to the ip address of your pi. Follow the prompts and login with u:pi password:raspberry

Now we need to make sure we are using all the space on our SD card




>> Expand FileSystem  and follow the prompts.

Update your pi


sudo apt-get update
sudo apt-get upgrade

SET Static IP


sudo nano /etc/dhcpcd.conf

as follows (extract from man dhcpcd.conf):-

Configures a static value.  If you set ip_address then dhcpcd will not attempt to obtain a lease
and just use the value for the address with an infinite lease time.

 Here is an example which configures a static address, routes and dns.
       interface eth0
       static ip_address=
       static routers=
       static domain_name_servers=

SET hostname


sudo nano /etc/hosts

Edit the name after the loopback address of

Save and exit,


sudo nano /etc/hostname

Edit, Save and Exit

Commit the changes to the system and reboot the system for the changes to take effect. : 

sudo /etc/init.d/hostname.sh

Follow that command with: 

sudo reboot

SET NTP Servers


sudo nano /etc/ntp.conf 

Find lines starting with "server". Replace that lines for lines with servers from pool.ntp.org.

Now you can restart ntp service.

/etc/init.d/ntp restart

Here is command to check if time is synchronizing properly. To list NTP servers with which RPi is synchronizing:

ntpq -pn 

Manage users


Login as pi and the issue the


command to change password

create a new user (for example) u:noddy p:bigears


sudo adduser noddy  

and you'll be prompted for a password for the new user noddy

The default pi user on Raspbian is a sudoer. This gives the ability to run commands as root when preceded by sudo, and to switch to the root user withsudo su.
To add a new user to sudoers, type

sudo visudo

(from a sudoer user) and find the line root    ALL=(ALL:ALL) ALL, found under the commented header '# User privilege specification'. Copy this line and switch from root to the username. To allow passwordless root access, change to NOPASSWD: ALL. The example below gives the user bob passwordless sudo access:
# User privilege specification

Disable the wireless radios on the Pi3 (Not good to be connecting to networks)


sudo nano /etc/modprobe.d/raspi-blacklist.conf

Add the following lines 

blacklist brcmfmac
blacklist brcmutil
blacklist btbcm
blacklist hci_uart


sudo reboot

You should now see some failures on restart, this is good and means the radios are disabled

Install some useful apps

sudo apt-get install the following

For example

sudo apt-get nmap



Network Scanner



mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.



tool for active measurements of the maximum achievable bandwidth on IP networks.



Tcpdump prints out a description of the contents of packets on a network interface



ser2net provides a way for a user to connect from a network connection to a serial port.



VNC, or "Virtual Network Computing", is a connection system that allows you to use your keyboard and mouse to interact with a graphical desktop environment on a remote server.



Simple Network Management Protocol (SNMP) is a widely used protocol for monitoring the health and welfare of network equipment (eg. routers), computer equipment and even devices like UPSs. Net-SNMP is a suite of applications used to implement SNMP v1, SNMP v2c and SNMP v3 using both IPv4 and IPv6. The suite includes:



IPTraf is a console-based network statistics utility for Linux. It gathers a variety of figures such as TCP connection packet and byte counts, interface statistics and activity indicators, TCP/UDP traffic breakdowns, and LAN station packet and byte counts.



This is htop, an interactive process viewer for Unix systems.



MediaInfo is a convenient unified display of the most relevant technical and tag data for video and audio files.

Install ffmpeg from source

Its all in here


Mount Network Drives

Again probably best to read this.


Useful commands

Measure temp of raspberrypi:

/opt/vc/bin/vcgencmd measure_temp


Whats Next?

Shortly Ill be posting the hardware setup ..

As we speak a 19" case is being printed on the Ultimaker2. While its a quick and dirty prototype it will serve to provide the basis for a better design.

Also I will demonstrate the serial terminal cabling, and how I use some of the tools I installed.

3D printing and girlfriends

I love my Ulitmaker2, but it wasn't warmly welcomed into our home.

Justifying £1700 is easy for a geek like me.  For my girlfriend (GF) she thought it was another waste of time and money on something that oozes hot plastic and goes up/down - side to side.

However i'm happy to report the situation has improved. Lots of business items have been "ozzed" out and the GF seems happier that i'm happy tinkering :)

Much so i'm even making commissions for the GF

As a first update to the new blog, I thought id show the easter egg mold I was asked to make.

Autocad fusion360 is my current 3d tool of choice.

Heres the render

And here's the final result, printed on my ultimaker2 with Blue – 2.9mm Polymaker PolyPlus PLA Filament from my new friends @ www.dream3d.co.uk

Heres how it looks


The hole at the bottom was a bit small so I drilled it out. Ive updated the model. Which incidentally I uploaded to thingy-verse.


So I guess question is, where's my chocolate egg? GF..over to you.

How loud is your stream?

Below is a sample of data I took recording popular news channels for 3mins exactly and then analysing the results. This was done between 0530g and 0614g 01/04/12 here was the test subject list of freely available news streams








Here was my process

All was done on my iMac in OSX (10.7.2)All testing never left the digital domain.
All audio file settings/encodes were 48000/16bit/Stereo. All playback locally used quicktime player 10.1 All web playback used safari 5.1.1

1)  Create - 18dbFS file in adobe audition
2) Used http://www.audiofile-engineering.com/spectre/ to confirm that playback level was -18dbFS on a digital meter and 4PPM on a BBC meter when played back and all audio controls set to max (all checked out)
3) Created video file in iMovie of a -18dbFS tone and uploaded to youtube http://www.youtube.com/watch?v=tziQZGjIspM
4) With the youtube flash player volume set to max, played back and calibrated my flash player to the spectre meters (only needed about -1.5db adjust, not sure why yet)
5) Went through popular news channels with their flash player volumes set to max, auto recorded 3min files to a PCM wav file, also did the same with the calibrated tone from the youtube player.
6) Put the .wav files through a tektronix cerify file checker, obtained results and plotted on graph below.
So I think its a fair test, as I ensured a unity path at all stages and times and recorded all files with the same setup.

As you can see CNN, Bloomberg, Aljazeera and BBC all look to group well as you would suspect. The 2 other channels NDTV and Euronews I have no conclusion yet.I was thinking I would see more of a spread of results on the internet streams as opposed to TV baseband audio levels… but I guess and hope this is following baseband TV levels, and I guess with modern encoders there is no real difference between baseband TV levels and the internet stream levels.

a) Im assuming -18dbFS ref level….. they could be -20/24 or anything really.
b) Im assuming the flash players all have 0dbFS at their max setting.
c)) This was only a specific sample window I would need more samples to be a lot more accurate.

Find that asset - PowerShell Script - Windows

Managing media assets is great nowdays, all these webUI CMS type applications, however, when trouble shooting a backend system I often find myself needing to locate specific files in a number of locations quickly. A collegue of mine came up with a nice little .bat script to search for a file name in a bunch of different server locations. However it was all hard coded and didn't format nicely on the screen.

I decided to pimp it up with a nice powershell script.....

Essentially at the command prompt use the format

./find_files_in_broadcast_servers.ps1 -f "yourfilename_or_wilcard" e.g. ./find_files_in_broadcast_servers.ps1 -f "catplayingpiano.mpg" ./find_files_in_broadcast_servers.ps1 -f "*cat*"



# Script to search files in locations listed in locations.txt #
# Usage - ./find_files_in_broadcast_servers.ps1 -f "yourfilename_or_wildcard" #
# Grab command arguments from command line - filename #

param([string]$f = "filename")

# Open locations.txt into $a for each search location (one per line in txt file with CRLF at end #

$a = Get-Content "C:\scripts\powershell\locations.txt"

# Use foreach loop to step through locations in locations.txt #

foreach ($i in $a)

    # Print seach location to console window in green #

    {Write-Host -ForeGroundColor green $i

    # Search for file, recurse subdirectorys with the root location specified in locations.txt, format in table, sort by name #

    dir $i -recurse -filter $f | sort name | ft directory, name, LastWriteTime}

# END #

You will need to create a locations.txt file in the location specified on the Get-Content line with all of your locations specifed. Use the windows UNC format. For example.... locations.txt..... \\server1\location1 \\server2\location2 \\server3\location3 \\server4\location4


Tip: you may need to set PowerShell security to run unsigned scripts, there are various different options dependant on your security needs.


PowerShell Security


Neil (themoog)

If in doubt just add layers

In a previous job I used to work as a CAD operator, a few years later when I was working in broadcast enginneering I was looking at creating some more standard Autocad templates and blocks for broadcast drawings. Ive never really got around to it, each time I do a drawing I just modify an old one from an existing template a colleague of mine made.

So ive decided to get back on it and create myself a better, more automated workflow.

One of the first things I was looking at is how to standardise layers. A few google searches later I found that the AIA (American Institute of Architects) had a system that seemed perfect (AIA CAD Layer Guidelines). With a few modifications I came up with the following….

themoog’s layering standards for broadcast Autocad drawings

As recommend by the 1997 AIA CAD layer Guidelines, layer names may be as short as six characters (discipline code + major group) or as long as sixteen characters (discipline code + major group + minor group + status). See bellow for examples.

B-VID = discipline code + major code
B-VID-SDI = discipline code + major code + minor code
B-VID-EXST = discipline code + status code
B-VID-SDI-EXST = disincline code + major code +minor code + status code

Discipline code

The discipline code is a two character field with either a hyphen or user defined modifier.

Discipline Code Discipline
A architectural
B broadcast
C civil
E electrical
I interior
M mechanical
S structural
T telecom

Major group

The major group filed is a four character field that identifies the system such as VIDEO, AUDIO etc…. Although most major groups are logically associated with specific discipline codes, it is possible to combine major group codes with any of the discipline codes. For example, B-VID, T-VID

Major Description
VID video
AUD audio
ROLL rollcall (S&W)

Minor group

This is an optional four character field for further differentiation of major groups fro example, B-VID-SDI, B-VID-CVBS

Minor Description
SDI serial digital video
CVBS composite video burst and sync
ABAL analog balanced audio
CBLN cable numbers
CABN cab numbers

Status field

The status field is an optional four character designator that differentiates new builds from remodeling and changes. For example B-VID-SDI-EXST

status description
NEWW new work
EXST existing to remain
DEMO existing to demolish
FUTR future work
TEMP temporary work
MOVE items to be moved
RELO relocated items
NICN not in contract
PHS1–9 phase numbers


annotation description
*-ANNO-DIMS dimensions
*-ANNO-KEYN keynotes
*-ANNO-LEGN legends and schedules
*-ANNO-NOTE notes
*-ANNO-NPLT non-plot info e.g. viewports
*-ANNO-REVS revisions
*-ANNO-TEXT text
*-ANNO-TTLB title blocks and sheet borders


As a general rule for all projects, drawing entities should assume the colour of the layer in which they reside. This means all colours are applied by ‘layer’ not ‘entity’

layer colour line-weight line-type
B-VID-SDI SDI Video 6-magenta continuous
B-VID-CVBS CVBS Video 3-green continuous
B-AUD-ABAL Analog balanced Audio 5-blue continuous
B-AUD-AUB Analog Unbalanced Audio 5-blue continuous

Colour Codes

code colour
1 red
2 yellow
3 green
4 cyan
5 blue
6 magenta
7 white
8 -
9 lt-grey


BTW, if anyone has any better solutions i’m still happy to hear, also I really want to know if anyone has any good cable numbering systems!

Virtual Waveform Monitor





For a quick and dirty project to learn processing I decided to write a small application to teach how RGB, color difference levels and vectors are displayed on a PAL Video scope.

Using three sliders you can pick your colour and see how it would be represented on a real PAL waveform monitor.  Useful for understanding how the RAW colours translate into real world measurements.

Because i'm happy with the learning curve I haven't added any graticules or measurement options. However if people find it useful i'll develop it more.

MacOSX, Windows, Linux

Download it here [download id="4"]

How long will this take? Latency in broadcast control

Latency in control systems for broadcast applications is a variable in producing smooth television. When you start combining the idea of controlling live systems over large distances this problem increases somewhat.

So what is acceptable latency? Well its hard to say, in live television when you want to move a camera live on air then the smaller the better. But what is the best we can get using todays technology?

This post is an exercise to find out what the shortest possible RTT (round trip time) is for controlling a device and seeing the result to complete the feedback loop for the operator.

Here is an example of moving a camera live on air, when the operator is based in London and the studio based in Hong Kong.

I will preface this in saying this is something I have had to actually develop and build. I think a Europe to Asia example should detail a worst case scenario anywhere in the world.

All timing assumptions are based on SD video using h.264, your mileage will vary (a lot) by using other types of video codec.

Latency - London <> Hong Kong

Purple - The Operator

Here we look at the cognitive psychological process.  There is some evidence  to say it takes 300ms to recognise an object http://www.themoog.org/opn so we should add in some "reaction time".

A quick google search brings up "The reaction time tester" http://www.themoog.org/stm.

Here you are asked to hit the mouse button when the green light comes on.  I scored 0.2942ms over an average of 5 tries.

Online Reaction Time Test

Of course there are many other factors, such as communication overload, skill of the operator, training etc... But this is meant to be a best case study so I'll use 300ms for ideal circumstances

Blue - Video Encoding

Well seems the standard nowadays is h.264 over TPC/IP.  The RAW encode/decode process spec'd on a D9093/D9094 cicso IP codec is 580ms for PAL and 550ms for NTSC in IP low mode. Why IP low mode? Well in practical experience this is the lowest latency setting achieved causing no problems in the picture.  Any lower and you start seeing frames drop

Cisco Encode / Decode times

Green - The decode process

Well I've sort of lumped the h.264 encoding / decoding latency together in the section above, but we should still add another 40ms to take any video processing (such as video synchronisers or standards converters) into account.

Yellow - TCP/IP network latency

I'm lucky and have access to a dedicated network. Using the standard ICMP ping tool available in any OS  I get about 300ms RTT (round trip time) between London and Hong Kong. 40ms RTT between London and Milan.

Over the Internet using http://www.pingtest.net/ i get the following result between my house in the UK and a server in Taiwan (that's the nearest server  I could get to Hong Kong)

Pingtest.net - The Global Broadband Quality Test

So I think best case is 300ms.

What makes up the network latencies? Well a number of factors.

Using http://www.wolframalpha.com/ I get the two following results.

london to milan - Wolfram|Alpha
london to hong kong - Wolfram|Alpha

The key piece of information here is speed of light in fibre. Now of course optical fibers don't go in a straight line, and also light has to be re-clocked and regenerated. But this is pretty much the best time your ever going to get (theoretically speaking)

The rest of the delay is made up by packet inspection routers and router packet queuing.

Network Jitter is a very important subject, but is not in the scope of this post


So what is the best RTT latency time I can expect?

Well to to visualise this I created the video below, using audio tones to represent the times shown in the flow chart diagram at the top of this post.


Using current technology with real world values I think expecting any less than 1740ms  is unlikely. Especially at the video quality that broadcasters expect.  Remember too I have only used SD video as an example, expect HD to increase this time. I also had the luxury of  using a very good network, if your using the Internet (which has its own QoS issues) your at least looking at adding 200ms.

The option of using another low quality return video feed for just monitoring the video feedback may also lower this time, but using 2 telco circuits will increase the cost.


I decided to replace rapidwaever with a wordpress site instead. I Like Rapidweaver but I had a couple of corrupted files and decided to move over to a "cloud" solution. Also it was much easier to set up the look and feel because your dealing in php/html

So this is my first post!!! (Again)

As a nice tit-bit i've taken a panorama with my Iphone of the new Bloomberg studios in London that i've been helping work on.

Bloomberg UK New Studios