This is probably the solution to a problem that exactly three other people in the Universe have, but I thought I’d write it down for their benefit ;).   You might also be able to use it to roll your own restream.io.  I suspect you’d need a pretty powerful machine to do that, but perhaps not.

The problem was this:  as documented elsewhere, I use an ATEM mini-Pro as the switcher for doing livestream shows. It has only one H.264 encoder, so whatever bitrate you use for streaming is the bitrate it uses for recording.   When I was using Twitch as the delivery point for the livestreams, this worked just fine because Twitch accommodates very high video bitrates – so the video recordings looked good.  When I moved to Bandcamp for livestreams, I found that it couldn’t handle as high a bitrate for video, and as a result the video on the recordings suffered a bit (but the audio quality was higher).   When you think about it, this makes sense – Twitch is a venue for gamers who want to show high-speed gameplay with chip-tuney audio, whereas Bandcamp is about music and not visuals.

I thought I might be able to have the best of both worlds by running the ATEM’s output at high bitrates to a relay server (thus getting  better bitrates for video recording by the ATEM) and then transcode the stream in real time to something that Bandcamp would tolerate.  And so it proved.  Extrapolating a bit, you could roll your own restream.io if you were so inclined.  You would, however, need a really powerful machine.  The single transcoding setup runs very well on a 12-core Linux laptop; you’d want to experiment to see how many different transcoding processes you could run simultaneously without bogging down.   So be warned: this ain’t likely to run well on a Raspberry Pi (though I haven’t tried it).

To do all this, you need a computer to use for transcoding, the nginx web server software with the nginx-rtmp module installed, and some time and patience.   A few caveats:

  • Nginx will run well on Linux (especially) and OS/X.  It will also run on Windows, but not fast or robustly. 
  • The rtmp module allegedly runs anywhere nginx will.  I have only tried it on Linux.
  • Significant experimentation may be involved.

The first step is to install nginx and its rtmp module on whatever machine you’re using.  There are instructions for Windows here. I haven’t used them, nor am I likely to.   You can easily google instructions for Linux and OS/X – here are two sets I think are likely to work well.  Disregard what they say about the nginx configuration file – we’ll get to that in a minute.

Again, unless you’re planning to use the nginx server for something other than a transcoding relay, you should disregard the configuration instructions and  work with the next section.

The tricky part is configuring the transcoding setup in nginx’s configuration file.  Here’s the config I used.  It omits everything unnecessary for the relay:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
	worker_connections 768;
	}
rtmp	{

	server	{
		listen 1935;
		chunk_size 4096;
		allow publish all;
		allow play all;
		application tbstream	{
					live on;
					record off;
					# working: push to twitch at settings of incoming stream
					push \
rtmp://live-yto.twitch.tv/app/[[YOUR-TWITCH-STREAMING-KEY]];
					# transcode for bandcamp
					exec_push "/usr/bin/ffmpeg" -i\ rtmp://localhost/tbstream/$name -vcodec libx264 -vprofile baseline -g 6\ 
-filter:v fps=30 -s 1280x720 -b:v 4400K -c:a copy  -f flv \ rtmp://localhost/bandcamp/$name 2>>/var/log/ffmpeg-logs/ffmpeg-bandcamp.log;
					}
		application bandcamp	{
					live on;
					record off;
					# bandcamp-y stuff will go here
					push \
rtmp://global-live.mux.com:5222/app/[[YOUR-BANDCAMP-STREAMING-KEY]];
					}
		}
}

Again, the config omits everything that is not needed for the relay.  Note that the nginx configuration requires a semicolon at the end of each line – it will not get confused and include it as part of the URL.   This setup delivers video to Twitch at whatever the incoming parameters are, then transcodes it for Bandcamp.   You can find out what all the transcoding parameters do by looking at a reference on the (invaluable) ffmpeg (this recipe book can also be helpful).

After that, all you need to do is point the ATEM configuration at your relay server, using the format of its configuration file.   Complete instructions for how to do that are in this YouTube video.

X