ONVIF Audio & Video Playback

Master precise control over recorded media with ONVIF Replay. Learn about reverse playback, NTP timestamps, Rate-Control, and Range headers using Happytime RTSP Server.

What is ONVIF Playback?

ONVIF Playback enables standardized access to recorded audio and video from ONVIF-compliant devices (NVRs, recorders, media servers). Unlike live streaming, playback allows you to retrieve footage from a specific time in the past, crucial for event review, forensic analysis, and compliance.

Happytime RTSP Server fully supports the ONVIF Replay specification, allowing clients to:

  • Seek to any point in the recording timeline.
  • Play forward or backward at different speeds.
  • Retrieve keyframes only for faster browsing.
  • Access accurate timestamps synchronized to UTC.

Core Mechanisms

RTP Header Extension (NTP Timestamp)

The most critical feature for reliable playback is the RTP Header Extension. It embeds an NTP timestamp directly into each RTP packet.

This provides:

  • Wallclock Accuracy: Each frame has its exact UTC creation time, regardless of playback speed or direction.
  • Reverse Playback Support: Enables smooth rewinding by providing absolute timing.
  • Synchronization Points: Flags (C-bit) mark I-frames (keyframes), ensuring streams start correctly.

The extension uses ID 0xABAC and contains the NTP timestamp, sync flags, and other metadata.

Transport Protocol

While UDP is supported, TCP-based transport is recommended for playback to ensure reliable packet delivery and prevent data loss during rewind or fast-forward operations.

Controlling Playback with RTSP

Playback is initiated and controlled using the RTSP PLAY command. Key headers include:

1. Range Header (Time Selection)

Specifies the start and end times for playback using absolute UTC timestamps.

Forward Playback (2025-10-08 08:00 to 09:00 UTC)
PLAY /stream HTTP/1.1
Range: clock=20251008T080000Z-20251008T090000Z
...
Reverse Playback (from 09:00 back to 08:00 UTC)
PLAY /stream HTTP/1.1
Range: clock=20251008T090000Z-20251008T080000Z
Scale: -1.0
...

2. Scale Header (Playback Speed)

Controls the playback rate and direction.

  • Scale: 1.0: Normal forward playback.
  • Scale: 2.0: Fast forward at 2x speed.
  • Scale: -1.0: Reverse playback at normal speed.
  • Scale: -2.0: Fast reverse at 2x speed.

3. Rate-Control Header (Delivery Mode)

Determines how the server delivers the stream.

  • Rate-Control: yes (Default): Server controls timing. Stream is delivered in real-time.
  • Rate-Control: no: Client controls timing. Server sends data as fast as possible (useful for fast seeking).

4. Frames Header (Frame Selection)

Limits the type of frames sent to reduce bandwidth.

Request only I-frames (Keyframes)
PLAY /stream HTTP/1.1
...
Frames: intra
Request I-frames and P-frames (skip B-frames)
PLAY /stream HTTP/1.1
...
Frames: predicted

Best Practices

  • Use TCP Transport: Ensures reliable delivery, especially for reverse playback.
  • Enable NTP Sync: Ensure your device's system clock is synchronized with NTP for accurate timestamps.
  • Leverage Rate-Control=no: For quick seeking through long recordings, use Rate-Control: no to fetch data rapidly.
  • Utilize Frame Filtering: Use Frames: intra for efficient thumbnail generation or fast scanning.
  • Handle Gaps Gracefully: The E-bit in the RTP extension indicates the end of a contiguous recording section (e.g., after a gap).

Feature Detection

Clients can check if a server supports ONVIF Replay by including the onvif-replay feature tag in the RTSP SETUP or PLAY request:

Require ONVIF Replay Support
PLAY /stream HTTP/1.1
Require: onvif-replay
...

If the server does not support it, it will respond with a Unsupported error.