Tencent Classroom Cloud VOD HLS Playback Architecture and Optimization
The article outlines Tencent Classroom’s cloud VOD solution, detailing HLS streaming fundamentals, a Mongoose‑based local HTTP proxy with LFU caching and pre‑loading, performance optimizations for latency, buffering, security, and playback reliability, and common transcoding pitfalls with practical fixes, highlighting cloud migration benefits.
Since 2018, Tencent Classroom has migrated live and on‑demand courses to the cloud. This article summarizes the client‑side solution for Tencent Classroom cloud VOD, covering HLS playback, local proxy design, performance optimizations, and common pitfalls.
1. HLS Overview
HLS (HTTP Live Streaming) is an Apple‑proposed HTTP‑based streaming protocol. Media is packaged in TS files, video is encoded as H264, and audio as MP3, AAC, or AC‑3. An index file (m3u8) controls playback.
Video container: TS
Video codec: H264
Audio codec: MP3, AAC, AC‑3
Control file: m3u8
The workflow is: the server encodes the input stream to MPEG‑4, segments it into .ts files, creates an m3u8 playlist, and the client sequentially fetches the TS segments according to the playlist.
2. HLS Index Files
The master playlist (master.m3u8) references variant playlists for each bitrate. Typical tags include #EXTM3U, #EXT‑X‑VERSION, #EXT‑X‑STREAM‑INF, PROGRAM‑ID, BANDWIDTH, RESOLUTION, etc. Variant playlists contain encryption tags such as #EXT‑X‑KEY (METHOD, URI, IV) and segment information (#EXTINF, #EXT‑X‑TARGETDURATION, #EXT‑X‑MEDIA‑SEQUENCE).
3. Player Local Proxy
Two playback modes are described:
Direct connection to the remote server – suffers from long start‑up latency, no caching or pre‑load capabilities.
Local HTTP proxy (implemented with Mongoose) – the client requests are rewritten to 127.0.0.1, the proxy fetches remote TS/DK files, caches them, and serves the player.
Key steps of the Mongoose‑based proxy:
Initialize the manager with mg_mgr_init .
Bind a listening port using mg_bind and provide a request handler.
Set the protocol to HTTP/WebSocket via mg_set_protocol_http_websocket so the handler receives HTTP events.
Continuously poll events with mg_mgr_poll .
Cache strategy uses LFU eviction; DNS results are cached; pre‑load of upcoming TS/DK segments; multi‑threaded download to improve throughput.
4. Optimization Areas
First‑frame latency – reduce master playlist fetches, request specific bitrate playlists directly, cache DNS results.
Playback success rate – comprehensive monitoring and issue‑by‑issue fixes.
Playback experience – precise seek handling, audio‑video sync, multi‑track alignment for recorded lectures.
Download speed – parallel requests and cache reuse.
Buffering – frame buffer and display buffer to absorb network or decoding jitter.
Security – key‑based anti‑hotlinking, HLS encryption, watermarking.
5. Common Pitfalls and Solutions
Missing bitrate after transcoding – re‑transcode or apply graceful downgrade to the nearest available quality.
Inconsistent master and variant playlists from getPlayInfo – re‑transcode the source video.
Early termination or inaccurate seek – mismatched EXTINF durations; resolve by re‑transcoding.
Aspect‑ratio stretching after cloud transcoding – ensure source video conforms to standard resolutions before upload.
Infinite loading caused by leftover MP4 playback position – reset position to 0 when it exceeds the HLS duration.
The article concludes that moving live‑replay and on‑demand courses to the cloud has significantly improved data handling and user experience, and invites the community to participate in further cloud VOD development.
Tencent Cloud Developer
Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.