YouTube Live Streaming Integration from Mobile Application
YouTube Live — the most popular platform for public streaming. Integration from mobile means: get user's RTMP endpoint via YouTube Data API v3, launch stream from camera to that endpoint, and manage broadcast (start, stop, metadata) — all from your app, not YouTube Studio.
YouTube Data API v3: Getting RTMP Endpoint
Broadcasting on YouTube — two objects: LiveBroadcast (event with time, title, privacy settings) and LiveStream (technical stream with RTMP endpoint and stream key). They link via bind.
API call sequence:
1. Authorization. OAuth 2.0 scope: https://www.googleapis.com/auth/youtube. iOS: AppAuth library or ASWebAuthenticationSession. Android: Google Sign-In SDK or AppAuth-Android.
2. Create LiveBroadcast:
POST https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet,status,contentDetails
{
"snippet": {
"title": "My Broadcast",
"scheduledStartTime": "2025-03-28T12:00:00Z"
},
"status": { "privacyStatus": "public" },
"contentDetails": { "enableAutoStart": true, "enableAutoStop": true }
}
enableAutoStart: true — broadcast starts automatically when video stream arrives. Without it need separate transition API call.
3. Create LiveStream:
POST https://www.googleapis.com/youtube/v3/liveStreams?part=snippet,cdn
{
"snippet": { "title": "Mobile Stream" },
"cdn": {
"frameRate": "30fps",
"ingestionType": "rtmp",
"resolution": "1080p"
}
}
Response contains ingestionInfo.ingestionAddress (RTMP URL) and ingestionInfo.streamName (stream key).
4. Bind:
POST .../liveBroadcasts/bind?id={broadcastId}&part=id,snippet&streamId={streamId}
Total: rtmp://{ingestionAddress}/{streamName} — full RTMP URL for streaming.
Streaming to Obtained Endpoint
Use HaishinKit (iOS) or rtmp-rtsp-stream-client-java (Android) — as in standard RTMP streaming. YouTube accepts H.264 + AAC.
YouTube stream requirements:
- Video: H.264, baseline/main/high profile, up to 1080p60
- Audio: AAC-LC, 44.1 or 48 kHz, up to 256 kbps
- Max bitrate for 1080p30: ~6 Mbps
- GOP (keyframe interval): 2 seconds max — important, else YouTube rejects stream
kVTCompressionPropertyKey_MaxKeyFrameInterval: 60 (for 30 fps = keyframe every 2 seconds) on iOS. Android: format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 2).
YouTube doesn't accept RTMPS (TLS) on rtmps:// — only rtmp://. Important when setting network requests on iOS (ATS requires HTTPS, but RTMP not HTTP — write exception in Info.plist for domain a.rtmps.youtube.com only if using RTMPS endpoint).
Managing Broadcast via API
Check stream status:
GET .../liveStreams?part=status&id={streamId}
status.streamStatus: inactive → testing → active. After active broadcast visible to viewers (with enableAutoStart: true).
End broadcast:
POST .../liveBroadcasts/transition?broadcastStatus=complete&id={broadcastId}&part=id,status
Update metadata during broadcast (title, description):
PUT .../liveBroadcasts?part=snippet
Poll status: request every 5 seconds while streamStatus != active. Not more often — YouTube API quota 10000 units/day, liveStreams.list costs 1 unit.
Broadcast Preview in App
YouTube provides monitorStream.embedHtml — embed URL of broadcast. Embed via WKWebView / WebView to view delayed stream (YouTube adds 5–20 seconds delay). To view yourself without delay — use camera preview locally.
Viewer count: GET .../videos?part=liveStreamingDetails&id={broadcastId} → liveStreamingDetails.concurrentViewers. Request every 30 seconds during broadcast.
Quotas and Limits
YouTube Data API quota: 10,000 units/day free. Creating LiveBroadcast — 50 units. Creating LiveStream — 50 units. Polling liveStreams.list — 1 unit/request. With active use (many broadcasts daily) need to request quota increase in Google Cloud Console.
YouTube prohibits 5+ simultaneous active broadcasts per account. For SaaS platform with many users — each works with own account (OAuth on behalf of user), not app.
Timeline: integrate OAuth + create broadcast via API + launch RTMP stream + manage status — 3–4 work days.







