Monthly Archives: March 2015

Chromecast Game Streaming

Over on /r/chromecast people ask from time to time whether it is possible to stream games to Chromecast. I’ve seen a couple of solutions offered, besides “get a SHIELD”. I’ve already got a Chromecast. I don’t need another dongle.

The first solution is to use the Chrome Google Cast extension to capture the screen and send it to Chromecast. This solution doesn’t work too well. A lot of games use DirectX and, for reasons I won’t go into, you end up transmitting a blank screen to Chromecast. You might be able to work around that by putting the game in Windowed mode, but then, after a brief celebration, you find out it stutters like crazy. Sadly, Google Cast wasn’t designed with game streaming in mind. Lastly, if you have two monitors they are combined and sent so your viewers can watch you surf reddit while you play a very narrow game of Team Fortress 2.

Another solution I saw was to Open Broadcaster to stream to Twitch.TV and then suck it back down to Chromecast. I didn’t try this, but I suspect it would work with a good Internet connection. The solution I offer next is basically this idea, but Twitch.tv is removed from the picture.

The general idea

Here’s the plan. We know Open Broadcaster is good at capturing video and sending it to Twitch.tv. Thousands of people do this everyday. The problem is that it uses a protocol called RTMP, and Chromecast doesn’t understand RTMP. Chromecast understands something called HLS. So we can use a program called nginx to accept RTMP and convert it to HLS. Then we use a web video player to push the HLS stream to Chromecast.

Open Broadcaster

I’m not going to go into great detail on this, because there are all kinds of guides for this. If you’ve never done this, open a Twitch.tv account and get streaming working. Once it works modify these settings under Broadcast Settings:

Mode Live Stream
Streaming Service Custom
FMS URL rtmp://127.0.0.1:1935/live
Play Path/Stream Key test

nginx

If you’re not a tech professional you’ve probably never heard of nginx. It’s a web server. And it happens to have an RTMP module. What is RTMP you ask? I have no idea, but Open Broadcaster will happily send video to it.

We need nginx with the RTMP module (nginx-rtmp-module) compiled in. If you are using Windows you can download nginx for Windows, which has it.

rtmp {
	server {
		listen 1935;
		chunk_size 4096;
		buflen 10s;

		application live {
			live on;
			record off;
			drop_idle_publisher 5s;

			hls on;
			hls_sync 100ms;
			hls_path "c:/Windows/Temp/hls";
			hls_fragment 10s;
			hls_playlist_length 1m;
		}
	}
}

application live {
live on;
record off;
drop_idle_publisher 5s;

The section configures the server to process RTMP requests at rtmp://localhost:1935/live. Live streaming is enabled, and recording is disabled.

			hls on;
			hls_sync 100ms;
			hls_path "c:/Windows/Temp/hls";
			hls_fragment 10s;
			hls_playlist_length 1m;
		}
	}
}

In this section we enable HLS and save the video segments into C:\Windows\Temp\hls. HLS breaks the stream into 10 second chunks. Chromecast retrieves the video segments in order and produces seamless playback.

Next we configure the HTTP server to process HLS requests at http://localhost/hls. It will also serve the video viewer at http://localhost. There is a stats screen at http://localhost/stat.

	server {
		listen       80;
		server_name  localhost;

		root ../www;
		error_page   500 502 503 504  /50x.html;

		location / {
			index index.html;
		}

		location /stat {
			rtmp_stat all;
			rtmp_stat_stylesheet stat.xsl;
		}

		location /stat.xsl {
		}

		location /hls {
			types {
				application/vnd.apple.mpegurl m3u8;
				video/mp2t ts;
			}
			root "c:/Windows/Temp";
			add_header Cache-Control no-cache;
			add_header Access-Control-Allow-Origin *;
		}
	}

Putting it all Together

Configure Open Broadcaster to stream to rtmp://localhost:1935/live with path “test” and start streaming. Open the browser to http://localhost. You should see a video viewer with a preview of the video. Press play and it should stream.

To get the video to Chromecast open the browser to your internal IP address, in my case http://192.168.1.109. Click the Chromecast icon and it should start streaming.

tl;dr

If this was too much for you to handle you can download everything from github. start-server.bat runs nginx so you can configure Open Broadcaster and start streaming right away.

Further Reading