《阿里云AI产品必知必会系列电子书》——阿里云视觉智能开放平台——视频理解QuickStart使用教程(3) https://developer.aliyun.com/article/1232491?groupCode=supportservice
四、通过Python-SDK调用视频理解-视频内容理解
1、pip install
pip install aliyun-python-sdk-videorecog==1.0.4
2、创建UnderstandVideoContent
from aliyunsdkcore.client import AcsClient from aliyunsdkcore.auth.credentials import AccessKeyCredential from aliyunsdkvideorecog.request.v20200320.UnderstandVideoContentRequest import UnderstandVideoContentRequest credentials = AccessKeyCredential('accesskey', 'accesskeysecret') client = AcsClient(region_id='cn-shanghai', credential=credentials) request = UnderstandVideoContentRequest() request.set_accept_format('json') request.set_VideoURL("url") response = client.do_action_with_exception(request) print(str(response, encoding='utf-8'))
3、返回异步任务请求ID
{ "RequestId": "7D***7C4-9369-5854-B1DF-60******F6" }
4、查询异步任务结果
from aliyunsdkcore.client import AcsClient from aliyunsdkcore.auth.credentials import AccessKeyCredential from aliyunsdkvideorecog.request.v20200320.GetAsyncJobResultRequest import GetAsyncJobResultRequest credentials = AccessKeyCredential('accesskey', 'accesskeysecret') client = AcsClient(region_id='cn-shanghai', credential=credentials) request = GetAsyncJobResultRequest() request.set_accept_format('json') request.set_JobId("7D***7C4-9369-5854-B1DF-60******F6") response = client.do_action_with_exception(request) print(str(response, encoding='utf-8'))
5、获取异步结果数据返回
{ "RequestId": "F9***85-283F-5CC9-8DC1-7BD***325", "Data": { "Status": "PROCESS_SUCCESS", "JobId": "7****4-9369-5854-B1DF-60****9F6", "Result":"{\"tagInfo\":{\"humanInfo\":[{\"timeR ange\":[[0.7272727272727273,0.9696969696969697]],\"timeProportion\":24.242424242424242,\"number\":2,\"category\":\"hu man-real-normal\"}],\"sceneInfo\":[{\"timeRange\":[[0,0.09090909090909091],[0.21212121212121213,0.6666666666666666],[0.6 96969696969697,0.7878787878787878],[0.8181818181818182,0.8787878787878788]],\"timeProportion\":69.6969696969697,\"n umber\":1,\"category\":\"gamescreen-screenshot\"},{\"timeRange\":[[0.09090909090909091,0.21212121212121213],[0.87878787 87878788,1]],\"timeProportion\":24.242424242424242,\"number\":1,\"category\":\"liveaction\"}]},\"videoInfo\":{\"width\":664,\" height\":372,\"duration\":31050,\"fps\":23.976023976023978}}" } }