All Products
Search
Document Center

Intelligent Media Services:IPC event search best practices

Last Updated:Dec 25, 2025

Internet Protocol Camera (IPC) event search lets you retrieve media assets based on content understanding. You can search for content such as objects, scenes, text, and icons. This document describes how to use an API to search for IPC events.

Prerequisites

  1. Call the CreateIpcOrder operation to purchase the service.

  2. Set up your environment. For more information, see OpenAPI Portal.

Create a search library

Call the CreateSearchLib operation to create a search library. The following code provides an example:

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys
import json

from typing import List

from alibabacloud_ice20201109.client import Client as ICE20201109Client
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_ice20201109 import models as ice20201109_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client() -> ICE20201109Client:
        """
        Initializes a client with credentials.
        @return: Client
        @throws Exception
        """
        # For production environments, use a more secure method that does not require an AccessKey pair. For more information about how to configure credentials, see https://www.alibabacloud.com/help/document_detail/378659.html.
        credential = CredentialClient()
        config = open_api_models.Config(
            credential=credential
        )
        # For more information about endpoints, see https://api.aliyun.com/product/ICE
        config.endpoint = f'ice.cn-shenzhen.aliyuncs.com'
        return ICE20201109Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        create_search_lib_request = ice20201109_models.CreateSearchLibRequest(
            search_lib_name='IPCamera_test1'
        )
        runtime = util_models.RuntimeOptions()
        try:
            resp = client.create_search_lib_with_options(create_search_lib_request, runtime)
            print(json.dumps(resp, default=str, indent=2))
        except Exception as error:
            # This is for demonstration purposes only. Handle exceptions with care. Do not ignore exceptions in your projects.
            # Error message
            print(error.message)
            # Diagnostic address
            print(error.data.get("Recommend"))

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        create_search_lib_request = ice20201109_models.CreateSearchLibRequest(
            search_lib_name='IPCamera_test1'
        )
        runtime = util_models.RuntimeOptions()
        try:
            resp = await client.create_search_lib_with_options_async(create_search_lib_request, runtime)
            print(json.dumps(resp, default=str, indent=2))
        except Exception as error:
            # This is for demonstration purposes only. Handle exceptions with care. Do not ignore exceptions in your projects.
            # Error message
            print(error.message)
            # Diagnostic address
            print(error.data.get("Recommend"))


if __name__ == '__main__':
    Sample.main(sys.argv[1:])

Request parameters:

Parameter name

Type

Required

Description

Sample value

SearchLibName

string

Yes

The name of the search library. The name can contain letters and digits. For IPC scenarios, the name must start with the prefix IPCamera_.

IPCamera_test1

Response parameters:

Parameter name

Type

Description

Example value:

RequestId

string

The request ID.

******3B-0E1A-586A-

AC29-742247******

Success

string

Indicates whether the call was successful. Valid values:

  • true: The call was successful.

  • false: The call failed.

true

Code

string

The return code.

200

SearchLibName

string

The name of the search library.

IPCamera_test1

Response example:

{
  "RequestId": "******3B-0E1A-586A-AC29-742247******",
  "Success": true,
  "Code": 200,
  "SearchLibName": "IPCamera_test1"
}

Create a search index

Call the CreateSearchIndex operation to create a search index. The following code provides an example:

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys
import json

from typing import List

from alibabacloud_ice20201109.client import Client as ICE20201109Client
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_ice20201109 import models as ice20201109_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client() -> ICE20201109Client:
        """
        Initializes a client with credentials.
        @return: Client
        @throws Exception
        """
        # For production environments, use a more secure method that does not require an AccessKey pair. For more information about how to configure credentials, see https://www.alibabacloud.com/help/document_detail/378659.html.
        credential = CredentialClient()
        config = open_api_models.Config(
            credential=credential
        )
        # For more information about endpoints, see https://api.aliyun.com/product/ICE
        config.endpoint = f'ice.cn-shenzhen.aliyuncs.com'
        return ICE20201109Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        create_search_index_request = ice20201109_models.CreateSearchIndexRequest(
            search_lib_name='IPCamera_test1',
            index_type='mm',
            index_config='{"level":"S.large"}'
        )
        runtime = util_models.RuntimeOptions()
        try:
            resp = client.create_search_index_with_options(create_search_index_request, runtime)
            print(json.dumps(resp, default=str, indent=2))
        except Exception as error:
            # This is for demonstration purposes only. Handle exceptions with care. Do not ignore exceptions in your projects.
            # Error message
            print(error.message)
            # Diagnostic address
            print(error.data.get("Recommend"))

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        create_search_index_request = ice20201109_models.CreateSearchIndexRequest(
            search_lib_name='IPCamera_test1',
            index_type='mm',
            index_config='{"level":"S.large"}'
        )
        runtime = util_models.RuntimeOptions()
        try:
            resp = await client.create_search_index_with_options_async(create_search_index_request, runtime)
            print(json.dumps(resp, default=str, indent=2))
        except Exception as error:
            # This is for demonstration purposes only. Handle exceptions with care. Do not ignore exceptions in your projects.
            # Error message
            print(error.message)
            # Diagnostic address
            print(error.data.get("Recommend"))


if __name__ == '__main__':
    Sample.main(sys.argv[1:])

Request parameters:

Parameter

Type

Required

Description

Example

SearchLibName

string

No

The name of the search library.

  • If you do not specify this parameter, the search index is created in the default search library of Intelligent Media Services (IMS). The default value is ims-default-search-lib.

  • You can also call the QuerySearchLib operation to query for existing search libraries.

IPCamera_test1

IndexType

string

Yes

Specifies the index type. Valid values are:

  • mm: A large vision model that can detect complex features and actions in videos. It supports the detection and search of specific actions, movements, and events, such as a soccer goal or an injured basketball player.

mm

IndexStatus

string

No

The index status. Valid values:

  • Active (default): Activated.

  • Deactivated (Invalid).

Active

IndexConfig

string

No

The index configuration in JSON format. For more information, see the following table.

{"level":"S.large"}

IndexConfig parameters:

Parameter Name

Type

Description

Example

level

string

The index specification. Valid values:

  • Shared (default): A shared instance that supports the analysis of 1 million faces or 1,000 hours of video using a large model.

  • S.large: A dedicated instance that supports the analysis of 1 million faces or 10,000 hours of video using a large model.

  • S.2xlarge is dedicated and supported.

    2 million faces or 20,000 hours of video using a large model.

  • S.4xlarge: Dedicated and supported

    4 million faces or 40,000 hours of video using a large model.

  • S.8xlarge: Dedicated and supported.

    8 million faces or 80,000 hours of video using a large model.

  • S.16xlarge: Dedicated and Supported

    16 million faces or 160,000 hours of video using a large model.

Shared

Response parameters:

Parameter

Type

Description

Example

RequestId

string

The request ID.

*****ACB-44F2-5F2D-

88D7-1283E70*****

Success

string

Indicates whether the call was successful. Valid values:

  • true: The call was successful.

  • false: The call failed.

true

Code

string

The return code.

200

Response example:

{
  "RequestId": "*****ACB-44F2-5F2D-88D7-1283E70*****",
  "Success": true,
  "Code": 200
}

Insert a media asset into the search library

Call the InsertMediaToSearchLib operation to insert a media asset into the search library. The following code provides an example:

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys
import json

from typing import List

from alibabacloud_ice20201109.client import Client as ICE20201109Client
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_ice20201109 import models as ice20201109_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client() -> ICE20201109Client:
        """
        Initializes a client with credentials.
        @return: Client
        @throws Exception
        """
        # For production environments, use a more secure method that does not require an AccessKey pair. For more information about how to configure credentials, see https://www.alibabacloud.com/help/document_detail/378659.html.
        credential = CredentialClient()
        config = open_api_models.Config(
            credential=credential
        )
        # For more information about endpoints, see https://api.aliyun.com/product/ICE
        config.endpoint = f'ice.cn-shenzhen.aliyuncs.com'
        return ICE20201109Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        insert_media_to_search_lib_request = ice20201109_models.InsertMediaToSearchLibRequest(
            search_lib_name='IPCamera_test1',
            media_type='video',
            input='oss://[example-bucket-]/[object_path-]',
            msg_body='{"title":"Short description","visionDescription":"Detailed visual description"}',
            images_input='{"images":["oss://[example-bucket-]/[object_path-]xxx1.jpg","oss://[example-bucket-]/[object_path-]xxx2.jpg","oss://[example-bucket-]/[object_path-]xxx3.jpg","oss://[example-bucket-]/[object_path-]xxx4.jpg"]}',
            namespace='name-1'
        )
        runtime = util_models.RuntimeOptions()
        try:
            resp = client.insert_media_to_search_lib_with_options(insert_media_to_search_lib_request, runtime)
            print(json.dumps(resp, default=str, indent=2))
        except Exception as error:
            # This is for demonstration purposes only. Handle exceptions with care. Do not ignore exceptions in your projects.
            # Error message
            print(error.message)
            # Diagnostic address
            print(error.data.get("Recommend"))

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        insert_media_to_search_lib_request = ice20201109_models.InsertMediaToSearchLibRequest(
            search_lib_name='IPCamera_test1',
            media_type='video',
            input='oss://[example-bucket-]/[object_path-]',
            msg_body='{"title":"Short description","visionDescription":"Detailed visual description"}',
            images_input='{"images":["oss://[example-bucket-]/[object_path-]xxx1.jpg","oss://[example-bucket-]/[object_path-]xxx2.jpg","oss://[example-bucket-]/[object_path-]xxx3.jpg","oss://[example-bucket-]/[object_path-]xxx4.jpg"]}',
            namespace='name-1'
        )
        runtime = util_models.RuntimeOptions()
        try:
            resp = await client.insert_media_to_search_lib_with_options_async(insert_media_to_search_lib_request, runtime)
            print(json.dumps(resp, default=str, indent=2))
        except Exception as error:
            # This is for demonstration purposes only. Handle exceptions with care. Do not ignore exceptions in your projects.
            # Error message
            print(error.message)
            # Diagnostic address
            print(error.data.get("Recommend"))


if __name__ == '__main__':
    Sample.main(sys.argv[1:])

Request parameters:

Parameter Name

Type

Required

Description

Example

SearchLibName

string

No

The name of the search library. Make sure that you have created the search library by calling the CreateSearchLib operation.

IPCamera_test1

MediaId

string

No

The media asset ID. If you do not specify this parameter, an ID is automatically generated.

411bed50018971edb60b0764a0ec6***

MediaType

string

No

The type of the media asset. Valid values:

  • video: Video

video

Input

string

Yes

The address of the video file to ingest, which is optional.

  • OSS URL (

    recommended): For example, oss://[example-bucket-]/[object_path-]

  • HTTP URL: A publicly downloadable URL, for example, http://example-test-****.mp4.

Note

Make sure that the file name is correct and the bucket is in the same region where you call the operation. This ensures that the source file can be accessed.

oss://[example-bucket-]/[object_path-]

MsgBody

string

No

The media asset information. A short description of the video content.

{"title":"Short description","visionDescription":"Detailed visual description"}

ImagesInput

string

No

Information about the set of keyframes extracted from the video file. This parameter is supported only for the IPCamera scenario and when MediaType is set to video.

{

"images": ["oss://[exampl-bucket-]/[object_path-]xxx1.jpg","oss://[example-bucket-]/[object_path-]xxx2.jpg","oss://[example-bucket-]/[object_path-]xxx3.jpg","oss://[example-bucket-]/[object_path-]xxx4.jpg"]

}

Namespace

string

No

The namespace.

name-1

Response parameters:

Parameter Name

Type

Description

Example value

RequestId

string

The request ID.

*****ACB-44F2-5F2D-88D7-1283E70*****

MediaId

string

The media asset ID.

****20b48fb04483915d4f2cd8ac****

Success

string

Indicates whether the call was successful. Valid values:

  • true: The operation succeeded.

  • false: The call failed.

true

Code

string

The return code.

200

Response example:

{
  "RequestId": "*****ACB-44F2-5F2D-88D7-1283E70*****",
  "MediaId": "****20b48fb04483915d4f2cd8ac****",
  "Success": true,
  "Code": 200
}

Event retrieval

Call the SearchMediaByHybrid operation to retrieve events. The following code provides an example:

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys
import json

from typing import List

from alibabacloud_ice20201109.client import Client as ICE20201109Client
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_ice20201109 import models as ice20201109_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client() -> ICE20201109Client:
        """
        Initializes a client with credentials.
        @return: Client
        @throws Exception
        """
        # For production environments, use a more secure method that does not require an AccessKey pair. For more information about how to configure credentials, see https://www.alibabacloud.com/help/document_detail/378659.html.
        credential = CredentialClient()
        config = open_api_models.Config(
            credential=credential
        )
        # For more information about endpoints, see https://api.aliyun.com/product/ICE
        config.endpoint = f'ice.cn-shenzhen.aliyuncs.com'
        return ICE20201109Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        search_media_by_hybrid_request = ice20201109_models.SearchMediaByHybridRequest(
            search_lib_name='IPCamera_test1',
            media_type='video',
            text='Two pandas are fighting',
            namespace='name-1'
        )
        runtime = util_models.RuntimeOptions()
        try:
            resp = client.search_media_by_hybrid_with_options(search_media_by_hybrid_request, runtime)
            print(json.dumps(resp, default=str, indent=2))
        except Exception as error:
            # This is for demonstration purposes only. Handle exceptions with care. Do not ignore exceptions in your projects.
            # Error message
            print(error.message)
            # Diagnostic address
            print(error.data.get("Recommend"))

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        search_media_by_hybrid_request = ice20201109_models.SearchMediaByHybridRequest(
            search_lib_name='IPCamera_test1',
            media_type='video',
            text='Two pandas are fighting',
            namespace='name-1'
        )
        runtime = util_models.RuntimeOptions()
        try:
            resp = await client.search_media_by_hybrid_with_options_async(search_media_by_hybrid_request, runtime)
            print(json.dumps(resp, default=str, indent=2))
        except Exception as error:
            # This is for demonstration purposes only. Handle exceptions with care. Do not ignore exceptions in your projects.
            # Error message
            print(error.message)
            # Diagnostic address
            print(error.data.get("Recommend"))


if __name__ == '__main__':
    Sample.main(sys.argv[1:])

Request parameters:

Parameter name

Type

Required

Description

Sample value

SearchLibName

string

No

The search library.

IPCamera_test1

MediaType

string

No

The type of the media asset. Valid values:

  • Video.

video

PageNo

integer

No

The page number. The default value is 1.

1

PageSize

integer

No

The number of entries to return on each page. The default value is 10. The maximum value is 50.

10

Text

string

No

The search query.

Two pandas are fighting.

Rack

MediaId

string

No

The media asset ID. If you specify this parameter, detailed information about the hit is returned.

****c469e944b5a856828dc2****

Namespace

string

No

The namespace.

name-1

Response parameters:

Parameter Name

Type

Description

Example

RequestId

string

The request ID.

****63E8B7C7-4812-46AD-0FA56029AC86****

Success

string

Indicates whether the operation was successful. Valid values:

  • true: The operation was successful.

  • false: The operation fails.

true

Code

string

The return code.

200

MediaList

array<object>

A collection of media assets that meet the requirements.

MediaList

object

Media asset details.

MediaList.MediaId

string

The ID of the media asset.

a18936e0e28771edb5

9ae6f6f47a****

MediaList.ClipInfo

array<object>

Segment information

MediaList.ClipInfo

object

MediaList.ClipInfo.From

double

The start time of the clip.

2

MediaList.ClipInfo.To

double

The end time of the clip.

4

MediaList.ClipInfo.Score

double

The score.

0.99

Total

long

The total number of media assets that meet the search criteria.

20

Response example:

{
  "RequestId": "****63E8B7C7-4812-46AD-0FA56029AC86****",
  "Success": true,
  "Code": 200,
  "MediaList": [
    {
      "MediaId": "a18936e0e28771edb59ae6f6f47a****",
      "ClipInfo": [
        {
          "From": 2,
          "To": 4,
          "Score": 0.99
        }
      ]
    }
  ],
  "Total": 20
}

Best practices for event retrieval

Use a complete natural language description with one or two keywords. Avoid using too many keywords, because this can result in partial matches. You should also avoid queries that are too short or ambiguous.

Category

Recommended

Not Recommended

Analysis

Character description

Children playing in a park

A child wearing red clothes and a backpack playing in a park.

Too many keywords: red clothes, backpack, child, park.

A farmer working in a field

-

-

Action description

An injured soccer player

Tossing a coin in badminton

The technical terms for edge selection can be complex.

A basketball player shooting a basket

-

-

Ma Long serving

-

-

Object, scenery, and scene description

Eiffel Tower

Xingfu Kindergarten

It can be difficult to interpret minor landmarks.

Shot description

A long shot of a stage

-

-

An aerial shot of Huangshan Mountain

-

-

A close-up shot of a host

-

-

Description of Romantic Life

-

People should have a sense of boundaries in their relationships.

Abstract classes are a complex concept.

Artistic or poetic description

-

Nurturing students like a spring breeze and gentle rain.

Abstract classes can be challenging to understand.