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'
|
port |
int
|
The port of the camera (usually |
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)
on_disconnect(uid=None, wait=False)
on_error(uid=None, wait=False)
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 |
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
on_video_stream(uid=None, wait=False)
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
- The stream is low resolution.
- You can start recording simultaneously without any glitches.
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()
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. |