Извлечение лучшего кадра при анализе QUALITY

Задача:

При выполнении анализа QUALITY извлечь лучший кадр видео для дальнейшего использования.

Решение:

На первом этапе процесса необходимо создать в системе папку, содержащую хотя бы один видео-файл с любым релевантным тегом видео.

Запрос создания целевой папки в рамках примера:

HTTP

Bash

Python

php

Java


POST /api/folders/ HTTP/1.1
Host: youradress.ru
X-Forensic-Access-Token: ******************************************
User-Agent: PostmanRuntime/7.15.2
Accept: */*
Cache-Control: no-cache
Postman-Token: f5ed40c1-696a-4b22-82dd-b7eaa13305cf,20a1adbb-a2b1-40e7-88ac-e32aae0f1577
Host: youradress.ru
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Length: 5207082
Connection: keep-alive
cache-control: no-cache


Content-Disposition: form-data; name="video1"; filename="Inquisitor (Replay)/original/close_1555917439844.mp4


------WebKitFormBoundary7MA4YWxkTrZu0gW--,
Content-Disposition: form-data; name="video1"; filename="Inquisitor (Replay)/original/close_1555917439844.mp4


------WebKitFormBoundary7MA4YWxkTrZu0gW--
Content-Disposition: form-data; name="payload"

{
  "media:tags": {
    "video1": [
      "video_selfie",
      "video_selfie_zoom_in",
      "orientation_portrait"
    ]
  }
}
------WebKitFormBoundary7MA4YWxkTrZu0gW--


curl -X POST \
  https://youradress.ru/api/folders/ \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Length: 5207082' \
  -H 'Content-Type: multipart/form-data; boundary=--------------------------820377466115707548083704' \
  -H 'Host: youradress.ru' \
  -H 'Postman-Token: f5ed40c1-696a-4b22-82dd-b7eaa13305cf,fd394441-d7f1-46e2-9b5d-0deebfe86daf' \
  -H 'User-Agent: PostmanRuntime/7.15.2' \
  -H 'X-Forensic-Access-Token: ******************************************' \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F 'video1=@Inquisitor (Replay)/original/close_1555917439844.mp4' \
  -F 'payload={
  "media:tags": {
    "video1": [
      "video_selfie",
      "video_selfie_zoom_in",
      "orientation_portrait"
    ]
  }
}'


import requests

url = "https://youradress.ru/api/folders/"

payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"video1\"; filename=\"close_1555917439844.mp4\"\r\nContent-Type: video/mp4\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"payload\"\r\n\r\n{\n  \"media:tags\": {\n    \"video1\": [\n      \"video_selfie\",\n      \"video_selfie_zoom_in\",\n      \"orientation_portrait\"\n    ]\n  }\n}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
headers = {
    'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    'X-Forensic-Access-Token': "******************************************",
    'User-Agent': "PostmanRuntime/7.15.2",
    'Accept': "*/*",
    'Cache-Control': "no-cache",
    'Postman-Token': "f5ed40c1-696a-4b22-82dd-b7eaa13305cf,2fdebc7e-010a-463f-a548-12c68571257c",
    'Host': "youradress.ru",
    'Accept-Encoding': "gzip, deflate",
    'Content-Type': "multipart/form-data; boundary=--------------------------820377466115707548083704",
    'Content-Length': "5207082",
    'Connection': "keep-alive",
    'cache-control': "no-cache"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)


setUrl('https://youradress.ru/api/folders/');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'Connection' => 'keep-alive',
  'Content-Length' => '5207082',
  'Content-Type' => 'multipart/form-data; boundary=--------------------------820377466115707548083704',
  'Accept-Encoding' => 'gzip, deflate',
  'Host' => 'youradress.ru',
  'Postman-Token' => 'f5ed40c1-696a-4b22-82dd-b7eaa13305cf,95e5a965-b9df-4c5f-86c9-331be6bee0f8',
  'Cache-Control' => 'no-cache',
  'Accept' => '*/*',
  'User-Agent' => 'PostmanRuntime/7.15.2',
  'X-Forensic-Access-Token' => '******************************************',
  'content-type' => 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
));

$request->setBody('------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="video1"; filename="close_1555917439844.mp4"
Content-Type: video/mp4


------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="payload"

{
  "media:tags": {
    "video1": [
      "video_selfie",
      "video_selfie_zoom_in",
      "orientation_portrait"
    ]
  }
}
------WebKitFormBoundary7MA4YWxkTrZu0gW--');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}


OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
RequestBody body = RequestBody.create(mediaType, "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"video1\"; filename=\"close_1555917439844.mp4\"\r\nContent-Type: video/mp4\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"payload\"\r\n\r\n{\n  \"media:tags\": {\n    \"video1\": [\n      \"video_selfie\",\n      \"video_selfie_zoom_in\",\n      \"orientation_portrait\"\n    ]\n  }\n}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--");
Request request = new Request.Builder()
  .url("https://youradress.ru/api/folders/")
  .post(body)
  .addHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW")
  .addHeader("X-Forensic-Access-Token", "******************************************")
  .addHeader("User-Agent", "PostmanRuntime/7.15.2")
  .addHeader("Accept", "*/*")
  .addHeader("Cache-Control", "no-cache")
  .addHeader("Postman-Token", "f5ed40c1-696a-4b22-82dd-b7eaa13305cf,1b356efb-83b7-490a-9b8f-787030ee1f95")
  .addHeader("Host", "youradress.ru")
  .addHeader("Accept-Encoding", "gzip, deflate")
  .addHeader("Content-Type", "multipart/form-data; boundary=--------------------------820377466115707548083704")
  .addHeader("Content-Length", "5207082")
  .addHeader("Connection", "keep-alive")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();

Ответ сервера на запрос создания целевой папки:

JSON


{
    "time_created": 1605466052.521026,
    "time_updated": 1605466052.52104,
    "technical_meta_data": {},
    "meta_data": {},
    "folder_id": "8a904fca-c2fb-482c-8aba-2f412b106624",
    "user_id": "4b90c98b-1f57-4b8e-b8c2-4db7e4503032",
    "resolution_time": null,
    "resolution_status": "INITIAL",
    "resolution_endpoint": null,
    "resolution_state_hash": "c16f51f5d84fd6b9",
    "resolution_comment": null,
    "operator_status": null,
    "operator_comment": null,
    "resolution_author_id": null,
    "is_archive": false,
    "media": [
        {
            "time_created": 1605466052.52267,
            "time_updated": 1605466052.52268,
            "technical_meta_data": {},
            "meta_data": {},
            "media_id": "82a90477-8cd4-4bdc-9b50-ce5e42476e60",
            "media_type": "VIDEO_FOLDER",
            "info": {
                "thumb": {
                    "md5": "120877a7e4dbebaccb673f2570ac94e1",
                    "size": 10962,
                    "width": 168,
                    "height": 300,
                    "mime-type": "image/jpeg"
                },
                "video": {
                    "FPS": 90000.0,
                    "md5": "217f925da64fd423fc8eca65969e0b4c",
                    "size": 5206626,
                    "width": 1920,
                    "height": 1080,
                    "duration": 4.3,
                    "mime-type": "video/mp4"
                },
                "preview": {
                    "FPS": 90000.0,
                    "md5": "217f925da64fd423fc8eca65969e0b4c",
                    "size": 5206626,
                    "width": 1920,
                    "height": 1080,
                    "duration": 4.3,
                    "mime-type": "video/mp4"
                }
            },
            "tags": [
                "video_selfie",
                "video_selfie_zoom_in",
                "orientation_portrait"
            ],
            "original_name": "close_1555917439844.mp4",
            "video_id": "82a90477-8cd4-4bdc-9b50-ce5e42476e60",
            "video_url": "http://youradress.ru/static/8a904fca-c2fb-482c-8aba-2f412b106624/82a90477-8cd4-4bdc-9b50-ce5e42476e60.mp4",
            "thumb_url": "http://youradress.ru/static/8a904fca-c2fb-482c-8aba-2f412b106624/82a90477-8cd4-4bdc-9b50-ce5e42476e60_thumb.jpg",
            "preview_url": "http://youradress.ru/static/8a904fca-c2fb-482c-8aba-2f412b106624/82a90477-8cd4-4bdc-9b50-ce5e42476e60.mp4"
        }
    ]
}

Из ответа для дальнейшей работы понадобятся следующие данные:

  • folder_id = 8a904fca-c2fb-482c-8aba-2f412b106624 - идентификатор созданной папки;

Далее требуется назначить на целевую папку анализ QUALITY и при назначении указать дополнительный параметр "extract_best_shot": true

Запросы назначения анализа в рамках примера:

HTTP

Bash

Python

php

Java


POST /api/folders/8a904fca-c2fb-482c-8aba-2f412b106624/analyses/ HTTP/1.1
Host: youradress.ru
X-Forensic-Access-Token: ******************************************
Content-Type: application/json
User-Agent: PostmanRuntime/7.15.2
Accept: */*
Cache-Control: no-cache
Postman-Token: afbbab67-b178-4123-b8ef-0bd79e67645e,2a062ae8-3645-40dd-a5c0-0758b2a4ac2a
Host: youradress.ru
Accept-Encoding: gzip, deflate
Content-Length: 125
Connection: keep-alive
cache-control: no-cache

{
  "analyses": [
    {
      "type": "quality",
            "params": {
       "extract_best_shot": true
      }
    }
  ]
}


curl -X POST \
  https://youradress.ru/api/folders/8a904fca-c2fb-482c-8aba-2f412b106624/analyses/ \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Length: 125' \
  -H 'Content-Type: application/json' \
  -H 'Host: youradress.ru' \
  -H 'Postman-Token: afbbab67-b178-4123-b8ef-0bd79e67645e,477842d9-c553-4cc5-ad4d-dbf3246baf79' \
  -H 'User-Agent: PostmanRuntime/7.15.2' \
  -H 'X-Forensic-Access-Token: ******************************************' \
  -H 'cache-control: no-cache' \
  -d '{
  "analyses": [
    {
      "type": "quality",
            "params": {
       "extract_best_shot": true
      }
    }
  ]
}'


import requests

url = "https://youradress.ru/api/folders/8a904fca-c2fb-482c-8aba-2f412b106624/analyses/"

payload = "{\n  \"analyses\": [\n    {\n      \"type\": \"quality\",\n            \"params\": {\n       \"extract_best_shot\": true\n      }\n    }\n  ]\n}"
headers = {
    'X-Forensic-Access-Token': "******************************************",
    'Content-Type': "application/json",
    'User-Agent': "PostmanRuntime/7.15.2",
    'Accept': "*/*",
    'Cache-Control': "no-cache",
    'Postman-Token': "afbbab67-b178-4123-b8ef-0bd79e67645e,aa786125-b0f7-4c4f-8820-1d3dad257ae1",
    'Host': "youradress.ru",
    'Accept-Encoding': "gzip, deflate",
    'Content-Length': "125",
    'Connection': "keep-alive",
    'cache-control': "no-cache"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)


setUrl('https://youradress.ru/api/folders/8a904fca-c2fb-482c-8aba-2f412b106624/analyses/');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'Connection' => 'keep-alive',
  'Content-Length' => '125',
  'Accept-Encoding' => 'gzip, deflate',
  'Host' => 'youradress.ru',
  'Postman-Token' => 'afbbab67-b178-4123-b8ef-0bd79e67645e,ce34bb06-1c98-446c-aa4e-30d9020d153b',
  'Cache-Control' => 'no-cache',
  'Accept' => '*/*',
  'User-Agent' => 'PostmanRuntime/7.15.2',
  'Content-Type' => 'application/json',
  'X-Forensic-Access-Token' => '******************************************'
));

$request->setBody('{
  "analyses": [
    {
      "type": "quality",
            "params": {
       "extract_best_shot": true
      }
    }
  ]
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}


OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n  \"analyses\": [\n    {\n      \"type\": \"quality\",\n            \"params\": {\n       \"extract_best_shot\": true\n      }\n    }\n  ]\n}");
Request request = new Request.Builder()
  .url("https://youradress.ru/api/folders/8a904fca-c2fb-482c-8aba-2f412b106624/analyses/")
  .post(body)
  .addHeader("X-Forensic-Access-Token", "******************************************")
  .addHeader("Content-Type", "application/json")
  .addHeader("User-Agent", "PostmanRuntime/7.15.2")
  .addHeader("Accept", "*/*")
  .addHeader("Cache-Control", "no-cache")
  .addHeader("Postman-Token", "afbbab67-b178-4123-b8ef-0bd79e67645e,8ddac812-2236-44b6-8247-da4e7a94999c")
  .addHeader("Host", "youradress.ru")
  .addHeader("Accept-Encoding", "gzip, deflate")
  .addHeader("Content-Length", "125")
  .addHeader("Connection", "keep-alive")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();

Ответ сервера на запрос назначения анализов:

JSON


[
    {
        "time_created": 1605466471.756024,
        "time_updated": 1605466471.756036,
        "technical_meta_data": {},
        "meta_data": null,
        "analyse_id": "c3b8c90e-9c8c-42ff-a6da-f2dc3176bbd8",
        "folder_id": "8a904fca-c2fb-482c-8aba-2f412b106624",
        "type": "QUALITY",
        "state": "PROCESSING",
        "results_data": null,
        "confs": {
            "threshold_replay": 0.45,
            "extract_best_shot": true,
            "threshold_liveness": 0.5,
            "threshold_spoofing": 0.45
        },
        "error_message": null,
        "error_code": null,
        "resolution_operator": null,
        "time_task_send_to_broker": 1605466471.7532,
        "time_task_received": null,
        "time_task_finished": null,
        "source_media": [
            {
                "time_created": 1605466052.52267,
                "time_updated": 1605466052.52268,
                "technical_meta_data": {},
                "meta_data": {},
                "media_id": "82a90477-8cd4-4bdc-9b50-ce5e42476e60",
                "media_type": "VIDEO_FOLDER",
                "info": {
                    "thumb": {
                        "md5": "120877a7e4dbebaccb673f2570ac94e1",
                        "size": 10962,
                        "width": 168,
                        "height": 300,
                        "mime-type": "image/jpeg"
                    },
                    "video": {
                        "FPS": 90000.0,
                        "md5": "217f925da64fd423fc8eca65969e0b4c",
                        "size": 5206626,
                        "width": 1920,
                        "height": 1080,
                        "duration": 4.3,
                        "mime-type": "video/mp4"
                    },
                    "preview": {
                        "FPS": 90000.0,
                        "md5": "217f925da64fd423fc8eca65969e0b4c",
                        "size": 5206626,
                        "width": 1920,
                        "height": 1080,
                        "duration": 4.3,
                        "mime-type": "video/mp4"
                    }
                },
                "tags": [
                    "video_selfie",
                    "video_selfie_zoom_in",
                    "orientation_portrait"
                ],
                "original_name": "close_1555917439844.mp4",
                "video_id": "82a90477-8cd4-4bdc-9b50-ce5e42476e60",
                "video_url": "http://youradress.ru/static/8a904fca-c2fb-482c-8aba-2f412b106624/82a90477-8cd4-4bdc-9b50-ce5e42476e60.mp4",
                "thumb_url": "http://youradress.ru/static/8a904fca-c2fb-482c-8aba-2f412b106624/82a90477-8cd4-4bdc-9b50-ce5e42476e60_thumb.jpg",
                "preview_url": "http://youradress.ru/static/8a904fca-c2fb-482c-8aba-2f412b106624/82a90477-8cd4-4bdc-9b50-ce5e42476e60.mp4"
            }
        ],
        "results_media": [
            {
                "technical_meta_data": {},
                "media_association_id": 1512564,
                "analyse_id": "c3b8c90e-9c8c-42ff-a6da-f2dc3176bbd8",
                "results_data": null,
                "media_association_type": "VIDEO",
                "source_video_id": "82a90477-8cd4-4bdc-9b50-ce5e42476e60",
                "output_images": [],
                "collection_persons": []
            }
        ],
        "results_group": [],
        "resolution_status": "PROCESSING",
        "resolution": "PROCESSING"
    }
]

Выполнение анализа занимает некоторое время, результат следует просматривать с помощью метода Folder Analyses [LIST].

Результаты выполнения анализа:

JSON


[
    {
        "time_created": 1605466471.756024,
        "time_updated": 1605466491.122332,
        "technical_meta_data": {},
        "meta_data": null,
        "analyse_id": "c3b8c90e-9c8c-42ff-a6da-f2dc3176bbd8",
        "folder_id": "8a904fca-c2fb-482c-8aba-2f412b106624",
        "type": "QUALITY",
        "state": "FINISHED",
        "results_data": null,
        "confs": {
            "threshold_replay": 0.45,
            "extract_best_shot": true,
            "threshold_liveness": 0.5,
            "threshold_spoofing": 0.45
        },
        "error_message": null,
        "error_code": null,
        "resolution_operator": null,
        "time_task_send_to_broker": 1605466471.7532,
        "time_task_received": 1605466471.793317,
        "time_task_finished": 1605466491.120507,
        "source_media": [
            {
                "time_created": 1605466052.52267,
                "time_updated": 1605466052.52268,
                "technical_meta_data": {},
                "meta_data": {},
                "media_id": "82a90477-8cd4-4bdc-9b50-ce5e42476e60",
                "media_type": "VIDEO_FOLDER",
                "info": {
                    "thumb": {
                        "md5": "120877a7e4dbebaccb673f2570ac94e1",
                        "size": 10962,
                        "width": 168,
                        "height": 300,
                        "mime-type": "image/jpeg"
                    },
                    "video": {
                        "FPS": 90000.0,
                        "md5": "217f925da64fd423fc8eca65969e0b4c",
                        "size": 5206626,
                        "width": 1920,
                        "height": 1080,
                        "duration": 4.3,
                        "mime-type": "video/mp4"
                    },
                    "preview": {
                        "FPS": 90000.0,
                        "md5": "217f925da64fd423fc8eca65969e0b4c",
                        "size": 5206626,
                        "width": 1920,
                        "height": 1080,
                        "duration": 4.3,
                        "mime-type": "video/mp4"
                    }
                },
                "tags": [
                    "video_selfie",
                    "video_selfie_zoom_in",
                    "orientation_portrait"
                ],
                "original_name": "close_1555917439844.mp4",
                "video_id": "82a90477-8cd4-4bdc-9b50-ce5e42476e60",
                "video_url": "http://youradress.ru/static/8a904fca-c2fb-482c-8aba-2f412b106624/82a90477-8cd4-4bdc-9b50-ce5e42476e60.mp4",
                "thumb_url": "http://youradress.ru/static/8a904fca-c2fb-482c-8aba-2f412b106624/82a90477-8cd4-4bdc-9b50-ce5e42476e60_thumb.jpg",
                "preview_url": "http://youradress.ru/static/8a904fca-c2fb-482c-8aba-2f412b106624/82a90477-8cd4-4bdc-9b50-ce5e42476e60.mp4"
            }
        ],
        "results_media": [
            {
                "technical_meta_data": {},
                "media_association_id": 1512564,
                "analyse_id": "c3b8c90e-9c8c-42ff-a6da-f2dc3176bbd8",
                "results_data": {
                    "confidence_replay": 0.050098747,
                    "confidence_liveness": null,
                    "confidence_spoofing": 0.050098747
                },
                "media_association_type": "VIDEO",
                "source_video_id": "82a90477-8cd4-4bdc-9b50-ce5e42476e60",
                "output_images": [
                    {
                        "time_created": 1605466491.123683,
                        "time_updated": 1605466491.123692,
                        "technical_meta_data": {},
                        "meta_data": {},
                        "media_id": "55e38bc6-8495-4120-a722-cfbf8d3cd6a9",
                        "media_type": "IMAGE_RESULT_ANALYSE_SINGLE",
                        "info": {
                            "thumb": {
                                "md5": "29bb242ffa65a7358ff302d7ecd37be1",
                                "size": 13308,
                                "width": 168,
                                "height": 300,
                                "mime-type": "image/jpeg"
                            },
                            "original": {
                                "md5": "93e0d940e1f085318b561f7bc3451c11",
                                "size": 232350,
                                "width": 1080,
                                "height": 1920,
                                "mime-type": "image/jpeg"
                            }
                        },
                        "tags": [],
                        "original_name": " < PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=1080x1920 at 0x7F8FE1B4C3C8 > ",
                        "image_id": "55e38bc6-8495-4120-a722-cfbf8d3cd6a9",
                        "original_url": "http://youradress.ru/static/8a904fca-c2fb-482c-8aba-2f412b106624/55e38bc6-8495-4120-a722-cfbf8d3cd6a9.jpeg",
                        "thumb_url": "http://youradress.ru/static/8a904fca-c2fb-482c-8aba-2f412b106624/55e38bc6-8495-4120-a722-cfbf8d3cd6a9_thumb.jpeg",
                        "media_association_id": 1512564
                    }
                ],
                "collection_persons": []
            }
        ],
        "results_group": [],
        "resolution_status": "SUCCESS",
        "resolution": "SUCCESS"
    }
]

В ответе можно увидеть, что появился дополнительный блок данных «results_media»\«output_images» (стр.83-114), в котором и находится ссылка на файл лучшего кадра видео (стр.110)