Skip to content

RTMP Module

rtmp module for insta360 allows real-time communication with the camera based on a TCP socket.

Classes:

Name Description
Client

Client for interacting with the camera using the RTMP protocol.

CommandFailedException

Exception raised when a command fails.

CameraNotConnectedException

Exception raised when the camera is not connected.

Client

Client for interacting with the camera using the rtmp protocol.

Parameters:

Name Type Description Default
host str

The IP address of the camera (usually 192.168.42.1).

'192.168.42.1'
port int

The port of the camera (usually 6666).

6666
logger Logger

A custom logger to use.

None
callback Optional[Callable[[Dict], Any]]

A callback function to call when a message is received.

None
enable_hwaccel bool
True
verify_camera_connected bool

Verify if the camera is accessible on the network as soon as the client class is instantiated.

False

Methods:

Name Description
open

Open a TCP socket to the camera.

close

Close the TCP socket.

sync_local_time_to_camera

Sync the local time to the camera.

get_camera_info

Get updated data about the camera, battery, storage, etc.

get_camera_type

Get the camera type.

take_picture

Take a picture.

get_serial_number

Get the camera serial number.

get_camera_files_list

Get the list of files on the camera.

set_normal_video_options

Set the normal video options.

get_normal_video_options

Get the normal video options.

start_capture

Start capturing video.

stop_capture

Stop capturing video.

get_exposure_settings

Get the exposure settings.

set_exposure_settings

Set the exposure settings.

set_capture_settings

Set the capture settings.

get_capture_settings

Get the capture settings.

start_preview_stream

Start the preview stream.

stop_preview_stream

Stop the preview stream.

get_camera_uuid

Get the camera UUID.

get_capture_current_status

Get the current capture status.

set_time_lapse_option

Set the time-lapse option.

start_time_lapse

Start the time-lapse.

stop_time_lapse

Stop the time-lapse.

is_camera_connected

Check if the camera is connected.

get_battery_status

Get the battery status.

get_storage_state

Get the storage state.

Classes:

Name Description
KeepAliveTimer

Timer to call the KeepAlive function.

Decorators

on_event: Register an event handler for an event on_connect: Register an event handler for connect event on_disconnect: Register an event handler for disconnect event on_error: Register an event handler for error event on_video_stream: Register an event handler for video_stream event

KeepAliveTimer

Bases: Timer

Timer to call the KeepAlive function.

close()

Stops the keep alive timer and closes the TCP socket.

display_stream()

Display the stream from the camera.

Note

This is a blocking function and needs to run in main thread as it uses OpenCV. OpenCV does not work well with threads.

ensure_camera_connected()

Check if the device is connected to the camera wifi. Helper method for insta360.rtmp.utils.ensure_camera_connected

Raises:

Type Description
CameraNotConnectedException

If the camera is not connected.

get_battery_status()

Get the battery status from the camera.

get_camera_files_list()

Get the list of files on the camera.

Returns:

Type Description
int

The sequence number of the sent message.

get_camera_info()

Get updated data about the camera, battery, storage, etc.

Returns:

Type Description
int

The sequence number of the sent message.

get_camera_type()

Get the camera type.

get_camera_uuid()

Get the camera UUID.

get_capture_current_status()

Get the current capture status from the camera.

Returns:

Type Description
int

The sequence number of the sent message

get_capture_settings()

Get capture settings from the camera.

get_exposure_settings()

Get exposure settings from the camera.

get_normal_video_options()

Get the normal video options.

Returns:

Type Description
int

The sequence number of the sent message.

get_serial_number()

Get the camera serial number.

get_storage_state()

Get the storage state from the camera.

is_camera_connected()

Check if the camera is connected.

on_connect(uid=None, wait=False)

Helper decorator to register a connect event. Has the same effect as calling on_event with event_name='connect'.

Example
client = Client()

@client.on_connect(uid='my-connect-handler')
async def connect_handler(**kwargs):
    print("Let's get this party going!")

on_disconnect(uid=None, wait=False)

Helper decorator to register a disconnect event. Has the same effect as calling on_event with event_name='disconnect'.

Example
client = Client()

@client.on_disconnect(uid='my-disconnect-handler')
async def disconnect_handler(**kwargs):
    print("Goodbye, hope the video was great!")

on_error(uid=None, wait=False)

Helper decorator to register a error event. Has the same effect as calling on_event with event_name='error'.

Example
client = Client()

@client.on_error(uid='my-error-handler')
async def error_handler(**kwargs):
    print("Whoops!")

on_event(event_name, uid=None, wait=False)

Decorator for registering coroutine handler that will be called when an event with event_name is emitted. Parameter uid may be used when e.g. factory building clients to ensure that duplicate handlers are not registered.

Parameters:

Name Type Description Default
event_name str

Event that the decorated handler will be called upon

required
uid str | None

A unique identifier for a signal receiver in cases where duplicate handlers may be registered.

None
wait bool

If True, the event loop will block until the handler is executed. This can be useful when the handler needs the received data in sequential manner (e.g. to ensure that the captured video data is recorded to file in proper order). It is up to the implementation to ensure that the handler does not block for too long, as it could cause the camera connection to be dropped.

False

Examples:

Registering a handler that will get triggered on ready event

client = Client()

@client.on_event('connect')
async def connect_handler(**kwargs):
    print(f"Connected to {client.connect_host}:{client.connect_port}")

Repeatedly registering handlers with the same uid

client = Client()

@client.on_event('connect', uid='my-unique-connect-handler')
async def connect_handler(**kwargs):
    print("This line will NOT be printed upon connection")

@client.on_event('connect', uid='my-unique-connect-handler')
async def another_connect_handler(**kwargs):
    print("This one WILL be printed upon connection")

Registering a handler to convert a saved file after disconnect in wait=True mode

@client.on_event('disconnect', wait=True)
async def disconnect_handler(**kwargs):
    print("Disconnected from the camera")
    some_longer_running_method_to_convert_file()

on_video_stream(uid=None, wait=False)

Helper decorator to register a video_stream event. Has the same effect as calling on_event with event_name='video_stream'.

Example
client = Client()

@client.on_video_stream(uid='my-video-stream-handler')
async def video_stream_handler(**kwargs):
    print("You're on camera, smile!")

open(fetch_camera_info=False)

Opens a TCP socket to the camera.

set_capture_settings(record_resolution=None, fov_type=None, focal_length_value=None, gamma_mode=None)

Set capture settings to the camera.

set_exposure_settings()

Set exposure settings to the camera.

set_normal_video_options(record_resolution=None, fov_type=None, focal_length_value=None, gamma_mode=None, white_balance=None, white_balance_value=None, function_mode='FUNCTION_MODE_NORMAL_VIDEO')

Set the normal video options.

Parameters:

Name Type Description Default
record_resolution Optional[str]

The recording resolution to set in the camera.

None
fov_type Optional[str]

The FOV type to set in the camera.

None
focal_length_value Optional[float]

The focal length value to set in the camera.

None
gamma_mode Optional[str]

The gamma mode to set in the camera.

None
white_balance Optional[str]

The white balance mode to set in the camera.

None
white_balance_value Optional[float]

The white balance value to set in the camera.

None
function_mode str

The function mode to set in the camera.

'FUNCTION_MODE_NORMAL_VIDEO'

Returns:

Type Description
int

The sequence number of the sent message.

set_time_lapse_option()

Set time-lapse options in the camera.

start_capture()

Start capturing video.

Returns:

Type Description
int

The sequence number of the sent message.

start_preview_stream()

Starts a low resolution preview stream.

Returns:

Type Description
int

The Sequence number of the sent message

Note
  1. The stream is low resolution.
  2. You can start recording simultaneously without any glitches.
Example
from insta360.rtmp import Client

client = Client()
client.open()

client.start_preview_stream()

# Optionally, start recording
client.start_capture()

start_time_lapse()

Start time-lapse in the camera.

stop_capture()

Stop capturing video.

Returns:

Type Description
int

The sequence number of the sent message.

stop_preview_stream()

Stops the preview stream.

Returns:

Type Description
int

The Sequence number of the sent message

Example
import time
from insta360.rtmp import Client

client = Client()
client.open()

client.start_preview_stream()
time.sleep(10)

client.stop_preview_stream()

stop_time_lapse()

Stop time-lapse in the camera.

sync_local_time_to_camera(timestamp=None, seconds_from_gmt=None)

Sync the local time and timezone to the camera.

Parameters:

Name Type Description Default
timestamp Optional[int]

The epoch timestamp to set.

None
seconds_from_gmt Optional[int]

The timezone offset from GMT in seconds.

None

Returns:

Type Description
int

The sequence number of the sent message.

take_picture()

Take a picture.

Returns:

Type Description
int

The sequence number of the sent message.