You can use the WowzaConfig class in the Wowza GoCoder™ SDK for iOS to configure properties for a live streaming broadcast. There are three primary categories of properties: video, audio, and connection properties for the Wowza Streaming Cloud™ service and Wowza Streaming Engine™ media server software.
You can also use the WowzaGoCoder class to get the bitrate of an encoded live stream as it is being transmitted across the network socket during a broadcast.
Before you begin
Before adding the functionality below to an app, make sure you've set up the Wowza GoCoder SDK for your project:
- Request a free license and download the latest version of the SDK.
- Configure your Xcode project to use the SDK.
See Download and install GoCoder SDK for iOS for detailed instructions.
Configure the stream
Configure the video
Use the following properties to configure the video stream:
Property | Description |
videoFrameRate | The number of frames per second (fps). The default is 30. |
videoKeyFrameInterval | The number of frames between keyframe insertions. The default is 30. |
videoBitrate | The video bitrate in kilobits per second (kbps). The default is 1500. Note that the bitrate of a stream is reduced as needed when network bandwidth is insufficient. |
The following example demonstrates how to use the video properties:
// Get a copy of the active config WowzaConfig broadcastConfig = self.goCoder.config; // Set the frame rate to 15 fps broadcastConfig.videoFrameRate = 15; // Set the keyframe interval to 10 frames broadcastConfig.videoKeyFrameInterval = 10; // Set the bitrate to 2.5 kbps broadcastConfig.videoBitrate = 2500; // Update the active config self.goCoder.config = broadcastConfig;
Configure the audio
Use the following properties to configure the audio stream:
Property | Description |
audioSampleRate | The audio sample rate in hertz (Hz). The default is 44100. |
audioChannels | The number of audio channels. The default is 2. |
audioBitrate | The audio bitrate in bits per second (bps). The default is 64000. |
The following example shows how to use the audio properties:
// Get a copy of the active config WowzaConfig broadcastConfig = self.goCoder.config; // Set the sample rate to 22.1 kHz broadcastConfig.audioSampleRate = 22100; // Update the active config self.goCoder.config = broadcastConfig;
Configure the connection
Use the following properties to configure the connection to your Wowza Streaming Engine server or to a Wowza Streaming Cloud live stream:
Property | Description |
hostAddress | The domain name or IP address of the destination. There isn't a default value. |
portNumber | The port number for the Wowza Streaming Engine server. The default is 1935. |
applicationName | The name of the destination live streaming application. The default is live. |
streamName | The name of the live stream that you're broadcasting. The default is myStream. |
username | (If your application requires it) the source authentication username. There isn't a default value. |
password | (If your application requires it) the password associated with the source authentication username. There isn't a default value. |
The following example shows how to use the connection properties:
// Get a copy of the active config WowzaConfig broadcastConfig = self.goCoder.config; // Set the hostname broadcastConfig.hostAddress = @"live.someserver.net"; // Set the name of the stream broadcastConfig.streamName = @"someStreamName"; // Update the active config self.goCoder.config = broadcastConfig;
Use configuration presets
Alternatively, configure your broadcast with one of the following presets, which accommodate common frame sizes:
Preset | Frame Size | Bitrate |
WOWZFrameSizePreset352x288 | 352x288 | 280 Kbps |
WOWZFrameSizePreset640x480 | 640x480 | 1.5 Mbps |
WOWZFrameSizePreset1280x720 | 1280x720, or 720p | 3.75 Mbps |
WOWZFrameSizePreset1920x1080 | 1920x1080, or 1080p | 5 Mbps |
WOWZFrameSizePreset3840x2160 | 3840x2160, or UHD 4K | 8 Mbps |
The following example shows how to use a frame-size preset:
// Get a copy of the active config WowzaConfig broadcastConfig = self.goCoder.config; // Set the defaults for 720p video [broadcastConfig loadPreset:WOWZFrameSizePreset1280x720]; // Update the active config self.goCoder.config = broadcastConfig;
Get the bitrate during a broadcast
You can get the bitrate of the encoded live stream as it is being transmitted across the network socket. Note that this bitrate can vary due to:
- Factors related to encoding the stream
- Automatic reduction of the stream bitrate ("throttling") to adjust for insufficient network bandwidth
The bitrate is updated every three seconds based on the average bitrate during the last 15 seconds.
You can get the bitrate by using the getCurrentBroadcastingNetworkBitrateThroughput method in the WowzaGoCoder class or by listening for the value with NSNotificationCenter.
To get the bitrate by using getCurrentBroadcastingNetworkBitrateThroughput
// Get the bitrate of the stream at the network socket [self.goCoder getCurrentBroadcastingNetworkBitrateThroughput];
To listen for the bitrate
- Add an observer of WOWZBroadcastBitrateNetworkThroughputUpdate notifications. For example:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(broadcastBitrateUpdated:) name:@"WOWZBroadcastBitrateNetworkThroughputUpdate" object:nil];
- Add the selector method that will respond when WOWZBroadcastBitrateNetworkThroughputUpdate notifications are received. The notification's payload will provide the bitrate value using the broadcastThroughputBitrate key. For example:
-(void) broadcastBitrateUpdated:(NSNotification *)note { dispatch_async(dispatch_get_main_queue(), ^{ self.bitrateLabel.text = [NSString stringWithFormat:@"%.02f kbps", [note.userInfo[@"broadcastThroughputBitrate"] floatValue]]; }); }