The media asset management feature of Intelligent Media Services (IMS) allows you to search for faces in media assets that are stored in the media asset library. You can search for or filter sensitive figures based on your business requirements. This topic describes how to call API operations to search for faces.
Prerequisites
The IMS server SDK is installed. For more information, see Install a server SDK.
Procedure
Configure intelligent content analysis.
Call the CreateSearchIndex operation to automatically initiate intelligent content analysis after media assets are registered. Set the storage type to face.
com.aliyun.ice20201109.Client client = Sample.createClient("accessKeyId", "accessKeySecret"); com.aliyun.ice20201109.models.CreateSearchIndexRequest createSearchIndexRequest = new com.aliyun.ice20201109.models.CreateSearchIndexRequest() .setIndexType("face"); com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); client.createSearchIndexWithOptions(createSearchIndexRequest, runtime);
Register the media assets.
Call the RegisterMediaInfo operation to register the materials to be searched. You can search for faces in mages and videos. In this example, a video is registered.
com.aliyun.ice20201109.Client client = Sample.createClient("accessKeyId", "accessKeySecret"); com.aliyun.ice20201109.models.RegisterMediaInfoRequest registerMediaInfoRequest = new com.aliyun.ice20201109.models.RegisterMediaInfoRequest() .setMediaType("video") .setTitle("face-test12") .setInputURL("oss://example-bucket/example.mp4"); com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); client.registerMediaInfoWithOptions(registerMediaInfoRequest, runtime);
Obtain information about the media assets.
Call the GetMediaInfo operation to confirm that the video is stored in the library.
com.aliyun.ice20201109.Client client = Sample.createClient("accessKeyId", "accessKeySecret"); com.aliyun.ice20201109.models.GetMediaInfoRequest getMediaInfoRequest = new com.aliyun.ice20201109.models.GetMediaInfoRequest() .setInputURL("oss://example-bucket/example.mp4"); com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); client.getMediaInfoWithOptions(getMediaInfoRequest, runtime);
If the value of
AiRoughData.Status
isSaveSuccess
, the video is stored in the library.Search for media assets based on a face image.
Call the SearchMediaByFace operation and set the URL of a face image to search for information about the media asset that contains the face.
com.aliyun.ice20201109.Client client = Sample.createClient("accessKeyId", "accessKeySecret"); com.aliyun.ice20201109.models.SearchMediaByFaceRequest searchMediaByFaceRequest = new com.aliyun.ice20201109.models.SearchMediaByFaceRequest() .setFaceSearchToken("test001") .setPersonImageUrl("https://****.oss-cn-shanghai.aliyuncs.com/test/testFacePic.png"); com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); client.searchMediaByFaceWithOptions(searchMediaByFaceRequest, runtime);
Sample response:
{ "RequestId": "F0FBE61A-66FF-55C0-8900-EE816FA20B8D", "MediaInfoList": [ { "MediaId": "92796460cd4571ed91c6e7e7c45b****" }, { "MediaId": "b5a003f0cd3f71ed919fe7e7c45b****" } ], "Total": 2, "Code": "200", "Success": true }
Search for media asset clips based on a face image.
Call the SearchMediaClipByFace operation and specify
MediaId
returned in Step 4 to search for clips that contain the face.com.aliyun.ice20201109.Client client = Sample.createClient("accessKeyId", "accessKeySecret"); com.aliyun.ice20201109.models.SearchMediaClipByFaceRequest searchMediaClipByFaceRequest = new com.aliyun.ice20201109.models.SearchMediaClipByFaceRequest() .setFaceSearchToken("test001") .setMediaId("92796460cd4571ed91c6e7e7c45b****"); com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); client.searchMediaClipByFaceWithOptions(searchMediaClipByFaceRequest, runtime);
API reference
Contact us
If you have questions or want to obtain technical support, join the DingTalk group for IMS (ID: 48335001108) to contact us.