Streaming your Desktop on Mac OS X

I have been playing a lot of Starcaft 2 lately, and really getting into the entire community. One part of the community that I recently discovered has been live streams of games (some from pros) via sites like justin.tv and ustream.com. There are plenty of articles online talking about how to stream your desktop on Windows based machines, but virtually none on how to do it from a Mac. This article will show how to use Adobe Flash Media Live Encoder (and a couple of other tools) to live stream your desktop to justin.tv (although the setup would also work for other streaming sites). <!–more–>

I am going to divide the article up into a couple of sections. The first part will show how to get a basic desktop stream going, including system sound. The second section will show a more advanced sound setup that allows you to also broadcast your microphone, and audio from other apps such as skype.

Basic Desktop Streaming Setup

The basic setup will allow us to stream our desktop and system audio to justin.tv. This requires the following software:

  • Adobe Flash Media Live Encoder (FMLE) 3.2 for Mac : Encodes and streams video and audio to justin.tv
  • CamTwist : Used to capture desktop as a video source
  • Soundflower : Utility used to capture and redirect system output
  • justin.tv config file : Only required if you are streaming to justin.tv (link provided below)

The basic setup is pretty simple, and essentially requires setting up CamTwist to capture your desktop as a video source, and have Flash Media Live Encoder take that video source, combine it with the system audio, and stream it to the server (in this case justin.tv).

A Note on Performance

Keep in mind that encoding and broadcasting live video feeds can be very CPU intensive, and thus may require significant system resources. Depending on what you are streaming, this may affect other applications running on your system, or even the quality of the stream.

Configuring CamTwist

First, download and install CamTwist. Once it is installed, open it up, and under the Step 1 section, double click “Desktop” (not “Desktop+”). “Desktop+” allows you to select a specific window to broadcast, but since we are going to be broadcasting our entire desktop, we will just use the Desktop preset.

You can save these settings by clicking the “Save Setup” button.

Do not select any effects in Step 2.

In Step 3 make sure that “Desktop” is included and checked. In the settings window, make sure that screen is set to “Main Screen”. This ensures that only the main screen will be broadcast (which only matters if you have multiple monitors).

Also make sure that “Full Screen” and “Show mouse pointer (simulated)” are selected.

Once you have set all of these settings, you can save them by clicking the “Save Setup” button.

title

Now, open the preferences (CamTwist > Preferences), and select the “General Tab”. Set the frame rate to the same frame rate you plan to encode at. I am using 24 FPS. The higher the FPS, the smoother the video, but the more bandwidth and CPU required to encode and transmit it.

Set video size to “Custom” and set it to your desktop resolution. In my case, I have it set to 1920 x 1200, which is my native desktop resolution. Set it to the native resolution even if you are going to broadcast at a lower resolution. We will have Adobe Flash Media Live Encoder scale the video down, as my experience has been that it does it much more efficiently than CamTwist.

title

Once you have set the preferences, close the window and restart CamTwist. Make sure the “Desktop” section is selected. You can test that everything is working by selecting Tools > Preview, which will give you a small preview of the video being captured.

Configuring Audio with Soundflower

In order to capture audio, we need a way to capture the system’s audio output, and make it an input for Flash Media Live encoder. Mac OS X does not have native support for doing this, but the free Soundflower utility enabled this.

Soundflower is a utility that can combine multiple audio outputs and redirect them into a single audio output. We can use this to capture system audio, and pass it on to FMLE to include the audio for our video stream.

First, download and install Soundflower. Once it is installed, launch it. It won’t open an application window, but will add a small menu item icon (a flower) on the top right of the menu bar.

We need to tell OS X to direct system audio output to Soundflower. Open Sound preferences (System Preferences > Sound > Output) and select “Soundflower (2ch)”.

title

Basically, anything that you would hear through your speakers will now be directed first through Soundflower.

Next, click the Soundflower icon on the menu bar, and for “Soundflower (2ch)” select what you would normally have set as your system output (such as headphone, or Line-Out). This will redirect the audio through Soundflower, and pass it through your normal output so you can still hear it. However, because it is first directed through Soundflower, we can now also use that as an input source in FMLE.

title

There is a lot more advanced stuff we can do with Soundflower, which we will cover later in the article.

Configuring Adobe Flash Media Live Encoder

Adobe Flash Media Live Encoder (FMLE) is a free tool provided by Adobe that can take a video and audio feed, and create either a VP6 or H.264 encoded video stream that can be streamed to servers and sites such as justin.tv.

Download and install the latest version of FMLE (this article is using version 3.2). If CamTwist is not already running, go ahead and open it. Once FMLE is installed, open it up.

Now, before we start changing settings, we need to first download a config file for our specific justin.tv account. This will include information specific to our account that justin.tv uses to determine which account the stream is associated with. If you are not using justin.tv, you may to skip this section, although you may need to look up docs on how to configure the stream for your specific server.

Log into your justin.tv account, and then visit this page. At the bottom of the page is section for “Flash Media Encoder”. Click the “Config File” button. This is the XML config file for FMLE specific for your justin.tv account. Click the button and download the file to your desktop.

Note : This file will allow anyone who has it to stream to your justin.tv account, so be careful to protect it.

Once you have downloaded the file, we are ready to import it into FMLE. Switch to FMLE and select File > Open Profile. You may get a warning that some tags are not support, and defaults are being used. Just ignore this.

If you look in the output panel on the right side of FMLE, you should see the FMS URL set to something like: rtmp://live.justin.tv/app, and the stream attribute have a value similar to: live12345678XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.

Again, this second string is specific to your account, and will allow anyone to stream to your justin.tv account. You can hide the panel it is shown in (so it wont be displayed on your stream), by selecting “Panel Options” and setting it to “Meta Data” (so the panel wont be displayed). Note that you may need to do this each time your start FMLE.

We are now ready to set up the encoding options for FMLE. First, we will setup the video encoding settings. Some of the settings may vary depending on your system, but I will point out where and why you might want to tweak them.

FMLE : Video Settings

First, in the video panel, make sure that “Video” is checked. For “Device”, select “CamTwist”. If “CamTwist” does not appear as an option, make sure that CamTwist is running and is set to broadcast the desktop. If it isn’t, start it, and then restart FMLE.

Once you have selected CamTwist, you can confirm that it is working by making sure “Input Video” is selected in the “Preview” panel at the top. With this selected, you should see the video feed preview of your desktop.

Next, we need to set the video codec we will be encoding to as well as its options. There is a choice between H.264 and VP6. I am not going to go into a discussion about which is better. In general though H.264 offers higher quality at lower bitrates, with slightly higher CPU usage, while VP6 offers lower quality, with higher bitrates and slightly lower CPU usage. For this article, I will be using H.264 to stream to the server.

Select “H.264” as the Format, and click the little wrench icon. This will open a panel where we can set additional setting specific to the codec.

Set the profile to “Main”.

The “Level” value will vary depending on the resolution you will be encoding at. In our case, I will be encoding at 720p (1280 x 720) at 24 FPS, so I need to set the level to “3.1”. You can find a list of levels and resolutions / FPS in the H.264 wikipedia article.

Finally, we need to set the Keyframe Frequency. This determines how frequently keyframes (complete captures of the image) are inserted into the stream. We will use the default of “5”.

title

Once you have set the codec settings, click the “OK” button.

Back in FMLE, set the Frame Rate to “24.00” fps. Higher frame-rates provide smoother video, but require more CPU and bandwidth. Lower frame-rates provide choppier video, but require less CPU and bandwidth. I think that 24 FPS is a good middle ground, but feel free to experiment. Just remember that if you change this, you should also change it in the CamTwist preferences, so they are the same.

Set “Input Size” to the size that you will be broadcasting / encoding at. We do this, even though the input received from CamTwist is a higher resolution. FMLE will scale the video to the appropriate size. It has been my experience that this uses less CPU that having CamTwist do the scaling.

Leave a Reply

Your email address will not be published. Required fields are marked *