Categories
Tech Explorations

Dirt-Cheap Livestreaming: How to do professional quality streaming on a budget

A couple of years ago I wrote an article on how I cobbled together livestreaming hardware at the very beginning of the pandemic. Finding AV equipment was very difficult, so I did what I could with what I had. Almost three years have passed since then, and in the meantime I built a multi-camera, simulcasting capable, live event oriented livestreaming solution on a shoestring budget. Many compromises were made, many frustrations were had, but it worked.

This is how I built it and made it work.

Why bother changing it?

After my initial stint doing a couple of livestreams for small events, the requirements kept popping up, for simple one camera setups my equipment would do, but it quickly started falling short; and as venues slowly started filling back up with people, I just couldn’t rely on building the event around the camera. I had to find a way to do this without being intrusive, and to be able to fulfill my clients’ needs.

Lessons from the previous setup

The setup I described in the previous writeup was not free of complications. On the video side, I was limited by a single HDMI input, and any switching solutions I had were too rough for my geriatric capture card; it would take way too long to reacquire a picture. On the audio side, my trusty USB interface was good, but way too finicky and unreliable (the drivers were crap, the knobs were crap, and while I got it for free it just wasn’t worth the hassle) for me to be comfortable using it for actual work. I also had a single camera, very short cable runs, no support for mobile cameras, and an overall jankiness that just would not cut it for bigger events.

A new centerpiece: ATEM Mini

My first gripe was my capture card. I was using an Elgato GameCapture HD, a capture device I bought back in 2014 which could barely do 1080p30. I still like it for its non-HD inputs (which I have extensively modified and a story for another time), but the single HDMI input, the long acquisition times, and the near three second delay in the video stream made it super janky to use in practice.

After a month and a half on a waiting list, I managed to get my hands on a Blackmagic ATEM Mini, the basic model, and it changed everything: it has four HDMI inputs, an HDMI mix output, USB-C interface, and two stereo audio interfaces, along with fully fledged live video and audio processing: transitions between sources, automatic audio switching, picture-in-picture, chroma and luma keying, still image display, audio dynamics and EQ control and so much more. Its rugged buttons and companion app make operating the ATEM Mini an absolute breeze, and its extensive functionality and integration makes it the closest thing to an all-in-one solution. Many things that I did using lots of devices and maximum jankiness were consolidated in this one device. Anyone who is getting into livestreaming should get one of these.

Dejankifying my audio

Having good audio is almost more important than having good video; a stream with mediocre video but good audio is serviceable, one with good video and bad audio is almost unbearable. Because most events I work on have live audiences on-site, there is no need for me to handle microphones or other audio equipment directly: most mixers have a secondary output I can tap into and get a stereo mix that I can pipe into the ATEM Mini. For line-level unbalanced inputs I can connect them straight into the ATEM, and if I needed something more involved like multiple audio sources, preamplification, or any sort of basic analog processing I keep a small Phonic AM440D mixer in my equipment case, which gives me endless flexibility for audio inputs.

One of the advantages of using common hardware for audio and video is that both streams are synchronized by default, which removes the need for delaying the audio stream entirely, which once again reduces the complexity of setting up livestreams in the field.

New cameras and solving the HDMI distance limitation

For a while, a single Panasonic HDC-TM700 was my only video source, with an additional Sony camera on loan for some events. This was one of my biggest limitations, which I set out to fix.

Most semi-pro/pro cameras are way too expensive for my needs: even standard consumer cameras are way out of my budget, a single camera like the one I already have would need a couple of months worth of revenue, which given that I’m still at university I couldn’t ramp up. There are ways out though.

For one, I thought about USB webcams. There are some good ones on the market right now that are more than enough for livestreaming, but they are very much on the expensive side and I have never liked them for something like this: poor performance at low light, small, low quality lenses and fixed apertures, and low bitrates are just a few of my gripes. Also, I had a better capture card that could take advantage of HDMI cameras. So I looked around AliExpress, and found exactly what I was looking for: Process Cameras.

A process camera is essentially a security camera with an HDMI output. They have no screen, fixed (although decent quality and reasonably large) lenses, and a perfectly usable dynamic range. Since the do not have a screen or autofocus capabilities they are best used for fixed shots, but most of my streams rarely require movement (for which I have the other camera). Best of all: they were very cheap, at around $100 a piece if you included a tripod.

Now, we need to talk about HDMI: It’s a perfectly good standard for home use, but it has some problems in this use case (which we can forgive, this is very much an edge case), the biggest one being max distance. HDMI rarely works above 10m, and even 5m is challenging without active cables and devices that can actually drive cables that long. There are optical cables which can take them over the 10m mark, but these are expensive, bulky, and stiff, which complicates using them in events where they could end up in the way. The solution is somewhat counter-intuitive: just don’t use HDMI cables. But isn’t it the best way to do it in this case? Yes!

See, just because we’re using HDMI signals doesn’t mean we need to adhere strictly to the electrical specification as long as we can get the message across while converting it to a physical medium better suited for long distances. There are many ways of doing this, some use coaxial cables and HD-SDI, others use simple fiber optic patch cables, but I went for old twisted-pair Cat5e: It’s cheap, it’s available, and there are ready-made converters with an HDMI connector on one side and a 8P8C plug on the other. Add a 3D-printed bracket for mounting it on the side of the camera and some small HDMI patch cables and we’re off. With these converters I can get 25m runs no problem, and even 75m in extreme cases, which is enough for most venues.

This was not the only use for a 3D printer: I made custom power bars which hang from a tripod’s center hook, for powering cameras and converters.

Better networking and server equipment

In my previous article I used a Raspberry Pi 3B+ to run an NGINX server with the appropiate RTMP module and some extra software to make a simulcasting server, where a single stream can feed multiple endpoints. This worked great, but Raspberry Pis are a bit anemic and I wanted something with a bit more oomph in case I wanted to do more with it. The idea of a portable server is useful for me not only for streaming, so I grabbed a 2011 Mac Mini on Facebook Marketplace, swapped the hard drive with an SSD and off I went. The additional RAM (4GB instead of just 1GB) allows me to have more services set up without worrying about resources and the beefier Intel Processor allows me more freedom to run concurrent tasks. There is even some QSV work I could do to use hardware encoding and decoding, but that’s a story for another time.

I also ditched my 16-port rackmount switch in exchange for a cheap Netgear WNDR3400v2 wireless router, which gives me a nice hotspot for connecting my phone or in case someone else needs it; the new router is much lighter too.

A portable camera jank-o-rama

For a couple of scenarios, I really needed a portable camera that was fully untethered; maybe for showcasing something, or to keep an eye on the action while on the move. There are some wireless HDMI solutions but it always felt like loosing a good camera for an entire shoot (I usually run a one-man operation, so it was pretty much always a short run for the portable camera), and the cost argument kept popping up.

The way I solved it is to me as janky as it is genius: just use your phone. Most modern phones have excellent cameras, decent audio, and even optical stabilization. I used Larix, a streaming app to create a streaming server that I broadcast over WiFi (see why I needed a wireless router?) to be picked up by OBS. Unreliable? a little bit. Has it ever mattered? Not really, this capability is more of a novelty and a fun thing to add to my repertoire, but not meant as a centerpiece. I have even toyed with a GoPro Hero 7 Black streaming to my RTMP server and picking it up from there, which works, albeit with lots of lag. It’s a bit of a pain to not have it in my ATEM switchboard and having to switch it over OBS, but, you know, it’ll do.

Miscellaneous

Until now I carried everyting on a duffel bag, which just wasn’t going to work anymore: the weight killed my back anytime I went near the thing and there just wasn’t enough space: so I needed something like the big wooden cases that the pro audio industry uses, without breaking the bank. I just took an old hard-side suitcase and crammed everything in it. It’s big enough for me to house most of my stuff but not too big as to be bulky, and allowed me to keep everything tidy but without wasting space.

Because my new cameras don’t have a screen, setting up the shot and focusing can be a challenge. I usually resorted to using my second monitor to do so, but it was always janky and time consuming. To solve this, I bought a CCTV camera tester with an HDMI input. This is essentialy a monitor with a battery, for way less than a professional one.

I needed lots of cables, some of them really long. I ended up buying rolls of power and Cat5E cable and made them myself. My standard kit includes four 25m Cat5E rolls and a 75m one in case the network jack is far away, plus three 20m extension cords so I can place the cameras wherever I want. This is not including the three power bars for the cameras and a fourth one for my computer.

So what comes next?

To be absolutely honest, I think this is as far as this setup goes. Livestreaming jobs have dried up now that the pandemic has quietened down, and pursuing more stable ventures would require lots of investment, which I’m not really in a position to make. I found a niche during the pandemic, and I milked it as much as I could, I’ve paid for the equipment two or three times already, so I’m not complaining, but until I find the time to do that YouTube channel I’ve always wanted to do, I don’t think it’s going to see the light of day for a while.

Closing thoughts

I’ve had some tremendous fun building up this setup, and for my uses, it has proven itself time and again as a dependable if basic setup. Maybe you can get your own ideas to get creative; many of the lessons learned here are very much applicable to other streaming opportunities and who knows, maybe you’ll get some ideas to get creative with this media.

Categories
Tech Explorations

RTMP systems for multistreaming

Given the current events, livestreaming has become an enticing alternative for giving some continuity to many activities that otherwise would not be possible during these difficult times. However, creating a professional quality setup for broadcasting live events is quite a challenge, especially because until just about a decade ago, the idea of creating a live TV studio in your bedroom was ludicrous to say the least. If you’re working with large groups of people, consider it a powerful tool to reach out to your audience.

This post is going to narrate the hoops I went through in the process of creating such broadcasts with professional quality and a relatively friendly budget in mind, as well as explaining a bit how livestreaming works, and how everything ties together for creating both creative and functional livestreams.

I: The gist of it all

Pretty much every social network worth its salt has some sort of livestreaming capability built in, ranging from the gimmicky to studio quality. For the purposes of this article, we’re going to be focusing on three: Facebook, Instagram, and YouTube, as they’re the ones I usually broadcast in.

  • YouTube is pretty much a pioneer on the subject, introducing one of the first livestreaming services available for everyone to use, and has pretty much everything nailed down at this point, providing a stable and reliable platform for pretty much every scenario.
  • Facebook also has a pretty solid platform for livestreaming, and it’s a personal favorite of mine because it will process and transmit pretty much everything you throw at it.
  • Instagram is the most frustrating one to work with, as it does not officially support broadcasting outside of its mobile app, and as such provides plenty of head scratching and hair pulling during the setup process.

Regardless of platform, pretty much every livestreaming service out there works using the Real-Time Messaging Protocol (RTMP), originally developed by Macromedia and now maintained by Adobe. The standard is (mostly) open and it works great, so it’s to be expected that everyone is using it. However, it does not specify a video standard per se, so you can send pretty much anything you want (this will be a problem later). RTMP works by using a streaming server address and a streaming key to connect and begin the transmission, which are different for each platform and are provided by them when you begin a livestream. Depending on the site, the stream key changes for each stream or after a set time, be mindful to keep them up to date.

For any livestream, there are four basic links in the chain that make it work. The chain is only as strong as its weakest link, so all of them must be reasonably balanced to get good results; these are Capture Hardware, Video Processing, Restreaming and Internet Connection.

II: Capture hardware

This is the first link of our broadcast chain, and involves everything needed to capture video and audio data that will go in your livestream. Integrated webcams are the default (and sometimes only) option for many people, but I decided against them mainly because of their poor quality; low framerates, issues with exposure, noisy output, etc. Modern external cameras like the ones offered by Logitech are a good alternative -ignoring the cheaper ones which often suffer from the same issues- you can easily get 1080p at 60fps with them, but since I don’t own one, I went with my preferred method, a video camera and a capture card.

For this method you can use whatever camera as long as it has a clean video output (avoid the ones that show all the controls and menus through the video output) and whatever capture card capable of processing the desired resolution. In my case I used a Panasonic HDC-TM700 portable video camcorder and an Elgato Game Capture HD USB capture card (a beaten old warhorse, and a story for another time.). Both are over five years old at this point, but I can still get a clean and reliable 1080p/30fps video into my broadcasting software with no issues. Both companies offer newer products that can be used instead, and as long as you have a compatible setup, you’ll be fine with whatever you can find.

For audio capture, you can use the audio straight from the camera’s microphone or, as I did, use an external audio interface to plug in dedicated microphones. I used a M-Audio Fast Track C600 audio interface (which I actually got for free, I’ll write about that adventure at some point) which works great, but requires a bit of a workaround, as probably most multichannel audio interfaces will. This gave me a clean sound and four mic channels for plugging whatever I want.

III: Video processing

Now that we have all the AV equipment set up its time to set up the software. I use good old OBS for it, because it’s light on system resources (a must for me running it on a laptop) and pretty much endlessly customizable. This is not a tutorial on how to use OBS, -and there are many of them out there who could explain it way better than I ever could- but it’s basically a video editor but live. you can have different scenes and switch between them, mix different audio sources, capture windows or screens, add text and graphics, and much much more. For me, I also had to install the Elgato Game Capture app which includes the drivers for my capture card, which work right out of the box with OBS as a video source. I also installed the OBS ASIO plugin to connect to my audio interface, as it provides low-latency and stable performance (drivers for de C600 are a bit janky, and ASIO gave me the least glitches.). For multichannel interfaces this is a must, because while OBS supports 2+ channel audio, it will not give independent control of each channel without it. I also added a window capture, which worked perfectly too (although beware if you have switchable graphics when capturing screens/windows, they are known to be a pain to set up).

Before we move on, we need to talk about video resolution aspect ratio. Because RTMP does not specify said parameters, each platform works in its own way, and has its own set of rules. Facebook is the most forgiving of all, allowing pretty much any resolution at whatever aspect ratio, vertical or horizontal. YouTube on the other hand, will only work with horizontal 16:9 video, and will complain about any resolution other than 1920×1080 (although it will still work), filling the screen by scaling up the video stream if it doesn’t match with the widescreen aspect ratio. Instagram will do the same, only this time it exclusively supports vertical video, and will scale up the video if you give it anything other than 9:16 video, losing everything but a sliver of video. For my setup, horizontal video made the most sense, so we were careful to frame the most important parts on that small sliver, but we still lost some important parts of the video. It might be possible to reprocess the video to remediate some of these issues, but not having the entire frame on Instagram was a reasonable compromise for me.

IV: Restreaming

As the title implies, we want to do multistreaming -also known as simulcasting- which means to transmit to multiple platforms at the same time, a task which OBS does not handle natively (you can run multiple instances of OBS with the -multi argument, but video capture devices and webcams will not allow you to use more than one stream at a time). A few comercial alternatives are available to solve this issue, such as Restream.io which is free for some platforms (but not for Instagram, which was a dealbreaker for me) and a limited number of streams. This left me with the predicament of having to set up my own restreaming server.

For this task I used NGINX, a ubiquitous, open source web server software which is -depending on who you ask- the most used web server on the Internet. Fortunately for me, someone had already made an RTMP module for NGINX which worked perfectly (all credit goes to this amazing post on the OBS forums detailing how to make it work). I ran the server on a Raspberry Pi 3B+ which was more than enough to make it work (the restreaming server doesn’t do any sort of processing, it just forwards the incoming stream to the desired servers). In theory you could run it on the same machine used for video processing, but I found NGINX for Windows to be very confusing and difficult to install, whereas the Linux (Raspbian Lite) install and configuration was very simple and straightforward.

Remember when I said that every streaming server used the same protocol? Well, that’s not entirely correct. While it’s true that all three platforms use RTMP for moving the stream around, only YouTube uses the standard protocol on port 1935 (the default port for RTMP), while Facebook and Instagram use RTMPS, which is just the standard RTMP protocol over an SSL tunnel on port 443. This complicated matters a bit because the RTMP NGINX module does not support RTMPS natively, so we now need to encapsulate the Instagram and Facebook video feeds on a secure tunnel.

This is where STunnel comes in. STunnel works as an SSL/TLS proxy, grabbing whatever data we throw at it and encrypting it before sending it back on its way to the target servers. This page helped me get it up and running with NGINX. Now that all the protocols are in order we can actually attempt a connection with the servers.

V: Internet connection

Now that everything is set up on our side, we need to connect to the streaming platforms. Before that though, make sure you have a stable internet connection (Ethernet is your best choice here, Wi-Fi can be very unstable and low speed in certain scenarios), and that your upload speed is greater than the OBS transmit bitrate (2500 kb/s by default) times the amount of streams you are going to simultaneously stream to.

For exact instructions, follow the tutorials listed above or check de OBS forums for help. For Facebook and YouTube is just a matter of copying and pasting the stream keys from their respective streaming menus and you’re on your way, but once again Instagram is going to put up a fight. For one, as we said earlier, Instagram does not officially support RTMP streaming, so we need to use software like YellowDuck that will trick Instagram into believing that it is receiving an RTMP transmission from a phone, the actual supported and official way of doing it. A quick note on any software or website designed to to this: logging in is very finicky. Test the stream beforehand with the actual account you want to use, to avoid screw-ups when the real time comes.

VI: Closing thoughts

After reading all of this, you might feel livestreaming to be a near impossible task but remember, most of the setup required has to be done only once, weeks in advance. after that is just a matter of keeping the stream keys up to date and making sure everything is working.

In dire times like this, streaming often brings a sense of community that not many other technologies can provide. It allows us to see a face, to feel like we’re part of something bigger. If you are in charge of anything that deals with people, please try to introduce it as a new way of reaching out to people, even after all of this is over. Good luck and happy streaming!