RTSP Video Streaming With Zoom

Materials

Example

In this example, we will use the Ameba Pro2 board to stream video data from the on-board camera sensor while demonstrating a dynamic zoom function, to a computer via RTSP (Real Time Streaming Protocol).

Open the example in File -> Examples -> AmebaMultimedia -> StreamRTSP -> VideoOnlyWithZoom

image01

The dynamic zoom behavior can be configured by modifying the following macro:

Users can update DYN_ZOOM_MODE to select between two zoom modes:

SCALE_UP_MODE (default): Creating a zoom-in effect.

SCALE_DOWN_MODE: Creating a zoom-out effect.

image02

In the highlighted code snippet, fill in the “ssid” with your WiFi network SSID and “pass” with the network password.

image03

Compile the code and upload it to Ameba. After pressing the Reset button, wait for the Ameba Pro 2 board to connect to the WiFi network. The board’s IP address and network port number for RTSP will be shown in the Serial Monitor.

You may download VLC media player from the link (here).

Upon the completion of the software installation, open VLC media player, and go to Media -> Open Network Stream

image04

Make sure your PC is connected to the same network as the Ameba Pro2 board for streaming. Since RTSP is used as the streaming protocol, key in rtsp://{IPaddress}:{port} as the Network URL in VLC media player, replacing {IPaddress} with the IP address of your Ameba Pro2 board, and {port} with the RTSP port shown in Serial Monitor e.g., rtsp://192.168.1.154:554. The default RTSP port number is 554. In the case of two simultaneous RTSP streams, the second port number defaults to 555.

image05

You may choose to change the caching time in “Show more options”. A lower cache time will result in reduced video latency but may introduce playback stuttering in the case of poor network conditions.

image06

Next, click “Play” to start RTSP streaming. The video stream from the camera will be shown in VLC media player. Meanwhile, in your Serial Monitor, the message “rtp started (UDP)” will appear.

image07

OSD text is drawn on the video to display the current zoom mode and ROI resolution.

image08

image09

Code Reference

The camera can produce 3 simultaneous video stream channels, with the default configuration for each channel as shown. You may choose to edit the code to use a different video stream.

Channel 0: 1920 x 1080, 30FPS, H264 format
Channel 1: 1280 x 720, 30FPS, H264 format
Channel 2: 1280 x 720, 30FPS, MJPEG format

image10

You may adjust the video bitrate based on your WiFi network quality, by uncommenting the highlighted code below.

image11