Fundamentals 5 min read

Implementation Principles of Real-Time Audio/Video Service

This article explains how WebRTC-based real-time audio/video uses P2P and server‑relay modes, details the discovery and tracing of rotation metadata issues, describes SDP and RTP header extensions for video orientation, and shows how to map this information to ffmpeg rotation parameters.

58 Tech
58 Tech
58 Tech
Implementation Principles of Real-Time Audio/Video Service

Real-time audio/video uses the WebRTC protocol stack, supporting both peer-to-peer (P2P) and server‑relay (peer‑server‑peer) communication modes.

Problem discovered : When switching from P2P to server‑relay, recorded videos contain rotation metadata, although live playback appears normal.

Problem tracing : The upstream peer’s RTP stream carries rotation information embedded in the SDP; the rotation is negotiated so the receiver can render the video correctly.

SDP extension : Rotation data is stored as an extmap attribute, e.g., a=extmap:4 urn:3gpp:video-orientation , occupying the fourth RTP header extension ID.

RTP packet format : An RTP packet consists of a fixed header and an optional header extension. The X bit indicates the presence of an extension; CC indicates the number of CSRC identifiers.

Header extension : Only one extension is allowed per packet. Its format is ID + length + data, with length measured in 32‑bit words. Extensions can be single‑byte or double‑byte.

Single‑byte header : Defined by profile 0xBEDE, IDs 1‑15, data length = len+1.

Double‑byte header : Defined by profile 0x100X, IDs 1‑255, data length = len.

Video Orientation (CVO) : Encoded in an 8‑bit field; the high‑order 4 bits are reserved, the next bit selects the camera mode, and the low‑order 3 bits represent one of eight possible rotation angles.

ffmpeg conversion : The extracted rotation angle can be applied with an ffmpeg filter, e.g., ffmpeg -i input.mp4 -vf "transpose=2" output.mp4 .

Summary : Parse CVO data from SDP, extract rotation from RTP header, map it to ffmpeg parameters, and perform the necessary video rotation during transcoding.

FFmpegReal-time CommunicationRTPWebRTCSDPVideo Orientation
58 Tech
Written by

58 Tech

Official tech channel of 58, a platform for tech innovation, sharing, and communication.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.