Paul(B);

Code.new(); Thoughts.write(); Stdout.flush();

Streaming Youtube to MP3 Audio in NodeJS

Recently I learned how to stream a Youtube video’s audio in MP3 format using nodejs. I wanted to publish my findings and show off how to accomplish this.

First, let’s build this the non streaming way, and then I will show you how to upgrade to a streaming method. You must install the powerful ffmpeg via your package management system of choice in order to play along.

I’ll be using nodejs, to do this, because it offers us a very easy way to stream bits around. Despite the recent controversy, I’m still quite partial to coffee-script due to it’s terse syntax and clean output, so I’m going to use that for most of the new code. Let’s also use the wonderful expressjs framework to get us started really quickly. This will set up our project skeleton.

Fixed Point Math in C#

Fixed point math is an interesting optimization for games, and it also has the feature of determinism, something that floating point implementations lack due to rounding, truncation, and hardware differences.

With determinism, a networked physics simulation can guarantee that every machine can perform the same action, and given the exact same starting conditions, produce the same result. This reduces the network overhead significantly, instead of being forced to check the same result was achieved across all computers participating, one can instead make sure that each action was completed in the correct order instead.